使用 OpenCV 检测二值图像的分叉和端点
我想检测我拥有的二值图像中的分叉和端点。图像已经变细了。一直在阅读如何做到这一点的方法,但我不知道如何在 OpenCV 中实现它。我所知道的是,我必须使用 3x3 窗口来扫描整个图像。如果 3x3 窗口上的 0 像素之和小于或等于 5,则这是一个分叉,如果总和为 7,则这是一个终止分支,并且如果6 是一条连续线。
首先,我不知道如何在 OpenCV 中声明一个 3x3 窗口以及如何访问组成该窗口的 9 个块中的每一个。
其次,我怎样才能将窗口移动到图像上。将感谢您的帮助,示例代码也可以。
I want to detect bifurcations and endpoints in a binary image that I have. The image has already been thinned. Been reading on ways of how one can possible do this, but I don't know how I could go about implementing it in OpenCV. All I know is that I have to use a 3x3 window to scan the whole image.Then this is a bifurcation if the sum of 0 pixels on the 3x3 window are less or equal 5, is a terminate branch if the sum is 7 and if is 6 is a continuous line.
First of how, I don't know how to declare a 3x3 window in OpenCV and how to access each of the 9 blocks that make up the window.
Secondly how can I then move the window over the image. Will be grateful for your help, a sample code will also do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了获得矩阵的 3x3 窗口,您可以执行以下
操作注意:您获取的感兴趣区域只是原始矩阵内的引用,如果您想要副本,则需要调用窗户。这让我咬了好几次:D
要访问块内的像素,您可以使用 at() Mat 类的成员函数。像这样(假设您的图像是 CV_8UC1 类型):
另外,请注意 at() 成员有一点开销,因此如果您想快速查看使用数据指针来加快速度。
要移动窗口,您需要移动感兴趣的矩形区域的位置。 Rect 构造函数的前两个参数采用左上角的 x 和 y 位置作为起始位置。因此,您需要将图像分成块。
注意:您可能需要查看函数 copyMakeBorder 在图像尺寸不能被 3 整除的情况下在图像周围添加边框。
In order to get a 3x3 window of a matrix you can do the following
Note: That the region of interest you acquire is only a reference inside the original matrix if you want a copy you'll need to call the clone() member of the window. This has bit me a few times :D
To access a pixel within the block you can use the at() member function of the Mat class. Like this (assuming your image is of type CV_8UC1):
Also, note the at() member has a bit of overhead, so if you want fast look at using the data pointer to speed things up.
To move the window around, you need to shift where the rectangle region of interest is. The first two parameters of the Rect constructor take the upper-left x and y locations to start at. So you'll need to divide your image into blocks.
Note: you may need to look that the function copyMakeBorder to add a border around your image for the cases when your image dimensions are not divisible by 3.