程序未进入嵌套在while循环中的for循环

时间:2019-12-25 14:20:34

标签: python

haar_upper_body_cascade = cv2.CascadeClassifier("cascade.xml")

video_capture = cv2.VideoCapture("00011.MTS")
video_width = video_capture.get(3) #1280
video_height = video_capture.get(4) #720
print ("video loaded")

while True:
   ret, frame = video_capture.read()
   frame = imutils.resize(frame, width=800) # resize original video for better viewing performance
   gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # convert video to grayscale
   upper = haar_upper_body_cascade.detectMultiScale(gray, 1.4,6)
   print ("cascade loaded")

   # Draw a rectangle around the upper bodies
    for (x, y, wi, he) in upper :
        print("entered loop")
        cv2.rectangle(frame, (x, y), (x + wi, y + he), (0, 255, 0), 1) 
        cv2.putText(frame, "Seat Belt ON", (x + 5, y + 15), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) 
        path = 'G:/00004' 
        cv2.imwrite(os.path.join(path , str(counter) + '.jpg'), frame)
        counter += 1
        cv2.imshow('Video', frame) 

在我的代码中,程序未进入嵌套在while循环中的for循环。因此,输出是一个无限循环,显示“级联加载”。

有人可以帮我解决这个问题吗?

0 个答案:

没有答案