0

I am going to detect the green color in image, the full code is shown below

import numpy as np
import argparse
import cv2

ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", help = "path to the image")
args = vars(ap.parse_args())

# load the image
image = cv2.imread(args["image"])
image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)


# define the list of boundaries
boundaries = [
    (  [ 146, 0, 0 ],[146, 100, 100 ])  # hsv 
]

for (lower, upper) in boundaries:
    lower = np.array(lower, dtype = "uint8")
    upper = np.array(upper, dtype = "uint8")

    mask = cv2.inRange(image, lower, upper)
    output = cv2.bitwise_and(image, image, mask = mask)

    cv2.imshow("images", np.hstack([image, output]))
    cv2.waitKey(0)

Here is the image

enter image description here

so hsv[146,40,40] = dark green

hsv [146, 80, 80]  = light green

http://www.rapidtables.com/web/color/RGB_Color.htm can verify the color

enter image description here enter image description here

but why the program outputs no green mask?

user824624
  • 7,077
  • 27
  • 106
  • 183
  • Did you verify that those exact values exist in your image? I used an image color picker and got `[ 72, 135, 27 ]` for light green and `[101, 183, 38]` for dark green from your image. – zindarod Sep 09 '17 at 09:01
  • I modified the code and converted the color into HSV space, but still doesn't work – user824624 Sep 09 '17 at 09:26
  • 1
    OpenCV HSV ranges are different... see the explanation in the duplicate – Miki Sep 09 '17 at 13:45

0 Answers0