Screen Capture with OpenCV and Python-2.7

后端 未结 3 1714
迷失自我
迷失自我 2020-11-30 03:46

I\'m using Python 2.7 and OpenCV 2.4.9.

I need to capture the current frame that is being shown to the user and load it as an cv::Mat

3条回答
  •  感动是毒
    2020-11-30 04:13

    That's a solution code I've written using @Raoul tips.

    I used PIL ImageGrab module to grab the printscreen frames.

    import numpy as np
    from PIL import ImageGrab
    import cv2
    
    while(True):
        printscreen_pil =  ImageGrab.grab()
        printscreen_numpy =   np.array(printscreen_pil.getdata(),dtype='uint8')\
        .reshape((printscreen_pil.size[1],printscreen_pil.size[0],3)) 
        cv2.imshow('window',printscreen_numpy)
        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            break
    

提交回复
热议问题