使用 OpenCV 计算网格上的对象
我对 OpenCV 比较陌生,我正在开发一个项目,需要计算网格上的对象数量。网格是图像的背景,每个空间中要么有物体,要么没有;我需要数一下在场的人数,但我真的不知道从哪里开始。我在这里和其他地方搜索过,但似乎找不到我要找的东西。将来我需要跟踪网格的空间编号,所以我最终还需要知道每个网格空间是被占用还是空的。我不会要求提供一个编码示例,但是有人知道完成此任务或类似任务的任何来源或教程吗?感谢您的帮助!
更多细节:图像将来自稳定安装的相机,物体的形状相对均匀,但大小和颜色各不相同。
I'm relatively new to OpenCV, and I'm working on a project where I need to count the number of objects on a grid. the grid is the background of the image, and there's either an object in each space or there isn't; I need to count the number present, and I don't really know where to start. I've searched here and other places, but can't seem to find what I'm looking for. I will need to be tracking the space numbers of the grid in the future, so I will also eventually need to know whether each grid space is occupied or empty. I'm not going so far as to ask for a coded example, but does anybody know of any source or tutorials to accomplish this task or one similar to it? Thanks for your help!
Further Details: images will come from a stable-mounted camera, objects are of relatively uniform shape, but varying size and color.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我首先回答几个问题:
给出这些问题的合理答案,我相信问题可以分为两部分:首先,确定每个网格空间的中心。要对对象进行计数,您可以对该区域进行采样以查看是否存在任何“非背景”的东西。
然后,您可以假设网格空间是由四个强大的、规则放置的角特征定义的。 (为了便于讨论,我假设您已经根据需要执行了初始图像准备:直方图均衡、用于降噪的高斯模糊等。)从那里,您可以尝试 OpenCV 的一些方法来查找角点(Harris 角点)检测器、cvGoodFeaturesToTrack 等)。您可能可以借用 OpenCV 平方查找示例 (samples/c/square.c) 中的一些技术。对于此任务,假设网格中心只是每组“相邻”(或足够接近)角点的质心就足够了。
或者,您可以使用霍夫变换来识别图像中的主要水平线和垂直线。然后,您可以确定交点来标识每个网格单元的范围。这种实现可能更具挑战性,因为从“附近”顶点推断结构(或邻接)以找到网格中心似乎更困难。
I would first answer a few questions:
Given reasonable answers to those questions, I believe the problem can be broken into two parts: first, identify the centers of each grid space. To count objects, you can then sample that region to see if anything "not background" is there.
You can then assume that a grid space is defined by four strong, regularly-placed, corner features. (For the sake of discussion, I'll assume you've performed the initial image preparation as needed: histogram equalization, gaussian blur for noise reduction, etc.) From there, you might try some of OpenCV's methods for finding corners (Harris corner detector, cvGoodFeaturesToTrack, etc). It's likely that you can borrow some of the techniques found in OpenCV's square finding example (samples/c/square.c). For this task, it's probably sufficient to assume that the grid center is just the centroid of each set of "adjacent" (or sufficiently near) corners.
Alternatively, you might use the Hough transform to identify the principal horizontal and vertical lines in the image. You can then determine the intersection points to identify the extents of each grid cell. This implementation might be more challenging since inferring structure (or adjacency) from "nearby" vertices in order to find a grid center seems more difficult.