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

How can I detect and track people using OpenCV?(如何使用 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 检测和跟踪人员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Reading *.mhd/*.raw format in python(在 python 中读取 *.mhd/*.raw 格式)
Count number of cells in the image(计算图像中的单元格数)
How to detect paragraphs in a text document image for a non-consistent text structure in Python OpenCV(如何在 Python OpenCV 中检测文本文档图像中的段落是否存在不一致的文本结构)
How to get the coordinates of the bounding box in YOLO object detection?(YOLO物体检测中如何获取边界框的坐标?)
Divide an image into 5x5 blocks in python and compute histogram for each block(在 python 中将图像划分为 5x5 块并计算每个块的直方图)
Extract cow number from image(从图像中提取奶牛编号)