简体   繁体   English

如何使用OpenCV检测和跟踪人员?

[英]How can I detect and track people using OpenCV?

I have a camera that will be stationary, pointed at an indoors area. 我有一台固定的相机,指向室内区域。 People will walk past the camera, within about 5 meters of it. 人们将走过相机,距离相机约5米。 Using OpenCV , I want to detect individuals walking past - my ideal return is an array of detected individuals, with bounding rectangles. 使用OpenCV ,我想检测走过的人-我的理想回报是一组检测到的具有矩形边界的人。

I've looked at several of the built-in samples: 我看了几个内置示例:

  • None of the Python samples really apply 没有一个Python示例真正适用
  • The C blob tracking sample looks promising, but doesn't accept live video, which makes testing difficult. C blob跟踪示例看起来很有希望,但不接受实时视频,这使测试变得困难。 It's also the most complicated of the samples, making extracting the relevant knowledge and converting it to the Python API problematic. 它也是最复杂的示例,使得提取相关知识并将其转换为有问题的Python API。
  • The C 'motempl' sample also looks promising, in that it calculates a silhouette from subsequent video frames. C “ motempl”样本看起来也很有希望,因为它可以从后续视频帧中计算出轮廓。 Presumably I could then use that to find strongly connected components and extract individual blobs and their bounding boxes - but I'm still left trying to figure out a way to identify blobs found in subsequent frames as the same blob. 大概我可以使用它来找到强连接的组件并提取单个斑点及其边界框-但是我仍然试图找出一种方法来将在后续帧中发现的斑点识别为同一斑点。

Is anyone able to provide guidance or samples for doing this - preferably in Python ? 有没有人能够提供指导或示例来进行此操作-最好是在Python中

The latest SVN version of OpenCV contains an (undocumented) implementation of HOG-based pedestrian detection. OpenCV的最新SVN版本包含(未记录)基于HOG的行人检测的实现。 It even comes with a pre-trained detector and a python wrapper. 它甚至带有预训练的检测器和python包装器。 The basic usage is as follows: 基本用法如下:

from cv import *

storage = CreateMemStorage(0)
img = LoadImage(file)  # or read from camera

found = list(HOGDetectMultiScale(img, storage, win_stride=(8,8),
                padding=(32,32), scale=1.05, group_threshold=2))

So instead of tracking, you might just run the detector in each frame and use its output directly. 因此,您可以只在每帧中运行检测器并直接使用其输出,而不是进行跟踪。

See src/cvaux/cvhog.cpp for the implementation and samples/python/peopledetect.py for a more complete python example (both in the OpenCV sources). 有关实现的信息,请参见src/cvaux/cvhog.cpp ;对于更完整的python示例(请参见OpenCV源代码),请参见samples/python/peopledetect.py

Nick, 缺口,

What you are looking for is not people detection, but motion detection. 您要找的不是人检测,而是运动检测。 If you tell us a lot more about what you are trying to solve/do, we can answer better. 如果您向我们详细介绍了您要解决的问题/我们将做的更好。 Anyway, there are many ways to do motion detection depending on what you are going to do with the results. 无论如何,有许多方法可以进行运动检测,具体取决于要对结果进行的处理。 Simplest one would be differencing followed by thresholding while a complex one could be proper background modeling -> foreground subtraction -> morphological ops -> connected component analysis, followed by blob analysis if required. 最简单的方法是先进行差分,然后进行阈值处理,而复杂的操作可能是适当的背景建模->前景减法->形态学操作->连通成分分析,然后根据需要进行斑点分析。 Download the opencv code and look in samples directory. 下载opencv代码并查看示例目录。 You might see what you are looking for. 您可能会看到想要的东西。 Also, there is an Oreilly book on OCV. 另外,有一本关于OCV的Oreilly书。

Hope this helps, Nand 希望这会有所帮助,南德

This is clearly a non-trivial task. 显然,这是一项艰巨的任务。 You'll have to look into scientific publications for inspiration ( Google Scholar is your friend here). 您必须研究科学出版物以获得灵感( Google学术搜索是您的朋友)。 Here's a paper about human detection and tracking: Human tracking by fast mean shift mode seeking 这是一篇关于人体检测和追踪的论文: 通过快速均值漂移模式搜索进行人体追踪

This is similar to a project we did as part of a Computer Vision course, and I can tell you right now that it is a hard problem to get right. 这类似于我们在“计算机视觉”课程中所做的一个项目,我现在可以告诉您,这是一个很难解决的问题。

You could use foreground/background segmentation, find all blobs and then decide that they are a person. 您可以使用前景/背景分割,找到所有斑点,然后确定它们是一个人。 The problem is that it will not work very well since people tend to go together, go past each other and so on, so a blob might very well consist of two persons and then you will see that blob splitting and merging as they walk along. 问题在于,由于人们倾向于走到一起,彼此走过去等等,它无法很好地工作,所以一个斑点可能很好地由两个人组成,然后您会看到这些斑点在行走时分裂并合并。

You will need some method of discriminating between multiple persons in one blob. 您将需要一种在一个斑点中区分多个人的方法。 This is not a problem I expect anyone being able to answer in a single SO-post. 我希望这不是问题,任何人都可以在一个SO帖子中回答。

My advice is to dive into the available research and see if you can find anything there. 我的建议是深入研究可用的研究,看看您是否能在其中找到任何东西。 The problem is not unsolvavble considering that there exists products which do this: Autoliv has a product to detect pedestrians using an IR-camera on a car, and I have seen other products which deal with counting customers entering and exiting stores. 考虑到存在可以做到这一点的产品,这个问题并非无法解决:Autoliv有一款产品可以使用汽车上的红外摄像头检测行人,我还看到了其他产品,可以统计进入和退出商店的顾客。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM