Detect RGB color interval with OpenCV and C++ -


i detect red colored object in video or image, opencv , c++. algorithms available this?

i comparison of relationship between levels of color. indeed, when brightness varies, ratio remains constant. want determine interval of acceptable values ​​for colors of zone of interest.

for cases @ red r (x, y) , g (x, y) / r (x, y) , b (x, y) / r (x, y).

i find ranges of acceptable values​​: first idea, releases maximum , minimum each report palette image red

i find :

if minr<=r(x,y)<=maxr , ming<=g(x,y)<=maxg minb<=b(x,y)<=maxb couleur(x,y)=blanc else couleur(x,y)=noir

preprocess image using cv::inrange() necessary color bounds isolate red. may want transform color-space hsv or ycbcr more stable color bounds because chrominance , luminance better separated. can use cvtcolor() this. check out answer here example of using inrange() createtrackbar().

so, basic template be:

mat redcoloronly; inrange(src, scalar(lowblue, lowgreen, lowred), scalar(highblue, highgreen, highred), redcoloronly); detectsquares(redcoloronly); 

edit : use trackbars determine color range want isolate, , use color intervals find work. don't have use trackbars.

example :
so, complete example of template here go,

i created simple (and ideal) image in gimp, shown below: enter image description here

then created program filter red squares:

#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <iostream>  using namespace std; using namespace cv;  mat redfilter(const mat& src) {     assert(src.type() == cv_8uc3);      mat redonly;     inrange(src, scalar(0, 0, 0), scalar(0, 0, 255), redonly);      return redonly; }  int main(int argc, char** argv) {     mat input = imread("colored_squares.png");      imshow("input", input);     waitkey();      mat redonly = redfilter(input);      imshow("redonly", redonly);     waitkey();      // detect squares after filtering...      return 0; } 

note : not able use these exact same filter intervals real imagery; suggest tune intervals trackbars see acceptable.

the output looks this:

enter image description here

voila! red square remains :)

enjoy :)


Comments

Popular posts from this blog

php - How to build a web site which gives a sub-domain dynamically to every registered user? -

Delphi Wmi Query on a Remote Machine -