2017-08-01 3 views
2

OpenCVのHOG検出器を使用して、ビデオ内の歩行者を検出しています。しかし、それによって返される境界ボックスはdetectMultiScale()に1つの負の値を持ちます。私はこの問題を理解し解決するために、これまでインターネット上で役に立つものや有用なものを見つけることができませんでした。私はなぜこの問題が発生しているのか分からない。それが出力です。PythonとopenCV:HOG記述子がMultiscaleで負のバウンディングボックスを返す

RECTS: [[183 -6 68 137] 
[ 76 -7 76 152]] 
WEIGHTS: [[ 1.21099767] 
[ 0.37004868]] 

HERESに私のコード:

hog = cv2.HOGDescriptor() 
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector()) 

webcam = cv2.VideoCapture ('/home/irum/Desktop/Test-Videos/pedistrianTestVideoLONG.mp4') 




while True: 
    # read each frame 
    ret, frame = webcam.read() 
    # resize it 
    image = imutils.resize(frame, width=min(300, frame.shape[1])) 
    orig = image.copy() 

    # detect people in the frame 
    (rects, weights) = hog.detectMultiScale(image, winStride=(4, 4), 
     padding=(8, 8), scale=1.1) 
    print('RECTS: ',rects) 
    print('WEIGHTS: ',weights) 
    print('LENGTH: ',len(rects)) 

    # draw the original bounding boxes 
    #for (x, y, w, h) in rects: 
    for i in range(len(rects)): 

     body_i = rects[i] 
     print('BODY_I: ',body_i) 

     (x, y, w, h) = [v * 1 for v in body_i] 
     print ('DETECTION (x, y, w, h)',x, y, w, h) 

     cv2.rectangle(orig, (x, y), (x + w, y + h), (0, 0, 255), 2) 

     # apply non-maxima suppression 
     rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects]) 
     pick = non_max_suppression(rects, probs=None, overlapThresh=0.65) 

     # draw the final bounding boxes 

     for i in range(len(pick)): 

      g += 1 

      body_p = pick[i] 

      (xA, yA, xB, yB) = [int(v * 1) for v in body_p] 
      print('DETECTION NMS (xA, yA, xB, yB)', xA, yA, xB, yB) 

      # rect on scaled image 
      cv2.rectangle(image, (xA, yA), (xB, yB), (0, 255, 0), 2) 

      # rects to map on original frame 
      (x1, y1, w1, h1) = [int(v * 4.28) for v in body_p] 
      print('(x1, y1, w1, h1) ' ,x1, y1, w1, h1) 

      cv2.rectangle(frame, (x1, y1), (w1, h1), (0, 45, 255), 2) 

      # Crop body from Original frame 
      body_big = frame[y1:h1, x1:w1] 

      print('DISPLAY') 
      cv2.imshow("BODY", body_big) 

      # Save body 
      save_body_path = '/home/irum/Desktop/pedestrian-detection/BIG_BODY' 

      cur_date = (time.strftime("%Y-%m-%d")) 
      cur_time = (time.strftime("%H:%M:%S")) 
      new_pin =cur_date+"-"+cur_time 
      filename1 = 'BIG' 
      filename2 = str(g)+str(filename1)+'-'+str(new_pin) 
      #print ("IMAGE TO SEND: ",filename2) 

      sampleFile = ('%s/%s.jpg' % (save_body_path, filename2)) 
      #print ("sampleFile",sampleFile) 

      cv2.imwrite('%s/%s.jpg' % (save_body_path, filename2), body_big) 
      #pyplot.imsave('%s.jpg' % (sampleFile), body_big) 



    # show the output images 
    cv2.imshow("Before NMS", orig) 
    cv2.imshow("After NMS", image) 
    cv2.imshow("BIG BODY", frame) 
    # cv2.imshow("FACE", body_big2) 
    key = cv2.waitKey(10) 
    if key == 27: 
     break 

答えて

1

インターネット上のほとんどすべてを試した後、私は答えを見つけることができませんでしたがどこにも私は、この問題を分析し、自分自身を開始し、それに解決策を見つけました。

(rects, weights) = hog.detectMultiScale(image, winStride=(4, 4), 
     padding=(0, 0), scale=1.1) 

私は(0,0)に引数padding値を変更し、それは私の問題を解決しました。そして、問題は、ボディがパディングのためにフレームの角で検出されたときに、トリミング中にフレームの側面からスペースを取っていたが、空きスペースがなかったので、それが私にネガティブを与えていた。

関連する問題