Home > Back-end >  imshow freezes when closing down in jupyter notebook
imshow freezes when closing down in jupyter notebook

Time:01-03

I'm trying to detect three types of fruit using a model and opencv for the webcam. Everything works, but when i try to close it down it freezes and i have to use task manager to close it down. This is the code I'm using:

cap = cv2.VideoCapture(0)
while True: 
    ret,img=cap.read()
    cv2.startWindowThread()
    cv2.imshow('Video', img)
    img = cv2.resize(img, (224, 224))
    pred = what_fruit(img)
    print(pred)

    if cv2.waitKey(1) == ord("q"):
            break

Is there a way to use opencv webcam and have it close down correctly in notebook?

CodePudding user response:

It appears you forgot two lines of code after the while loop:

cap.release()
cv2.destroyAllWindows()
  • Related