-1

Someone please explain me that why the following code is for detecting red color region and how about other color? Note: The original picture is in BGR format.

split(frame, channels);
add(channels[0], channels[1], channels[1]);
subtract(channels[2], channels[1], channels[2]);
threshold(channels[2], thresh_frame, 50, 255, CV_THRESH_BINARY);
quangtoi
  • 1
  • 1

2 Answers2

0

Where are the methods from and what do they do?

Wild guess: "channels" refers to the single colors of the used color spectrum (RGB, CMYK, ...). If you subtract the RED channel from your original picture (or whatever combination of CMYK gives you RED) and look if the returned values are in a specific range then you can tell if the color is RED or not.

0

Probably the image is in BGR format (red in the third channel) and the code identifies red is pixels where

RED-(GREEN+BLUE) >=50
Ophir Gvirtzer
  • 604
  • 4
  • 8
  • Yes, you are right. The original picture is in BGR format. I saw that, this method is better than that finding HSV values (with function: inrange()). – quangtoi Mar 26 '15 at 11:06