c++ - detect blue line with if statement -


i have made blue line using opencv , houghlines (in c++) , wondering include in if statement supposed detect if blue line exists , if perform action.

i trying cv::inrange function detect blue, cannot use in if statement.

here code draw blue lines:

         vector<vec2f> lines;          houghlines(dst, lines, 1, cv_pi/180, 100, 0, 0 );           for(size_t = 0;i < lines.size();i++)          {             float rho = lines[i][0], theta = lines[i][1];              //scan horizontal line)             if(theta > cv_pi/180*80 && theta < cv_pi/180*100){              point pt1, pt2;             double = cos(theta), b = sin(theta);             double x0 = a*rho, y0 = b*rho;             pt1.x = cvround(x0 + 1000*(-b));             pt1.y = cvround(y0 + 1000*(a));             pt2.x = cvround(x0 - 1000*(-b));             pt2.y = cvround(y0 - 1000*(a));              //draw line in blue             cvline(m_image, pt1, pt2, scalar(255,0,0), 3, cv_aa);             }         }     } 

and want

if (blue line exists) {      } 

here current image getting. (ignore green , red line, pov of car on road) suppose detect when blue line in lower part of image (right in front of picture) perform action (make car stop)

pov of car

thank time.

ps. saransh kejriwal, trying flag now.

there 2 ways can follow:

1) set flag when draw blue line:

everytime draw blue line, set int flag=1.

drawline(); flag=1; 

this can checked in 'if' condition. when flag 1, means you've drawn blue line earlier. neater, if suits requirement.

2) design blue colour filter in case you've drawn blue line before you're calling 'if' statement, here's algorithm follow, -design blue colour mask using inrange, , save mask on different mat object (mat mask;) - apply findcontours on mask. check contour area of each contour obtained. - in case have drawn line, 1 of contours have significant area, can apply if condition as:

if(contourarea(contours[i])>some_threshold_value) {      //your code here } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -