Hudixt Hudixt - 3 months ago 43
C++ Question

What is the correct hsv range for this image?

I am trying to use inrange function in opencv to get the square(green part) but it doesn't seems to work. Here is my image
enter image description here
Here is my code:

cv::inRange(src, cv::Scalar(35, 20, 20), cv::Scalar(85, 255, 200), src);


And here is the output for my code:
enter image description here

How can i get all the green part using correct hsv values....

Answer

Look at the HSV color wheel and pick the right range. Be aware that HSV has fit into 3 8 bit- channels, but the H channel does not, so you have to divide this value by 2. The range for H is 0-180 in OpenCV. See this question for reference. HSV color wheel

With this configuration ( I tested the values with ImageJ not OpenCV)

cv::inRange(src, cv::Scalar(35, 60, 200), cv::Scalar(60, 255, 255), src);

i got this result: enter image description here With cv::findContours you can easily detect all contours and filter just the square by shape and size or by their hierarchy.