cv2.imshow command doesn't work properly in opencv-python

前端 未结 16 1555
轻奢々
轻奢々 2020-12-04 17:31

I\'m using opencv 2.4.2, python 2.7 The following simple code created a window of the correct name, but its content is just blank and doesn\'t show the image:



        
相关标签:
16条回答
  • 2020-12-04 17:53

    I faced the same issue. I tried to read an image from IDLE and tried to display it using cv2.imshow(), but the display window freezes and shows pythonw.exe is not responding when trying to close the window.

    The post below gives a possible explanation for why this is happening

    pythonw.exe is not responding

    "Basically, don't do this from IDLE. Write a script and run it from the shell or the script directly if in windows, by naming it with a .pyw extension and double clicking it. There is apparently a conflict between IDLE's own event loop and the ones from GUI toolkits."

    When I used imshow() in a script and execute it rather than running it directly over IDLE, it worked.

    0 讨论(0)
  • 2020-12-04 17:54

    If you have not made this working, you better put

    import cv2
    img=cv2.imread('C:/Python27/03323_HD.jpg')
    cv2.imshow('Window',img)
    cv2.waitKey(0)
    

    into one file and run it.

    0 讨论(0)
  • 2020-12-04 17:59

    Doesn't need any additional methods after waitKey(0) (reply for above code)

    import cv2
    img=cv2.imread('C:/Python27/03323_HD.jpg')
    cv2.imshow('ImageWindow',img)
    cv2.waitKey(0)
    

    Window appears -> Click on the Window & Click on Enter. Window will close.

    0 讨论(0)
  • 2020-12-04 18:03

    imshow() only works with waitKey():

    import cv2
    img = cv2.imread('C:/Python27/03323_HD.jpg')
    cv2.imshow('ImageWindow', img)
    cv2.waitKey()
    

    (The whole message-loop necessary for updating the window is hidden in there.)

    0 讨论(0)
提交回复
热议问题