BoboTiG / python-mss

An ultra fast cross-platform multiple screenshots module in pure Python using ctypes.
https://pypi.org/project/mss/
MIT License
1.04k stars 94 forks source link

Screenshots have poor color accuracy #221

Closed wkaisertexas closed 1 year ago

wkaisertexas commented 1 year ago

General information:

Description of the warning/error

Colors get washed out when taking monitor captures

Full message

Running the numpy / opencv sample code from the documentation and noticed that the color gets extremely washed out. The macbook I am running this on has a 10-bit panel. Perhaps some of this information could be getting lost, but I am not quite sure.

Screenshot 2022-12-30 at 6 23 17 PM

Code Used

import cv2
import numpy

import mss
import time
with mss.mss() as sct:
    # Part of the screen to capture
    monitor = {"top": 40, "left": 0, "width": 800, "height": 640}

    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.imshow("OpenCV/Numpy normal", img)

        # Display the picture in grayscale
        # cv2.imshow('OpenCV/Numpy grayscale',
        #            cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY))

        print(f"fps: {1 / (time.time() - last_time)}")

        # Press "q" to quit
        if cv2.waitKey(25) & 0xFF == ord("q"):
            cv2.destroyAllWindows()
            break
BoboTiG commented 1 year ago

When you save to a PNG file using sct.shot(), do you see the color issue too?

wkaisertexas commented 1 year ago

Yes, the colors are also faded there. It is just far more noticeable with the hall of mirrors effect created by taking multiple screenshots

BoboTiG commented 1 year ago

I should get a Mac soon, until then I can't do anything.

wkaisertexas commented 1 year ago

Looking back, I think it is an HDR 10 bit versus SDR 8 bit issue. Somehow, the color space is getting converted, so when converting back the colors do not look quite right.

I found something similar with Adobe photoshop and screenshots getting washed out.

https://community.adobe.com/t5/photoshop-ecosystem-discussions/screenshot-has-faded-colors-when-pasted-into-photoshop/td-p/11757932

Might be worth taking a look at.

laerson-hammes commented 1 year ago

This happens because you use OpenCV, you need to convert the image color before showing it on the screen

cv2.cvtColor(np.array(screenshot, cv2.COLOR_RGB2BGR)
wkaisertexas commented 1 year ago
Screenshot 2023-10-26 at 8 00 05 PM

That is definitely not the issue. It is an issue with the P3 Color Space being converted down to Standard Dynamic Range (SDR) which causes colors to become compressed.