OpenCV对象检测 - 中心点

Dav*_*raw 33 opencv image-processing object-detection

给定纯白色背景上的对象,是否有人知道OpenCV是否提供了从捕获的帧中轻松检测对象的功能?

我正在尝试找到一个对象(矩形)的角点/中心点.我目前正在做的方式是蛮力(扫描物体的图像)而不准确.我想知道引擎盖下是否有功能我不知道.

编辑细节:大小与小苏打相同.相机位于物体上方,为其提供2D /矩形感.来自相机的方向/角度是随机的,这是从角点计算的.

它只是一个白色背景,上面有物体(黑色).拍摄的质量与您希望从Logitech网络摄像头看到的一致.

一旦我得到角点,我计算中心.然后将中心点转换为厘米.

它正在精炼'我如何'获得这四个角落是我正在努力关注的.您可以使用此图像查看我的强力方法:图像

Ism*_*l C 26

已经有一个如何在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}
Run Code Online (Sandbox Code Playgroud)

不是他们正在做的事情的确切音译,但它应该对你有所帮助.


小智 7

希望这有所帮助,使用矩量法得到黑白图像的质心.

cv::Point getCentroid(cv::Mat img)
{
    cv::Point Coord;
    cv::Moments mm = cv::moments(img,false);
    double moment10 = mm.m10;
    double moment01 = mm.m01;
    double moment00 = mm.m00;
    Coord.x = int(moment10 / moment00);
    Coord.y = int(moment01 / moment00);
    return Coord;
}
Run Code Online (Sandbox Code Playgroud)