Search code examples
wxpython

How to display the image of each video frame in wxpython


I want to display each image from video frame on wxpython, for example, in a panel block. Like when I use imshow in opencv, but now I can control the output in my own window. Is there any ways to do this? Sorry for my bad English


Solution

  • Basically, you need to be able to access every video frame. For example with OpenCV you can loop through the VideoCapture:

    cam = cv2.VideoCapture("filename.mpeg")
    while 1:
        (grabbed, frame) = cam.read()
        if grabbed:
            frame
            # frame is a numpy array containing the image from the video
    

    Now you have got the frame, which you can display for example with cv2.imshow. With wxpython you need to convert this bitmap to something wxpython can display, which is a wx.Bitmap. So you can do:

    bitmap = wx.Bitmap.FromBuffer(width, height, frame)
    

    If you do not know how to display a wx.Bitmap, you better start with a wxPython docs and demos.