Salo7ty
Salo7ty

Reputation: 495

Point vs MCvPoint2D64f, What is the difference between them?

I am coding in project that is using ConnectedCompnents method

My code:

temp = img.ThresholdBinary(new Gray(50), new Gray(255));
Mat label=new Mat();
Mat stats = new Mat();
Mat centroid = new Mat();


int nlabels = CvInvoke.ConnectedComponentsWithStats(temp, label, stats, centroid);
MCvPoint2D64f[] centerpoints = new MCvPoint2D64f[nlabels];
Point[] centerpoints2 = new Point[nlabels];
centroid.CopyTo(centerpoints);
centroid.CopyTo(centerpoints2);

foreach (MCvPoint2D64f pt in centerpoints)
{
    textBox1.AppendText($"x : {pt.X}  ,  y : {pt.Y}");
    CvInvoke.Circle(img, new Point((int)pt.X,(int)pt.Y), 10,new MCvScalar(0,0,255),3);
}

foreach (Point pt in centerpoints2)
{
    textBox2.AppendText($"x : {pt.X}  ,  y : {pt.Y}");
    CvInvoke.Circle(img2, new Point(pt.X, pt.Y), 10, new MCvScalar(0, 0, 255), 3);
}

imageBox2.Image = img;
imageBox1.Image = img2;

There are difference values in centroidPoints with Point and MCvPoint2D64F when this values shows in textboxes.

And with {Point}, circles did not drawn but with MCvPoint2D64F it is drawn correctly

What is difference between them?

Upvotes: 1

Views: 106

Answers (1)

PeterJ
PeterJ

Reputation: 3791

The difference is that MCvPoint2D64F represents a point defined with double x / y coordinates whereas assuming a fairly standard set of using directives Point will be System.Drawing.Point that represents each point as a pair of integers. From the CvInvoke.ConnectedComponentsWithStats documentation you'll see:

centroids

Type: Emgu.CV.IOutputArray

Centroid output for each label, including the background label. Centroids are accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F.

The 64F designator on the data type indicates a 64-bit floating point value which is a double in C# so you should be using MCvPoint2D64F. EmguCV won't attempt to translate values in an output array so when you're using Point it will copy the binary floating point representation into integers which won't make sense.

Upvotes: 2

Related Questions