使用OpenCV Python-2.7进行全身检测和跟踪
作者:互联网
使用C可以使用很多材料.我想知道是否有办法在Python-2.7中使用OpenCV进行全身检测?
鉴于一个人沿着矢状平面行走的视频(摄像机从行走方向取90度),我想将一个感兴趣的区域限制在覆盖整个人体的矩形上,并逐帧跟踪运动.
解决方法:
这个是使用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()
结果
标签:object-detection,python,python-2-7,opencv 来源: https://codeday.me/bug/20190926/1822098.html