How to detect two different colors using `cv2.inRange` in Python-OpenCV?

后端 未结 3 1165
旧时难觅i
旧时难觅i 2020-11-27 06:06

How can I define \"lower\" and \"upper\" range of two different color, such as red and blue (because red and blue are not next to each other in the HSV color)

This o

3条回答
  •  广开言路
    2020-11-27 06:48

    # Make a copy of the image
    
    image_copy = np.copy(image)
    ## TODO: Define the color selection boundaries in RGB values
    # play around with these values until you isolate the blue background
    
    lower_blue = np.array([200,0,0]) 
    upper_blue = np.array([250,250,255])
    
    # Define the masked area
    
    mask = cv2.inRange(image_copy, lower_blue, upper_blue)
    # Vizualize the mask
    
    plt.imshow(mask,cmap='gray')
    

提交回复
热议问题