OpenCV 对象检测 - 中心点 [英] OpenCV Object Detection - Center Point

查看:69
本文介绍了OpenCV 对象检测 - 中心点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Given an object on a plain white background, does anybody know if OpenCV provides functionality to easily detect an object from a captured frame?

我正在尝试定位对象(矩形)的角点/中心点.我目前这样做的方式是蛮力(扫描对象的图像)并且不准确.我想知道是否有我不知道的功能.

I'm trying to locate the corner/center points of an object (rectangle). The way I'm currently doing it, is by brute force (scanning the image for the object) and not accurate. I'm wondering if there is functionality under the hood that i'm not aware of.

编辑详细信息:大小和小苏打罐差不多.相机位于物体上方,使其具有 2D/矩形感觉.来自相机的方向/角度是随机的,根据角点计算.

Edit Details: The size about the same as a small soda can. The camera is positioned above the object, to give it a 2D/Rectangle feel. The orientation/angle from from the camera is random, which is calculated from the corner points.

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

It's just a white background, with the object on it (black). The quality of the shot is about what you'd expect to see from a Logitech webcam.

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

Once I get the corner points, I calculate the center. The center point is then converted to centimeters.

我正在努力改进如何"获得这 4 个角.你可以用这张图片看到我的蛮力方法:图片

It's refining just 'how' I get those 4 corners is what I'm trying to focus on. You can see my brute force method with this image: Image

推荐答案

在 OpenCV 中已经有一个如何进行矩形检测的示例(查看 samples/squares.c),实际上很简单.

There's already an example of how to do rectangle detection in OpenCV (look in samples/squares.c), and it's quite simple, actually.

这是他们使用的粗略算法:

Here's the rough algorithm they use:

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}

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

Not an exact transliteration of what they are doing, but it should help you.

这篇关于OpenCV 对象检测 - 中心点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆