pip install opencv-python
pip install mss
import time, cv2, mss, numpy

with mss.mss() as sct:
    monitor = {'top': 40, 'left': 0, 'width': 800, 'height': 640} # Part of the screen to capture
    while True:
        last_time = time.time()
        img = numpy.array(sct.grab(monitor)) # Get raw pixels from the screen, save it to a Numpy array
        cv2.imshow('OpenCV/Numpy normal', img) # Display the picture
        print('fps: {0}'.format(1 / (time.time()-last_time)))
        # Press "q" to quit
        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            break

 

#References
OpenCV https://docs.opencv.org/master/

mss https://pypi.org/project/mss/1.0.2/

https://stackoverflow.com/questions/35097837/capture-video-data-from-screen-in-python

+ Recent posts