视频行人检测系统
目的
设计一个视频行人检测系统,能够分割出多个行人。
代码
import cv2
import numpy as np
#判断是否处于人像区域
def is_inside(o, i):
ox, oy, ow, oh = o
ix, iy, iw, ih = i
return ox > ix and oy > iy and ox + ow < ix + iw and oy + oh < iy + ih
#读取视频文件
cap= cv2.VideoCapture("lzq3.mp4")
#cap= cv2.VideoCapture(0)
while (True):
#读取视频帧图像
ret, frame = cap.read()
# 进行行人检测
hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
found, w = hog.detectMultiScale(frame)
found_filtered = []
for ri, r in enumerate(found):
for qi, q in enumerate(found):
if ri != qi and is_inside(r, q):
break
else:
found_filtered.append(r)
# 用蓝线框出人像区域
for person in found_filtered:
x, y, w, h = person
cv2.rectang