Kailegh
Kailegh

Reputation: 197

Detect not complete/perfect triangles

I am tryng to detect traffic signs by their colour and shape, i have the binary image from de colour segmentation and i try to detect triangles in it, by unless all the sides of the triangle are complete y doesnt work,

in this image for example it does not detect any triangle

enter image description here

the code i am using is this:

vector<Point> approx;
   findContours(copia,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE);
   vector<Rect_ <int> > boundRect( contours.size() );
   vector<Rect_ <int> > boundRect_( contours.size() );
   for(size_t i=0; i<contours.size();i++)
   {

       approxPolyDP(Mat(contours[i]), approx,arcLength(Mat(contours[i]), true)*0.02, true);

       if (approx.size() == 3 &&fabs(contourArea(Mat(approx))) > 300 && isContourConvex(Mat(approx)))
           drawContours(capture->image,contours,i,Scalar(0,255,0));

It is not a problem of the cotourArea, i have no problem detecting complete triangles. I do not know if i could do something to detect that kind of "not complete triangles" or i would have to do something to complete the triangle so that i could detect them. In either case i am a bit lost

Thank you for your help

EDIT: i forgot to upload the image

Upvotes: 2

Views: 754

Answers (2)

MKur
MKur

Reputation: 11

Topic is old - but might help others. I had same issue but I dealt with it using dilate() function on input image (it might require 2-3 iterations if triangle has big gap). It is not the best solution but at the moment seems to be the easiest one.

Upvotes: 1

kcc__
kcc__

Reputation: 1648

Actually, opencv side of a triangle maybe difficult in terms of vision but I would suggest some method that may help you achieve.

1) Use Corner detector

(OpenCV Canny) to detector all corner in the binary image. I would say use Morphological Operations (Dilate and Errode) as a means to reduce noise instead of blurring or non-max suppression. Next Use the extreme points, and connect it to form Triangles. Because there will be perhaps many corners you can try fitting all the points and select the maximum Fit. You may also use delaunay triangulation to find the triangle to the points.

2) Using Curvature Info. Since one edge of the triangle is missing, you can use the 2 edges to compute the curvature of the circumscribing contour. Again here Morphological Operations (Dilate and Errode) can be useful. Than you can select points where curvature (Computing the Curvature of Binary Image Contour) change drastically as extreme point as vertex and fit lines to get approximation to the traiangle. If you image is less noisely you can use Convex Hull to get the approximation.

3) RANSAC Fitting You may also use Fitting method to approximate the triangle by using variants of triangles and fit it to the 2 estimated edges on the binary image.

Upvotes: 1

Related Questions