已经有一个有关如何在OpenCV中进行矩形检测的示例(请参见samples / squares.c),实际上非常简单。
这是他们使用的粗略算法:
0. rectangles <- {}
1. image <- load image
2. for every channel:
2.1 image_canny <- apply canny edge detector to this channel
2.2 for threshold in bunch_of_increasing_thresholds:
2.2.1 image_thresholds[threshold] <- apply threshold to this channel
2.3 for each contour found in {image_canny} U image_thresholds:
2.3.1 Approximate contour with polygons
2.3.2 if the approximation has four corners and the angles are close to 90 degrees.
2.3.2.1 rectangles <- rectangles U {contour}
他们所做的并不是确切的音译,但它可以为您提供帮助。
0
给定一个纯白色背景上的对象,有人知道OpenCV是否提供了可以轻松地从捕获的帧中检测对象的功能吗?
我正在尝试定位对象(矩形)的角/中心点。我当前的操作方式是蛮力(扫描对象的图像)并且不准确。我想知道是否存在我不知道的功能。
编辑详细信息 :大小与小汽水罐差不多。相机位于对象上方,以使其具有2D /矩形感。相机的方向/角度是随机的,这是根据拐角点计算得出的。
它只是一个白色背景,上面有对象(黑色)。拍摄质量与您期望从Logitech网络摄像头看到的图像有关。
一旦获得角点,就可以计算中心。然后将中心点转换为厘米。
我正在尝试着重于“如何”获得这四个角。你可以看到我的蛮力方法与此图像: 图片