Home > front end >  Color lost with cv.warpPerspective function
Color lost with cv.warpPerspective function

Time:06-21

I am trying to inverse a picture from

birdview

to a normal

perspektiv

so I can extract two blue lines and copy it to my original image by using the following code:

lane_color = [255, 0, 0] #BGR-color

def object_isolation(img, color):
    color = np.uint8([[color]])
    hsv_color = cv.cvtColor(color, cv.COLOR_RGB2HSV)
    
    image_hsv = cv.cvtColor(img, cv.COLOR_RGB2HSV)
    lower_range = np.array([hsv_color[0][0][0]-30,hsv_color[0][0][1]-30,hsv_color[0][0][2]-30], dtype = np.int32)
    upper_range = np.array([hsv_color[0][0][0] 30,hsv_color[0][0][1] 30,hsv_color[0][0][2] 30], dtype = np.int32)
    
    mask = cv.inRange(image_hsv, lower_range, upper_range)
    result = cv.bitwise_and(img, img,mask = mask )
    return result

......


image = object_isolation(normal_perspektiv, lane_color) # image only contains the Blue color
lines = np.nonzero(image) 
nonzero_lane_y = lines[0]
nonzero_lane_x = lines[1]

for i in range(len(nonzero_lane_y)):
    frame[nonzero_lane_y[i]][nonzero_lane_x[i]] = [255, 0, 0] # frame is my original image

But you can see in the picture, that the blue line is not continuous like the blue line in bird view. How can I draw a much clearly line?

Thanks.

CodePudding user response:

Answer to this question:

i just add thickness to the function cv.polylines(...., thickness = 2) and it works very good(@fmw42).

End

  • Related