Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thresholing a RGB image using inrange (OpenCV)

Tags:

c++

opencv

I'm filtering a RGB image (attached RGB image) with the inrange function to filter out all colors in my image except orange.

cv::Mat output;
cv::inRange(image, cv::Scalar(255, 140 , 0), cv::Scalar(255, 165, 0),output);
cv::imshow("output", output);

However all this does is return a black output. Additionally, I saw another question using the inrange function which used the values

cv::inRange(image, cv::Scalar(0, 125, 0), cv::Scalar(255, 200, 255), output);

and when I use these values it returns the right output. What is the difference here and What am I doing wrong?

like image 564
user3504972 Avatar asked Mar 08 '23 06:03

user3504972


1 Answers

The orange color in your image is (254, 165, 0). But more importantly, the images in OpenCV are in BGR order, so you need to do:

cv::inRange(image, cv::Scalar(0, 140, 254), cv::Scalar(0, 165, 254), output);
like image 117
szym Avatar answered Mar 20 '23 03:03

szym