Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Using imaqFindCircularEdge() and imaqFitEllipse()

Hi,

I am using Visual Studio .NET and accessing IMAQ Vision 6.0.5 using C++.

I am trying to use imaqFindCircularEdge() and imaqFitEllipse() with limited luck.

Even when imaqFitEllipse() returns OK, I might get negative values for the center of the ellipse.

Is maybe imaqFitEllipse() using a separate scaling/unit than pixels, or what might be wrong?

I am working on binary images.

Thanks,
Torbjørn

Here is a snippet of my code:
--------------
if(bDoFitEllipse)
{
CircularEdgeReport* edgeReport;
Annulus searchArea; // circular search area used in imaqFindCircularEdge
FindEdgeOptions CircularEdgeOptions = {1, 4, 2, 5.0, TRUE, TRUE, TRUE, TRUE};
BestEllipse myBestEllipse;
searchArea.center.x = *cx;
searchArea.center.y = *cy;
searchArea.innerRadius = *b/3;
searchArea.outerRadius = *a;
searchArea.startAngle = 0.0;
searchArea.endAngle = 360.0;

//Locates a circular edge in an annular search area
edgeReport = imaqFindCircularEdge(myImage, searchArea, IMAQ_OUTSIDE_TO_INSIDE, &CircularEdgeOptions, NULL);

if(edgeReport != NULL)
{

if(imaqFitEllipse(edgeReport->coordinates, edgeReport->numCoordinates, &myBestEllipse) == 0)
{
printIMAQError("ERROR: CartDetect->getEllipseProperties():imaqFitEllipse");
} else {

//Print both center of mass and center based on ellipse fitting
printf("cx x: %4.2f %4.2f, cy y: %4.2f %4.2f\n",*cx,myBestEllipse.center.x,*cy,myBestEllipse.center.y);


}
}

imaqDisposeCircularEdgeReport(edgeReport);
}
0 Kudos
Message 1 of 2
(3,199 Views)
I think I found the problem regarding negative values. I was missing a simple check:

--------------------------
if(edgeReport != NULL)
--------------------------

should be:

---------------------------------------------------------
if(edgeReport != NULL && edgeReport->numCoordinates > minNumEdgePoints)
---------------------------------------------------------

Anyway - only in a few images from my stream I am able to successfully detect a circle, fit an ellipse and find the center using the code above.

Any examples on how I can make imaqFindCircularEdge() and imaqFitEllipse() work "robustly" together?

Thanks,
Torbjørn
0 Kudos
Message 2 of 2
(3,180 Views)