Point vs MCvPoint2D64f,它们有什么区别?
Point vs MCvPoint2D64f, What is the difference between them?
我在使用 ConnectedCompnents 方法的项目中编码
我的代码:
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;
在文本框中显示此值时,Point
和 MCvPoint2D64F
的质心点值存在差异。
对于 {Point},圆没有画出来,但是 MCvPoint2D64F
画得正确
它们有什么区别?
区别在于 MCvPoint2D64F
表示用 double
x / y 坐标定义的点,而假设一组相当标准的使用指令 Point
将是 System.Drawing.Point that represents each point as a pair of integers. From the CvInvoke.ConnectedComponentsWithStats 文档你会看到:
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.
数据类型上的 64F 指示符表示 64 位浮点值,在 C# 中是 double
,因此您应该使用 MCvPoint2D64F
。 EmguCV 不会尝试转换输出数组中的值,因此当您使用 Point
时,它会将二进制浮点表示复制为没有意义的整数。
我在使用 ConnectedCompnents 方法的项目中编码
我的代码:
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;
在文本框中显示此值时,Point
和 MCvPoint2D64F
的质心点值存在差异。
对于 {Point},圆没有画出来,但是 MCvPoint2D64F
画得正确
它们有什么区别?
区别在于 MCvPoint2D64F
表示用 double
x / y 坐标定义的点,而假设一组相当标准的使用指令 Point
将是 System.Drawing.Point that represents each point as a pair of integers. From the CvInvoke.ConnectedComponentsWithStats 文档你会看到:
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.
数据类型上的 64F 指示符表示 64 位浮点值,在 C# 中是 double
,因此您应该使用 MCvPoint2D64F
。 EmguCV 不会尝试转换输出数组中的值,因此当您使用 Point
时,它会将二进制浮点表示复制为没有意义的整数。