0

I am a bit confused right now, i can't find the correct value for this green square. Here is the image enter image description here

The hsv values that i choose are:-

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

Here is the output from this:- enter image description here

What is the correct value for hsv that i should choose?

Utkarsh Dixit
  • 4,267
  • 3
  • 15
  • 38

1 Answers1

1

These ranges should work good enough:

inRange(hsv, Scalar(35, 20, 20), Scalar(85, 255, 255), mask);

enter image description here

Remember that OpenCV stores images as BGR, and not RGB. So when you convert to HSV be sure to use COLOR_BGR2HSV, and not COLOR_RGB2HSV.

#include <opencv2/opencv.hpp>
using namespace cv;

int main()
{
    Mat3b img = imread("path_to_image");

    Mat3b hsv;
    cvtColor(img, hsv, COLOR_BGR2HSV);

    Mat1b mask;
    inRange(hsv, Scalar(35, 20, 20), Scalar(85, 255, 255), mask);

    imshow("Mask", mask);
    waitKey();

    return 0;
}

You can find additional details on HSV ranges here and here

Community
  • 1
  • 1
Miki
  • 40,887
  • 13
  • 123
  • 202
  • Thanks, it was a silly mistake i forgot to convert it to HSV..... Also can you tell me how to pick inrange values for HSV i don't know how to find them.... – Utkarsh Dixit Aug 29 '16 at 18:54