使用 OpenCV+Python-2.7 进行全身检测和跟踪
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34871294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Full body detection and tracking using OpenCV+Python-2.7
提问by ébe Isaac
There are a lot of materials available to do this with C++. I would to know if there is a way to do full body detection using OpenCV in Python-2.7?
有很多可用的材料可以用 C++ 做到这一点。我想知道是否有办法在 Python-2.7 中使用 OpenCV 进行全身检测?
Given video of a person walking along the sagittal plane (camera taken 90 degrees from the direction of walk), I would like to bound a region of interest rectangle covering the entire body of that person and track the same in movement frame by frame.
给定一个人沿着矢状面行走的视频(与行走方向成 90 度角的相机),我想限制一个覆盖该人整个身体的感兴趣区域矩形,并逐帧跟踪它的运动。
采纳答案by Arijit
This one is using the hog descriptor you can find the sample in samples/python/peopledetect.py I used the sample video provided by the opencv installation.
这个是使用hog描述符你可以在samples/python/peopledetect.py中找到示例我使用了opencv安装提供的示例视频。
import numpy as np
import cv2
def inside(r, q):
rx, ry, rw, rh = r
qx, qy, qw, qh = q
return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh
def draw_detections(img, rects, thickness = 1):
for x, y, w, h in rects:
# the HOG detector returns slightly larger rectangles than the real objects.
# so we slightly shrink the rectangles to get a nicer output.
pad_w, pad_h = int(0.15*w), int(0.05*h)
cv2.rectangle(img, (x+pad_w, y+pad_h), (x+w-pad_w, y+h-pad_h), (0, 255, 0), thickness)
if __name__ == '__main__':
hog = cv2.HOGDescriptor()
hog.setSVMDetector( cv2.HOGDescriptor_getDefaultPeopleDetector() )
cap=cv2.VideoCapture('vid.avi')
while True:
_,frame=cap.read()
found,w=hog.detectMultiScale(frame, winStride=(8,8), padding=(32,32), scale=1.05)
draw_detections(frame,found)
cv2.imshow('feed',frame)
ch = 0xFF & cv2.waitKey(1)
if ch == 27:
break
cv2.destroyAllWindows()