Skip to content

Source Tweak Parameters for CamGear API

Source Tweak Parameters

Overview

With CamGear's options dictionary parameter, the user has the ability to alter various tweak parameters available within OpenCV's VideoCapture Class by formatting them as its attributes.

These tweak parameters can be used to transform input Camera-Source properties (such as its brightness, saturation, resolution, iso, gain etc.) seamlessly. All parameters supported by CamGear API are disscussed in this document.

Exclusive CamGear Attributes

CamGear's Exclusive Attributes

In addition to Source Tweak Parameters, CamGear also provides some exclusive attributes for its options dictionary parameters.

These attributes are as follows:

  • STREAM_RESOLUTION (string): This attribute can be used in CamGear's Stream Mode (stream_mode=True) for specifying supported stream resolution. Its possible values can be: 144p, 240p, 360p, 480p, 720p, 1080p, 1440p, 2160p, 4320p, worst, best, and its default value is best. Its usage is as follows:

    In case specificed STREAM_RESOLUTION value is unavailable within Source Stream, it defaults to best!

    options = {"STREAM_RESOLUTION": "720p"} # 720p stream will be used. 
    

    Its complete usage example is given here ➶

  • STREAM_PARAMS (dict): This dictionary attribute can be used in CamGear's Stream Mode (stream_mode=True) for specifying parameters for its internal yt_dlp backend class. Its usage is as follows:

    All STREAM_PARAMS Supported Parameters

    options = {"STREAM_PARAMS": {"nocheckcertificate": True}} # disables verifying SSL certificates in yt_dlp
    
  • THREADED_QUEUE_MODE (boolean): This attribute can be used to override Threaded-Queue-Mode mode to manually disable it:

    Disabling Threaded-Queue-Mode can be dangerous! Read more here ➶

    options = {"THREADED_QUEUE_MODE": False} # disable Threaded Queue Mode. 
    
  • THREAD_TIMEOUT (int/float): This attribute can be used to override the timeout value(positive number), that blocks the video-thread for at most timeout seconds if no video-frame was available within that time, and otherwise raises the Empty exception to prevent any never-ending deadlocks. Its default value is None, meaning no timeout at all. Its usage is as follows:

    New in v0.2.1

    THREAD_TIMEOUT attribute added in v0.2.1.

    options = {"THREAD_TIMEOUT": 300} # set Video-Thread Timeout for 5mins. 
    

 

Supported Source Tweak Parameters

All Source Tweak Parameters supported by CamGear API are as follows:

Remember, Not all parameters are supported by all cameras devices, which is one of the most troublesome thing with OpenCV library. Each camera type, from android cameras, to USB cameras , to professional ones, offers a different interface to modify its parameters. Therefore, there are many branches in OpenCV code to support as many of them, but of course, not all possible devices are covered, and thereby works. Furthermore, OpenCV does not return any helpful error messages regarding this problem, so it’s pretty much based on trial and error.

You can easily check parameter values supported by your webcam, by hooking it to a Linux machine, and using the command v4l2-ctl -d 0 --list-formats-ext (where 0 is an index of the given camera) to list the supported video parameters and their values. If that doesn't works, refer to its datasheet (if available).

These parameters can be passed to CamGear's options dictionary parameter by formatting them as its string attributes. Its complete usage example is here ➶

Values Description
CAP_PROP_POS_MSEC Current position of the video file in milliseconds.
CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.
CAP_PROP_POS_AVI_RATIO Relative position of the video file: 0=start of the film, 1=end of the film.
CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
CAP_PROP_FPS Frame rate.
CAP_PROP_FOURCC 4-character code of codec. see VideoWriter::fourcc.
CAP_PROP_FRAME_COUNT Number of frames in the video file.
CAP_PROP_FORMAT Format of the Mat objects returned by VideoCapture::retrieve().
CAP_PROP_MODE Backend-specific value indicating the current capture mode.
CAP_PROP_BRIGHTNESS Brightness of the image (only for those cameras that support).
CAP_PROP_CONTRAST Contrast of the image (only for cameras).
CAP_PROP_SATURATION Saturation of the image (only for cameras).
CAP_PROP_HUE Hue of the image (only for cameras).
CAP_PROP_GAIN Gain of the image (only for those cameras that support).
CAP_PROP_EXPOSURE Exposure (only for those cameras that support).
CAP_PROP_CONVERT_RGB Boolean flags indicating whether images should be converted to RGB.
CAP_PROP_WHITE_BALANCE_BLUE_U Currently unsupported.
CAP_PROP_RECTIFICATION Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently).
CAP_PROP_MONOCHROME
CAP_PROP_SHARPNESS
CAP_PROP_AUTO_EXPOSURE DC1394: exposure control done by camera, user can adjust reference level using this feature.
CAP_PROP_GAMMA
CAP_PROP_TEMPERATURE
CAP_PROP_TRIGGER
CAP_PROP_TRIGGER_DELAY
CAP_PROP_WHITE_BALANCE_RED_V
CAP_PROP_ZOOM
CAP_PROP_FOCUS
CAP_PROP_GUID
CAP_PROP_ISO_SPEED
CAP_PROP_BACKLIGHT
CAP_PROP_PAN
CAP_PROP_TILT
CAP_PROP_ROLL
CAP_PROP_IRIS
CAP_PROP_SETTINGS Pop up video/camera filter dialog (note: only supported by DSHOW backend currently. The property value is ignored)
CAP_PROP_BUFFERSIZE
CAP_PROP_AUTOFOCUS
CAP_PROP_SAR_NUM Sample aspect ratio: num/den (num)
CAP_PROP_SAR_DEN Sample aspect ratio: num/den (den)
CAP_PROP_BACKEND Current backend (enum VideoCapture APIs). Read-only property.
CAP_PROP_CHANNEL Video input or Channel Number (only for those cameras that support)
CAP_PROP_AUTO_WB enable/ disable auto white-balance
CAP_PROP_WB_TEMPERATURE white-balance color temperature