简体   繁体   English

在 OpenCV 中查找子像素中的轮廓点

[英]Finding contour points in subpixel in OpenCV

If we find contours for an image using cv2.findContours() , the co-ordinates present in each contour are of datatype of int32.如果我们使用cv2.findContours()找到图像的轮廓,则每个轮廓中存在的坐标的数据类型为 int32。 Example: Printing contours[0] gives,示例:打印contours[0]给出,

array([[[0,1]],
       [[1,1]],
          .
          .
          .
       [[400,232]]])

Is there any way to find the co-ordinates in the contour with the higher precision (subpixel)?有没有办法以更高的精度(亚像素)找到轮廓中的坐标?

array([[[0.11,1.78]],
       [[1.56,1.92]],
          .
          .
          .
       [[400.79,232.35]]])

In principle, in a properly sampled gray-scale image you do have information to guess at the location with sub-pixel precision.原则上,在正确采样的灰度图像中,您确实有信息可以以亚像素精度猜测位置。 But it's still a guess.但这仍然是一个猜测。 I'm not aware of any existing algorithms that try to do this, I only know of algorithms that trace the contour in a binary image.我不知道有任何尝试这样做的现有算法,我只知道在二进制图像中追踪轮廓的算法。

There have been a few papers published (that I'm aware of) that try to simplify the outline polygon in a way that you get a better representation of the underlying contour.已经发表了几篇论文(我知道)试图以一种更好地表示底层轮廓的方式来简化轮廓多边形。 These papers all make an assumption of smoothness that allows them to accomplish their task, without such an assumption there is no other information in the binary image than what is extracted by the simple pixel contour algorithm.这些论文都做出了允许他们完成任务的平滑度假设,如果没有这样的假设,二值图像中除了简单像素轮廓算法提取的信息之外没有其他信息。 The simplest method in this category is smoothing the polygon: move each vertex a little closer to the line formed by its two neighboring vertices.此类别中最简单的方法是平滑多边形:将每个顶点稍微靠近其两个相邻顶点形成的线。

If the goal however is to get more precise measurements of the object, then there are several different approaches to use the gray-value data to significantly improve the precision of these measurements.然而,如果目标是对物体进行更精确的测量,那么有几种不同的方法可以使用灰度值数据来显着提高这些测量的精度。 I'm familiar with two of them:我熟悉其中两个:

  • LJ van Vliet, “Gray-scale measurements in multi-dimensional digitized images”, PhD thesis Delft University of Technology, 1993. PDF LJ van Vliet,“多维数字化图像中的灰度测量”,代尔夫特理工大学博士论文,1993 年。PDF
  • N. Sladoje and J. Lindblad, “High Precision Boundary Length Estimation by Utilizing Gray-Level Information”, IEEE Transactions on Pattern Analysis and Machine Intelligence 31(2):357-363, 2009. DOI N. Sladoje 和 J. Lindblad,“利用灰度信息进行高精度边界长度估计”,IEEE 模式分析和机器智能汇刊 31(2):357-363, 2009。DOI

The first one does area, perimeter and local curvature in 2D (higher dimensions lead to additional measurements), based on the assumption of a properly sampled band-limited image.第一个基于适当采样的带限图像的假设,在 2D 中进行面积、周长和局部曲率(更高的维度导致额外的测量)。 The latter does length, but is the start point of the “pixel coverage” model: the same authors have papers also on area and Feret diameters.后者确实有长度,但它是“像素覆盖”模型的起点:同一作者也有关于面积和 Feret 直径的论文。 This model assumes area sampling of a sharp boundary.该模型假设锐边界的区域采样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM