Screen not being captured correctly
See original GitHub issueHi I’ve been trying to find a way to capture my Mac’s screen to use to train a neural network, but I couldn’t find a way to capture the screen with decent FPS until I found your library. The FPS using this library are very good, however the screen is not being captured correctly.
General informations:
- OS name: macOS
- OS version: 10.12.5
- OS architecture: 64 bits
- Result of the command
python --version
: Python 3.6.0 :: Anaconda custom (x86_64)
For GNU/Linux users:
- Desktop Environment: Quartz
Description of the warning/error
Using grab()
to capture either the whole screen or a section of the screen, the display is not captured properly, looking like every other row of pixels has been shifted to the side. This happens when using OpenCV to show the image and when saving the image to a file.
Code (OpenCV/Numpy Example Code):
import time
import cv2
import mss
import numpy
with mss.mss() as sct:
# Part of the screen to capture
monitor = {'top': 50, 'left': 0, 'width': 840, 'height': 940}
while 'Screen capturing':
last_time = time.time()
# Get raw pixels from the screen, save it to a Numpy array
img = numpy.array(sct.grab(monitor))
# Display the picture
# cv2.resize(img, (40, 40))
cv2.imshow('OpenCV/Numpy normal', img)
# Display the picture in grayscale
# cv2.imshow('OpenCV/Numpy grayscale',
# cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY))
print('fps: {0}'.format(1 / (time.time()-last_time)))
# Press "q" to quit
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
I am using the dev branch as the master branch does not work on Macs.
Full message
N/A
Other details
This happens when capturing the whole screen and a section of the screen.
Thank You.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to fix Display Capture not Working in OBS Studio [Black ...
Step 3) In OBS click Display Capture > Properties > Capture Method > Windows 10 (1903 and up). Click on Tools > Check...
Read more >Fixed: Print Screen Not Working on Windows 10 | SoftwareKeep
Here are 6 solutions on how to fix print screen not working in Windows 10. Click here to get started.
Read more >How to fix Display Capture not Working in OBS ... - YouTube
Here's a quick fix when display capture doesn't work but window capture does work. This issue mostly affects laptops.
Read more >When trying to capture a screenshot my screen shifts or resizes
This article describes how to fix issues you may encounter while trying to use screen capture on Windows 10 and a version of...
Read more >a window do not captured in any windows screen recorder
Yes I know by pressing Windows key + Shift + S I can take screenshot (I'm not a basic user). My problem with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi there,
I’m experiencing this same issue. It’s exclusive to the retina display on the MBP, as neither of the external monitors plugged in (not HiDPI) have any issue. Since retina displays are usually scaled down to a lower “apparent” resolution, it seems the detected width and height of the screenshot are the scaled down resolution, but the actual raw pixels are still the entire size of the display.
The content of
sct.monitors
is[{'width': 4640, 'top': -160, 'height': 1184, 'left': 0}, {'width': 1440, 'top': 0, 'height': 900, 'left': 0}, {'width': 1280, 'top': 224, 'height': 800, 'left': 1440}, {'width': 1920, 'top': -160, 'height': 1080, 'left': 2720}]
The monitor in question with issues is monitor 2, but the problem persists even if there are no external monitors plugged in. I’m using Python 2.7.14 and the current dev branch as of commit 96b18f698d33afeab9a73d62e91ffecb8663bdd9.
I’ve tried all of the examples, and as far as I’m aware, the problem continues throughout them for both grabbing a specific portion of the screen, and grabbing the full screen.
Something similar to the error message in #23 appears when using
sct.shot
:ValueError: attempt to assign bytes of size 4096000 to extended slice of size 1024000
. 4096000 here is the “true” amount of pixels (2560 x 1600), while 1024000 is the scaled down “apparent” resolution (1280 x 800).I was able to get the screenshot to display properly by hardcoding the dimensions of 2560 and 1600 in a couple places in screenshot.py, but of course the resulting image was not the desired size of 1280 x 800.
Any ideas what I can do to fix it so that it scales properly in the first place? Thanks for your time.
I have the same problem as both guys above. mss 3.1.0 MacBook Pro (Retina, Mid 2012). High Sierra 10.13.1 Quarz Python 3.6.x Anaconda