tshino / softcam

A library to make a virtual webcam on Windows
MIT License
110 stars 30 forks source link

Image colors are not correct #23

Closed risingblock closed 1 year ago

risingblock commented 1 year ago

Hi, I tried loading an image in Python and sending it.

It works, but the image appears very blue.

Here is my code:

from PIL import Image
from x64.Release import softcam

def main():
    dt = 1/60
    cam = softcam.camera(1920, 1280, 60)
    image = Image.open('./test.jpg')
    image = image.convert('RGB')

    # Here, you can wait for an application to connect to this camera.
    while not cam.wait_for_connection(timeout=1):
        pass

    while True:
        # send the image
        cam.send_frame(image)

if __name__ == '__main__':
    main()

Original image: https://images.unsplash.com/photo-1542500186-6edb30855637?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1740&q=80

What shows up in Zoom (virtual camera): https://i.imgur.com/3ljVlsU.jpg

Any idea why? Is it related to the color table of the image? I tried converting to RGB, not sure what else I should do.

Thanks

risingblock commented 1 year ago

Got this to work by converting the image to BGR format.

bgr_image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
tshino commented 1 year ago

Yes, the API is expecting that the color component order is BGR! This is due to following the DirectShow convention and maximizing camera application compatibility.

I didn't notice such incompatibility between OpenCV and Pillow. I will add a note on it to the README!

Thank you for your information!