2017-02-15 8 views
1

私はウェブカメラを使用している人を検出しようとしています。
私は既にビデオを使用している人を検出しようとしました。
ビデオからウェブカメラに変更すると検出が機能しません。
ホッグ人検出opencv WEBCAMを使用

ウェブカメラをサポートするにはどうすればよいですか?

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(0) 
while True: 
    ret,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) 
    if cv2.waitKey(1) & 0xFF == ord('e'): 
      break 
cap.release() 
cv2.destroyAllWindows() 
+0

ビデオとウェブカメラからサンプルの人物画像を投稿できますか? – Micka

答えて

1

それは通常のビデオで動作する場合に処理されたフレームは、(すなわち、あまりにも多くのノイズ、大きすぎる人など)大きく変化しない限り、それはウェブカメラでは動作しないだろう、なぜ、私が見ることができません。

ウェブカメラから画像を取得していますか(コードには表示されません)。それがUSBウェブカメラなら、OpenCV VideoReaderの機能を使ってすべてがうまくいく可能性が高いです。あなたはループの中であなたのウェブカメラからフレームを次々と取得します。このチュートリアルで詳しく説明しています。 http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html