0

Very simple code

import cv2
cap = cv2.VideoCapture('../data/videos/cat.mp4')
ret, frame = cap.read()

cv2.imshow('Hi', frame)
cv2.waitKey(0)
cv2.destroyAllWindows()

It opens the first frame as expected and shows it. When I press a key however, python refuses to respond and I get Application not responding leading to a crash after a while or me having to manually force quit it.

I'm running it in a Jupyter notebook in VSCode (using the extension). Strange thing is that when I run this code in a .py file inside VSCode, it does work as expected. I see a million and one threads about this but they mostly give the advice add waitKey and destroyAllWindows but I haven't come across one using ipynb in VSCode. Anyone knows how to fix this?

RogerKint
  • 454
  • 5
  • 13
  • 1
    imshow + waitKey should work even from within jupyter, but it WILL HALT the notebook kernel until you actually return from the waitKey call. this should not be surprising. -- make sure `frame is not None`. you MUST error-check any usage of VideoCapture. it does not throw exceptions. – Christoph Rackwitz Jan 11 '23 at 14:40
  • @M.Spiller No I have gone through that post before making my own :(. Suggestions like setting waitKey to a positive value don't work either. – RogerKint Jan 11 '23 at 14:43
  • Find out, which line causes the problem. I.e. put each line into a dedicated notebook cell and execute individually, inspecting the return values. I still suspect that it will freeze when calling `imshow` – MSpiller Jan 11 '23 at 15:24

0 Answers0