Python Forum

Full Version: Screen capture opencv - grab error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I’m trying to capture frames of all or portion of the screen with Python. I reviewed the previous questions asked in the stackoverflow. When I run the code below on my computer, I get this error. How can I solve this?
Python version 3.8.0
mss version : 2.0.22
import time
import cv2
import numpy as np
from mss import mss
mon = {'top': 160, 'left': 160, 'width': 200, 'height': 200}
with mss() as sct:
    # mon = sct.monitors[0]
    while True:
        last_time = time.time()
        img = sct.grab(mon)
        print('fps: {0}'.format(1 / (time.time()-last_time)))
        cv2.imw('test', np.array(img))
        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            break
ERROR:

Error:
img = sct.grab(mon) AttributeError: 'MSS' object has no attribute 'grab'
Please, post the full traceback you get, verbatim.