How can I detect and track people using OpenCV?(如何使用 OpenCV 检测和跟踪人员?)
问题描述
我有一个固定的相机,指向室内区域.人们会在距离它约 5 米的范围内经过摄像头.使用 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. Using OpenCV, I want to detect individuals walking past - my ideal return is an array of detected individuals, with bounding rectangles.
我查看了几个内置示例:
I've looked at several of the built-in samples:
- 没有一个 Python 示例真正适用
- C blob 跟踪示例看起来很有希望,但不接受实时视频,这使得测试变得困难.它也是样本中最复杂的,使得提取相关知识并将其转换为 Python API 存在问题.
- C 'motempl' 示例看起来也很有前景,因为它会根据后续视频帧计算轮廓.大概我可以使用它来找到强连接的组件并提取单个 blob 及其边界框 - 但我仍然试图找出一种方法来将在后续帧中发现的 blob 识别为同一个 blob.
- None of the Python samples really apply
- The C blob tracking sample looks promising, but doesn't accept live video, which makes testing difficult. It's also the most complicated of the samples, making extracting the relevant knowledge and converting it to the Python API problematic.
- The C 'motempl' sample also looks promising, in that it calculates a silhouette from subsequent video frames. 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.
有没有人可以提供指导或示例 - 最好是在 Python 中?
Is anyone able to provide guidance or samples for doing this - preferably in Python?
推荐答案
最新的 SVN 版本的 OpenCV 包含一个(未记录的)基于 HOG 的行人检测的实现.它甚至带有一个预训练的检测器和一个 python 包装器.基本用法如下:
The latest SVN version of OpenCV contains an (undocumented) implementation of HOG-based pedestrian detection. It even comes with a pre-trained detector and a python wrapper. 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.
请参阅 src/cvaux/cvhog.cpp
了解实现,参阅 samples/python/peopledetect.py
了解更完整的 Python 示例(均在 OpenCV 源代码中).
See src/cvaux/cvhog.cpp
for the implementation and samples/python/peopledetect.py
for a more complete python example (both in the OpenCV sources).
这篇关于如何使用 OpenCV 检测和跟踪人员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 OpenCV 检测和跟踪人员?
基础教程推荐
- Python 的 List 是如何实现的? 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01