Cscore changing camera settings

I’m having trouble changing the exposure setting of my Playstation Eye camera through python-cscore on my raspberry pi 3.


cam = cscore.UsbCamera("usbcam", 0)
cam.setVideoMode(cscore.VideoMode.PixelFormat.kYUYV, 320, 240, 30)
cam.setExposureManual(0)

The code runs and I’m able to see the output from the camera, but the exposure remains unchanged and the terminal outputs this error when the code runs:


CS: ERROR: ioctl VIDIOC_S_EXT_CTRLS failed at UsbCameraProperty.cpp:66: Invalid argument (UsbUtil.cpp:122)

I’m also running an mjpeg server and I’m able to change the exposure through that, so I’m not sure what I’m doing wrong. Thanks for the help in advance.

Sounds like something that cscore doesn’t properly support yet. Recommend filing a bug at https://github.com/wpilibsuite/cscore

Will do, thanks for the reply.

Have you looked at the supported properties either through the enumeratePropertiesAPI or the cscore web server?

Sorry I’m new to all of this, but by the cscore web server, are you referring to the mjpeg server or something else? If you’re talking about the mjpeg server, I am able to change the exposure by setting the exposure to manual using the radio buttons and then changing the exposure slider. As for the enumerate properties, I have added the following line:

print(cam.enumerateProperties())

and I get the following output:

<cscore._cscore.VideoProperty object at 0x769fda28>,
<cscore._cscore.VideoProperty object at 0x769fd4b8>,
<cscore._cscore.VideoProperty object at 0x769fd6c8>, 
<cscore._cscore.VideoProperty object at 0x6eafdaa0>, 
<cscore._cscore.VideoProperty object at 0x6eafda88>, 
<cscore._cscore.VideoProperty object at 0x6eb6b3b0>, 
<cscore._cscore.VideoProperty object at 0x6eb6b1d0>, 
<cscore._cscore.VideoProperty object at 0x6eb6b2f0>, 
<cscore._cscore.VideoProperty object at 0x6eb6b320>, 
<cscore._cscore.VideoProperty object at 0x6eb6b2d8>, 
<cscore._cscore.VideoProperty object at 0x6eb6b908>, 
<cscore._cscore.VideoProperty object at 0x6e921218>, 
<cscore._cscore.VideoProperty object at 0x6e921230>, 
<cscore._cscore.VideoProperty object at 0x6e921248>, 
<cscore._cscore.VideoProperty object at 0x6e921260>, 
<cscore._cscore.VideoProperty object at 0x6e921278>, 
<cscore._cscore.VideoProperty object at 0x6e921290>, 
<cscore._cscore.VideoProperty object at 0x6e9212a8>, 
<cscore._cscore.VideoProperty object at 0x6e9212c0>, 
<cscore._cscore.VideoProperty object at 0x6e9212d8>]

I don’t know what any of this means so if you can help me or point me in the right direction that would be appreciated.

Yes, the mjpeg server page where you change the settings, we need to know the actual settings names.

In code, You need to call getName() on each property, e.g.


for prop in cam.enumerateProperties():
    print(prop.getName())

If you run this script it will enumerate all available properties and their parameters:

After the settings.py, this is the output I get:

CS: usbcam: Connecting to USB camera on /dev/video0
CS: usbcam: set format 1 res 320x240
Properties:
raw_brightness (int): value=0 min=0 max=255 step=1 default=0
brightness (int): value=0 min=0 max=100 step=1 default=0
raw_contrast (int): value=32 min=0 max=255 step=1 default=32
contrast (int): value=12 min=0 max=100 step=1 default=12
raw_saturation (int): value=64 min=0 max=255 step=1 default=64
saturation (int): value=25 min=0 max=100 step=1 default=25
raw_hue (int): value=0 min=-90 max=90 step=1 default=0
hue (int): value=50 min=0 max=100 step=1 default=50
white_balance_automatic (bool) value=1 default=1
exposure (int): value=120 min=0 max=255 step=1 default=120
gain_automatic (bool) value=1 default=1
raw_gain (int): value=20 min=0 max=63 step=1 default=20
gain (int): value=31 min=0 max=100 step=1 default=31
horizontal_flip (bool) value=0 default=0
vertical_flip (bool) value=0 default=0
power_line_frequency (enum): value=0    0: Disabled    1: 50 Hz
raw_sharpness (int): value=0 min=0 max=63 step=1 default=0
sharpness (int): value=0 min=0 max=100 step=1 default=0
auto_exposure (enum): value=0    0: Auto Mode    1: Manual Mode

I was able to change the exposure setting using:

cam.getProperty("auto_exposure").set(1)
cam.getProperty("exposure").set(0)

Is this the correct way to change the settings? If so, thanks for all your guys’ help, I couldn’t have figured it out without you.