Python openCV中的实时人体检测

时间:2014-03-17 12:59:59

标签: python opencv image-processing

现在我用openCV在Python2.7中编写实时人体检测程序。 我写的代码非常慢,指的是[sample code]

我写的代码如下。

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

只有一个图像处理得很好,但我想实现一个实时图像。 有谁知道如何加速实时人体检测程序?

0 个答案:

没有答案