I used HoughLinesP
to identify lines. However, my problem is how do I know when there are no lines detected. I have tried comparing the vector lines to null but nothing happens. To be precise, here is my code:
for(size_t k=0; k<lines.size(); k++){
Vec4i l = lines[k];
line(gray, Point(l[0], l[1]), Point(l[2], l[3]),Scalar(0,0,255), 3, CV_AA);
double x = l[2]-l[0];
double y = l[3]-l[1];
double slope = (x/y);
double rad = atan(slope);
double pi = 3.1416;
double deg = (rad*180)/pi;
double fin = deg+90;
int part = 0;
if (lines.empty()){printf("NO LINE IN THIS PORTION OF THE IMAGE!");part = 0;}
else{
if (fin>=0 && fin<=45){part = 1;}
else if (fin>45 && fin<=90){part = 2;}
else if (fin>90 && fin<=135){part = 3;}
else if (fin>135 && fin<=180){part = 4;}
}
printf("portion number = %d angle = %f PART = %d\n",j, fin, part);
}
I am identifying a particular sector with the part
variable. If there are no lines detected, I would like for part == 0
to be true. But, I can't find the correct way to know if there are no lines detected. It is only printing angles if there is already a line in the image. Thanks!