现在,我正在使用openCV在Python2.7中编写实时人体检测程序。我编写的代码严重慢,它指的是[示例代码]
我写的代码如下。
from cv import *
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
NamedWindow("people detection demo", 1)
storage = CreateMemStorage(0)
capture = CaptureFromCAM(0)
SetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 600)
SetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 450)
while True:
img = QueryFrame(capture)
found = list(HOGDetectMultiScale(img, storage, win_stride=(8,8),
padding=(32,32), scale=1.05, group_threshold=2))
found_filtered = []
for r in found:
insidef = False
for q in found:
if inside(r, q):
insidef = True
break
if not insidef:
found_filtered.append(r)
for r in found_filtered:
(rx, ry), (rw, rh) = r
tl = (rx + int(rw*0.1), ry + int(rh*0.07))
br = (rx + int(rw*0.9), ry + int(rh*0.87))
Rectangle(img, tl, br, (0, 255, 0), 3)
ShowImage("people detection demo", img)
if WaitKey(10) == ord('q'):
break
只能很好地处理一幅图像,但是我想实现实时图像。有谁知道如何加快实时人体检测程序?
调整比例参数。它表示有多少检测器缩放跟踪窗口,即它从某个固定尺寸开始,如果找不到,将尺寸乘以比例因子等。它不必为1.05,可以设置1.1或1.2甚至更高时间消耗和检测率(不要设置得太高,因为检测率会迅速降低)。
如果您不必使用python,请考虑使用c ++ API。它具有GPU支持,可以加速数倍。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句