pythonopencvcamera

PS Camera taking too much light on OpenCV


I installed a third-party driver and firmware to use my PS 4 Camera on PC and I need it to do a object detection project. Everything works fine on camera on Windows (the screen resolution looks buggy but this is simply how Windows read Sony data format).

Here is how it looks (I have a red light in the room): Image from Windows app

--

When I open the same cam on OpenCV the image was looking very bright, or it looks very low quality.

Here is how the image looks in OpenCV when saved with imwrite():

Here's the actual frame of the low quality image (no screenshot)

In the first image you can clearly read ALIENWARE under the monitor, in the second image is clearly granulated.

I wrote the simplest code just to read and show the cam:

import cv2

#read

webcam = cv2.VideoCapture(0)

#visualize

while True:

    ret, frame = webcam.read()

    cv2.imshow('webcam', frame)

    if cv2.waitKey(40) & 0xFF == ord('q'):
        break

webcam.release()
cv2.destroyAllWindows()

How can I fix this?


Solution

  • I solved the problem! With ffmpeg/ffplay I figured out that this cam can only support certain frame/resolution combinations:

    [dshow @ 000002e52f473900]   pixel_format=yuyv422  min s=3448x808 fps=8 max s=3448x808 fps=60.0002 (tv, bt470bg/bt709/unknown, topleft)
    [dshow @ 000002e52f473900]   pixel_format=yuyv422  min s=1748x408 fps=8 max s=1748x408 fps=120 (tv, bt470bg/bt709/unknown, topleft)
    [dshow @ 000002e52f473900]   pixel_format=yuyv422  min s=898x200 fps=30 max s=898x200 fps=240.004 (tv, bt470bg/bt709/unknown, topleft)
    

    it appears that if you try to lower/increase the fps while keeping the same resolution it adjust the resolution itself to the nearest supported resolution but keeping the said framerate (if between min-max interval). That happens on OpenCV as well.

    Now, with

        width = 3448  
        height = 808 
        cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
        cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
    
        fps = 60
        cap.set(cv2.CAP_PROP_FPS, fps)
    

    it outputs this image:

    much better image

    Thank you all for your help!