opencv.imshow will cause jupyter notebook crash

后端 未结 8 1454
借酒劲吻你
借酒劲吻你 2021-01-31 07:46

I check other question on google or stackoverflow, they are talking about run cv2.imshow in script, but my code run in jupyter notebook.

Here is my configuration:

<
8条回答
  •  一整个雨季
    2021-01-31 08:39

    This will help you understand what is happening:

    import cv2
    cvim2disp = cv2.imread('data/home.jpg')
    cv2.imshow('HelloWorld', cvim2disp)
    cv2.waitKey(0) 
    cv2.destroyWindow('HelloWorld')
    

    waitKey(0) method is waiting for an input infinitely. When you see a frame of the corresponding image, do not try to close the image using close in top right corner.

    Instead press some key. waitkey method will take that as an input and it will return back a value. Further you can also check which key was pressed to close the frame.

    Additionally waitKey(33) will keep the frame active for 33 ms and then close it automatically.

    destroyWindow() will destroy the current frame if there. destroyAllWindows() will destroy all the frames currently present.

    This will solve.

提交回复
热议问题