边界矩形本质上是一个包含包围所选轮廓/特征的最小矩形的 x 位置、y 位置、宽度和高度。 typedef 结构体 CvRect { 整数x; 整数y; 整数宽度; int 高度; } CvRect;
自然地,对于你的图片,我会比较轮廓的 y 位置,并选择接近的轮廓。
此外,结构中的宽度和高度字段将告诉您尺寸的相似性。
注意:相同的区域可能并不总是表示相同的大小。例如。 a*b=ab,也 (a/4)*(4b)=ab,但大小几乎不同。代码示例是用 C 编写的,但我认为用 C# 来解决它并不会太难。希望这对你有用!
As you mentioned, if only same size and lying on the same line (approximately) are the criteria then here's another way of going about it.
Find connected components (guess you could loosely call that blob detecting, not sure) using the OpenCV function cvFindContours(). This link provides working code to do that.
Compute the Bounding Rectangle of each contour as you step through the list of all contours present in the picture.
The Bounding Rectangle is essentially a CvRect struct containing the x-position, y-position, width and height of the smallest rectangle that encloses the selected contour/feature. typedef struct CvRect { int x; int y; int width; int height; } CvRect;
Naturally for your picture I'd compare the y-positions of the contours are select the ones that are close.
Additionally the width and height fields in the structure will tell you about the similarity in size.
Note: same area may not always indicate same size. eg. a*b=ab, also (a/4)*(4b)=ab but hardly of same size. Code samples are in C but I think figuring it out in C# won't be too hard. Hope this works for you!
I would suggest doing a Blob detection and determine the center of gravity and the area of the blob. I am assuming that the rectangels in the image would be filled with black? If not then this step has to put before the blob extraction. With this coordinates you can calculate the difference between the points and a line. By moving the line in the image you get different "error". See here how to calculate this error (just one example)
When minimizing this error, then you have you line.
To calculate the error you might also consider first to filter the blob coordinates by the size of the blobs (only about the same size)
发布评论
评论(2)
正如您所提到的,如果只有相同的大小和位于同一条线上(大约)是标准,那么这是另一种方法。
使用 OpenCV 函数 cvFindContours() 查找连接的组件(我猜您可以松散地调用该斑点检测,不确定)。 此链接提供了执行此操作的工作代码。
当您逐步浏览列表时,计算每个轮廓的边界矩形图片中存在的所有轮廓。
边界矩形本质上是一个包含包围所选轮廓/特征的最小矩形的 x 位置、y 位置、宽度和高度。
typedef 结构体 CvRect
{
整数x;
整数y;
整数宽度;
int 高度;
}
CvRect;
自然地,对于你的图片,我会比较轮廓的 y 位置,并选择接近的轮廓。
注意:相同的区域可能并不总是表示相同的大小。例如。 a*b=ab,也 (a/4)*(4b)=ab,但大小几乎不同。代码示例是用 C 编写的,但我认为用 C# 来解决它并不会太难。希望这对你有用!
As you mentioned, if only same size and lying on the same line (approximately) are the criteria then here's another way of going about it.
Find connected components (guess you could loosely call that blob detecting, not sure) using the OpenCV function cvFindContours(). This link provides working code to do that.
Compute the Bounding Rectangle of each contour as you step through the list of all contours present in the picture.
The Bounding Rectangle is essentially a CvRect struct containing the x-position, y-position, width and height of the smallest rectangle that encloses the selected contour/feature.
typedef struct CvRect
{
int x;
int y;
int width;
int height;
}
CvRect;
Naturally for your picture I'd compare the y-positions of the contours are select the ones that are close.
Note: same area may not always indicate same size. eg. a*b=ab, also (a/4)*(4b)=ab but hardly of same size. Code samples are in C but I think figuring it out in C# won't be too hard. Hope this works for you!
我建议进行斑点检测并确定斑点的重心和面积。我假设图像中的矩形将填充黑色?如果不是,则此步骤必须放在斑点提取之前。通过这个坐标,您可以计算点和线之间的差异。通过移动图像中的线,您会得到不同的“错误”。请参阅此处如何计算此误差(仅一个示例
) /en.wikipedia.org/wiki/Simple_linear_regression" rel="noreferrer">最小化这个错误,然后你就可以了。
要计算误差,您还可以考虑首先按斑点大小过滤斑点坐标(仅大约相同大小)
I would suggest doing a Blob detection and determine the center of gravity and the area of the blob. I am assuming that the rectangels in the image would be filled with black? If not then this step has to put before the blob extraction. With this coordinates you can calculate the difference between the points and a line. By moving the line in the image you get different "error". See here how to calculate this error (just one example)
When minimizing this error, then you have you line.
To calculate the error you might also consider first to filter the blob coordinates by the size of the blobs (only about the same size)