Use mask in opencv to detect color similarity
cv::Mat3b bgr = cv::imread("red_test.png");
cv::Mat3b hsv;
cvtColor(bgr, hsv, cv::COLOR_BGR2HSV);
cv::Mat1b mask1, mask2;
inRange(hsv, cv::Scalar(0, 70, 50), cv::Scalar(10, 255, 255), mask1);
inRange(hsv, cv::Scalar(170, 70, 50), cv::Scalar(180, 255, 255), mask2);
cv::Mat1b mask = mask1 + mask2;
In order to detect the red heart in the image, the code above when applied is applied which provides with 2 masked images namely 'mask1' and 'mask2'. Then I combine masks generated for both the red color range by doing an OR operation pixel-wise. The following output is generated.
What I need to know is: Is it possible to use the output image to detect red color in other sample images? (ignore the heart shape, it's only the color I'm interested in).
you can use colormatch template too
Thanks for your reply LBerger. Could you please give an example of the arguments I need to put in while executing? Thanks
Nothing it's only a loop to fix a threshold
I don't think I understand. So, I can't add arguments in your template to find matching color images? I thought that's why you linked me the template. Masks, inRange don't seem to help one bit.
thanks for your help
Have you complied and run sample? There is two parts when you try matchTemplate using correlation (grayscale or color):