問題描述
我有一個固定的相機,指向室內區域.人們會在距離它約 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 檢測和跟蹤人員?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!