背景差分により動体検知を行い、動体を矩形で囲んだあとに矩形で囲まれた対象に対して人であるかどうかの識別をしたいのですが、どのようにしたら実現できるでしょうか?
すでに人認識用のカスケードはあります。
bodycascade = cv2.CascadeClassifier(r'bodycascades.xml')
python
1import numpy as np 2import cv2 3import sys 4 5path=(r"mp4") 6cv2.ocl.setUseOpenCL(False) 7 8 9#read video file 10cap = cv2.VideoCapture(path) 11 12 13fgbg = cv2.createBackgroundSubtractorMOG2(500,150,False) 14 15 16while (cap.isOpened): 17 18 #if ret is true than no error with cap.isOpened 19 ret, frame = cap.read() 20 21 22 if ret==True: 23 24 #apply background substraction 25 fgmask = fgbg.apply(frame) 26 blur=cv2.GaussianBlur(fgmask,(15,15),0) 27 28 29 (im2, contours, hierarchy) = cv2.findContours(fgmask.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) 30 31 #looping for contours 32 for c in contours: 33 if cv2.contourArea(c) < 15000: 34 continue 35 36 #輪郭から矩形を作る 37 (x, y, w, h) = cv2.boundingRect(c) 38 39 40 #矩形を描画 41 rect=cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2) 42 43 cv2.imshow('foreground and background',fgmask) 44 cv2.imshow('rgb',frame) 45 if cv2.waitKey(1) & 0xFF == ord("q"): 46 break 47cv2.namedWindow("foreground and background", cv2.WINDOW_NORMAL) 48cv2.namedWindow("rgb", cv2.WINDOW_NORMAL) 49 50 51cap.release() 52cv2.destroyAllWindows() 53
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/21 08:15
2019/02/21 08:19 編集
2019/02/21 10:40