Apply image filter to camera on Linux

One interesting part of camera is to apply filter to the output images/videos. Under Linux operating systems, we can use the v4l2-utils to achieve this.

First, we need to check what kinds of filters, or known as control, is supported on the camera,

$ v4l2-ctl — list-ctrls
brightness (int) : min=0 max=255 step=1 default=-8193 value=128
contrast (int) : min=0 max=255 step=1 default=57343 value=128
saturation (int) : min=0 max=255 step=1 default=57343 value=155
white_balance_temperature_auto (bool) : default=1 value=1
gain (int) : min=0 max=255 step=1 default=57343 value=255
power_line_frequency (menu) : min=0 max=2 default=2 value=2
white_balance_temperature (int) : min=2000 max=6500 step=1 default=57343 value=5000 flags=inactive
sharpness (int) : min=0 max=255 step=1 default=57343 value=70
backlight_compensation (int) : min=0 max=1 step=1 default=57343 value=0
exposure_auto (menu) : min=0 max=3 default=0 value=3
exposure_absolute (int) : min=3 max=2047 step=1 default=250 value=416 flags=inactive
exposure_auto_priority (bool) : default=0 value=1
pan_absolute (int) : min=-36000 max=36000 step=3600 default=0 value=0
tilt_absolute (int) : min=-36000 max=36000 step=3600 default=0 value=0
focus_absolute (int) : min=0 max=250 step=5 default=8189 value=0 flags=inactive
focus_auto (bool) : default=1 value=1
zoom_absolute (int) : min=100 max=500 step=1 default=57343 value=100
brightness (int) : min=0 max=255 step=1 default=-8193 value=128
contrast (int) : min=0 max=255 step=1 default=57343 value=128
saturation (int) : min=0 max=255 step=1 default=57343 value=155
white_balance_temperature_auto (bool) : default=1 value=1
gain (int) : min=0 max=255 step=1 default=57343 value=255
power_line_frequency (menu) : min=0 max=2 default=2 value=2
white_balance_temperature (int) : min=2000 max=6500 step=1 default=57343 value=5000 flags=inactive
sharpness (int) : min=0 max=255 step=1 default=57343 value=70
backlight_compensation (int) : min=0 max=1 step=1 default=57343 value=0

Above is the list of controls supported by my camera, Logitech C920 if you are curious.
You can see all things about controls, including name, data type, min/max value, default value, step value…

To see the current value of a control,

$ v4l2-ctl — get-ctrl sharpness
sharpness: 128

or you can use the shorthand parameter -C

$ v4l2-ctl -C sharpness

If you want to change value of a control, do this

$ v4l2-ctl — set-ctrl sharpness=255

or shorthand param with -c

You can also set values to several controls in one command, separated by comma,

$ v4l2-ctl -c sharpness=200,saturation=255,contrast=196

Have fun :)


One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.