opencv.imshow will cause jupyter notebook crash

后端 未结 8 1453
借酒劲吻你
借酒劲吻你 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:36

    The API documentation for cv2.waitKey() notes the following:

    This function is the only method in HighGUI that can fetch and handle events, so it needs to be called periodically for normal event processing unless HighGUI is used within an environment that takes care of event processing.

    So perhaps calling the function in an endless loop would make the window responsive? I haven't tested this, but maybe you would like to try the following:

    import cv2
    
    cvim2disp = cv2.imread('data/home.jpg')
    cv2.imshow('img', cvim2disp)
    while(True):
        k = cv2.waitKey(33)
        if k == -1:  # if no key was pressed, -1 is returned
            continue
        else:
            break
    cv2.destroyWindow('img')
    

提交回复
热议问题