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?
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:
img = sct.grab(mon)
AttributeError: 'MSS' object has no attribute 'grab'