Utkarsh Dixit
Utkarsh Dixit

Reputation: 4275

What would be the hsv range for this in Opencv?

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?

Upvotes: 0

Views: 1933

Answers (1)

Miki
Miki

Reputation: 41775

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

Upvotes: 1

Related Questions