使用 OpenCV 计算网格上的对象

发布于 2024-11-06 08:46:04 字数 256 浏览 0 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泛滥成性 2024-11-13 08:46:04

我首先回答几个问题:

  1. 一个物体会被完全封闭在网格单元中吗?或者可以将其放置在网格线的顶部吗? (换句话说,该对象是否会在相机中隐藏一条线?)
  2. 一个单元格中是否会存在多个对象?
  3. 一个物体可以占据多个单元格吗? (与问题1密切相关)

给出这些问题的合理答案,我相信问题可以分为两部分:首先,确定每个网格空间的中心。要对对象进行计数,您可以对该区域进行采样以查看是否存在任何“非背景”的东西。

然后,您可以假设网格空间是由四个强大的、规则放置的角特征定义的。 (为了便于讨论,我假设您已经根据需要执行了初始图像准备:直方图均衡、用于降噪的高斯模糊等。)从那里,您可以尝试 OpenCV 的一些方法来查找角点(Harris 角点)检测器、cvGoodFeaturesToTrack 等)。您可能可以借用 OpenCV 平方查找示例 (samples/c/square.c) 中的一些技术。对于此任务,假设网格中心只是每组“相邻”(或足够接近)角点的质心就足够了。

或者,您可以使用霍夫变换来识别图像中的主要水平线和垂直线。然后,您可以确定交点来标识每个网格单元的范围。这种实现可能更具挑战性,因为从“附近”顶点推断结构(或邻接)以找到网格中心似乎更困难。

I would first answer a few questions:

  1. Will an object be completely enclosed in a grid cell? Or can it be placed on top of a grid line? (In other words, will the object hide a line from the camera?)
  2. Will more than one object be in one cell?
  3. Can an object occupy more than one cell? (closely related to question 1)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文