Python Forum
Screen capture opencv - grab error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Screen capture opencv - grab error
#1
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'
buran write Jan-27-2022, 12:19 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
Please, post the full traceback you get, verbatim.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [PyMuPDF] Grab all strings of a given size? Winfried 3 667 Dec-26-2023, 07:39 AM
Last Post: Pedroski55
  Can't stop keyboard listener to grab chars typed inside CTk window Valjean 9 1,305 Sep-25-2023, 08:07 PM
Last Post: deanhystad
  [SOLVED] [ElementTree] Grab text in attributes? Winfried 3 1,620 May-27-2022, 04:59 PM
Last Post: Winfried
  libhdf5 library error (opencv-contrib) 1979gian 0 1,929 May-11-2020, 06:10 PM
Last Post: 1979gian
  Error Installing PySceneDetect and OpenCV jpnoli 1 1,899 Mar-26-2020, 12:19 PM
Last Post: buran
  How to capture an error message TheHacker707 4 3,577 Feb-15-2020, 03:03 PM
Last Post: snippsat
  capture next block of text after finding error in file kdefilip2 6 3,409 Nov-27-2019, 07:36 PM
Last Post: buran
  Grab and Parse a chunkc of text sumncguy 4 2,379 Oct-07-2019, 05:17 PM
Last Post: Gribouillis
  python opencv grayscale conversion error Spandora 1 9,561 May-26-2019, 10:43 AM
Last Post: heiner55
  wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' Shadower 1 6,171 Feb-06-2019, 01:25 AM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020