Skip to content

NetGear_Async API Parameters

NetGear_Async provides a special internal wrapper around VideoGear, which itself provides internal access to both CamGear and PiGear APIs and their parameters.

enablePiCamera

This parameter provide access to PiGear or CamGear APIs respectively. This means the if enablePiCamera flag is True, the PiGear API will be accessed, and if False, the CamGear API will be accessed.

Data-Type: Boolean

Default Value: Its default value is False.

Usage:

NetGear_Async(enablePiCamera=True) # enable access to PiGear API

Its complete usage example is given here ➶.

 

address

This parameter sets the valid network address of the Server/Client. Network addresses unique identifiers across the network.

Data-Type: String

Default Value: Its default value is based on selected primary mode, i.e 'localhost' for Send Mode and '*' for Receive Mode.

Usage:

NetGear_Async(address="192.168.0.145")

 

port

This parameter sets the valid Network Port of the Server/Client. A network port is a number that identifies one side of a connection between two devices on the network and is used determine to which process or application a message should be delivered.

Data-Type: String

Default Value: Its default value is '5555'

Usage:

NetGear_Async(port="5575")

 

protocol

This parameter sets the valid messaging protocol between Server/Client. A network protocol is a set of established rules that dictates how to format, transmit and receive data so computer network devices - from servers and routers to endpoints - can communicate regardless of the differences in their underlying infrastructures, designs or standards. Supported protocol are: 'tcp' and 'ipc'.

Data-Type: String

Default Value: Its default value is 'tcp'

Usage:

NetGear_Async(protocol="ipc")

 

pattern

This parameter sets the supported messaging pattern(flow of communication) between Server/Client. Messaging patterns are the network-oriented architectural pattern that describes the flow of communication between interconnecting systems. NetGear provides access to ZeroMQ's pre-optimized sockets which enables you to take advantage of these patterns.

Data-Type: Integer

Default Value: Its default value is 0 (i.e zmq.PAIR).

All supported ZMQ patterns for NetGear_Async are:

  • 0 (.i.e. zmq.PAIR): In this pattern, the communication is bidirectional. There is no specific state stored within the socket. There can only be one connected peer. The server listens on a certain port and a client connects to it.
  • 1 (.i.e. zmq.REQ/zmq.REP): In this pattern, it employs ZMQ REQ sockets that can connect to many servers. The requests will be interleaved or distributed to both the servers. socket zmq.REQ will block send unless it has successfully received a reply back and socket zmq.REP will block on recv() unless it has received a request.
  • 2 (.i.e. zmq.PUB/zmq.SUB): It is an another classic pattern where senders of messages, called publishers, do not program the messages to be sent directly to specific receivers, called subscribers. Messages are published without the knowledge of what or if any subscriber of that knowledge exists. A ZMQ.SUB can connect to multiple ZMQ.PUB (publishers). No single publisher overwhelms the subscriber. The messages from both publishers are interleaved.
  • 3 (.i.e. zmq.PUSH/zmq.PULL): Its sockets let you distribute messages to multiple workers, arranged in a pipeline. A Push socket will distribute sent messages to its Pull clients evenly. This is equivalent to the producer/consumer model but the results computed by the consumer are not sent upstream but downstream to another pull/consumer socket.

Usage:

NetGear_Async(pattern=1) # sets zmq.REQ/zmq.REP pattern

 

receive_mode

This parameter select the Netgear's Mode of operation. It basically activates Receive Mode(if True) and Send Mode(if False). Furthermore, recv() method will only work when this flag is enabled(i.e. Receive Mode), whereas send() method will only work when this flag is disabled(i.e.Send Mode).

Data-Type: Boolean

Default Value: Its default value is False(i.e. Send Mode is activated by default).

Usage:

NetGear_Async(receive_mode=True) # activates Recieve Mode

 

timeout

In NetGear_Async, the Receiver-end keeps tracks if frames are received from Server-end within this specified timeout value (in seconds), Otherwise TimeoutError will be raised, which helps to close the Receiver-end safely if the Server has lost connection prematurely. This parameter controls that timeout value (i.e. the maximum waiting time (in seconds)) after which Client exit itself with a TimeoutError to save resources. Its minimum value is 0.0 but no max limit.

Data-Type: Float/Integer

Default Value: Its default value is 10.0.

Usage:

NetGear_Async(timeout=5.0) # sets 5secs timeout

options

This parameter provides the flexibility to alter various NetGear_Async API's internal properties and modes.

Data-Type: Dictionary

Default Value: Its default value is {}

Usage:

Supported dictionary attributes for NetGear_Async API

  • bidirectional_mode (boolean) : This internal attribute activates the exclusive Bidirectional Mode, if enabled(True).

    The desired attributes can be passed to NetGear_Async API as follows:

    # formatting parameters as dictionary attributes
    options = {
        "bidirectional_mode": True,
    }
    # assigning it
    NetGear_Async(logging=True, **options)
    

 

 

Parameters for Stabilizer Backend

Enable this backend with stabilize=True in NetGear_Async.

stabilize

This parameter enable access to Stabilizer Class for stabilizing frames, i.e. can be set to True(to enable) or unset to False(to disable).

Data-Type: Boolean

Default Value: Its default value is False.

Usage:

NetGear_Async(stabilize=True) # enable stablization

Its complete usage example is given here ➶.

 

options

This parameter can be used in addition, to pass user-defined parameters supported by Stabilizer Class. These parameters can be formatted as this parameter's attribute.

Supported dictionary attributes for Stabilizer Class are:

  • SMOOTHING_RADIUS (integer) : This attribute can be used to alter averaging window size. It basically handles the quality of stabilization at the expense of latency and sudden panning. Larger its value, less will be panning, more will be latency and vice-versa. Its default value is 25. You can easily pass this attribute as follows:

    options = {'SMOOTHING_RADIUS': 30}
    
  • BORDER_SIZE (integer) : This attribute enables the feature to extend border size that compensates for stabilized output video frames motions. Its default value is 0(no borders). You can easily pass this attribute as follows:

    options = {'BORDER_SIZE': 10}
    
  • CROP_N_ZOOM(boolean): This attribute enables the feature where it crops and zooms frames(to original size) to reduce the black borders from stabilization being too noticeable (similar to the Stabilized, cropped and Auto-Scaled feature available in Adobe AfterEffects). It simply works in conjunction with the BORDER_SIZE attribute, i.e. when this attribute is enabled, BORDER_SIZE will be used for cropping border instead of extending them. Its default value is False. You can easily pass this attribute as follows:

    options = {'BORDER_SIZE': 10, 'CROP_N_ZOOM' : True}
    
  • BORDER_TYPE (string) : This attribute can be used to change the extended border style. Valid border types are 'black', 'reflect', 'reflect_101', 'replicate' and 'wrap', learn more about it here. Its default value is 'black'. You can easily pass this attribute as follows:

    Altering BORDER_TYPE attribute is Disabled while CROP_N_ZOOM is enabled.

    options = {'BORDER_TYPE': 'black'}
    

 

 

Parameters for CamGear backend

Enable this backend with enablePiCamera=False in NetGear_Async. Default is also False.

source

NetGear_Async API will throw RuntimeError if source provided is invalid.

This parameter defines the source for the input stream.

Data-Type: Based on input.

Default Value: Its default value is 0.

Its valid input can be one of the following:

  • Index (integer): Valid index of the connected video device, for e.g 0, or 1, or 2 etc. as follows:

    NetGear_Async(source=0)
    
  • Filepath (string): Valid path of the video file, for e.g "/home/foo.mp4" as follows:

    NetGear_Async(source='/home/foo.mp4')
    
  • Streaming Services URL Address (string): Valid Video URL as input when Stream Mode is enabled(i.e. stream_mode=True)

    CamGear internally implements yt_dlp backend class for pipelining live video-frames and metadata from various streaming services. For example Twitch URL can be used as follows:

    Supported Streaming Websites

    The complete list of all supported Streaming Websites URLs can be found here ➶

    CamGear(source='https://www.twitch.tv/shroud', stream_mode=True)
    
  • Network Address (string): Valid (http(s), rtp, rtsp, rtmp, mms, etc.) incoming network stream address such as 'rtsp://192.168.31.163:554/' as input:

    NetGear_Async(source='rtsp://192.168.31.163:554/')
    
  • GStreamer Pipeline:

    CamGear API also supports GStreamer Pipeline.

    Requirements for GStreamer Pipelining

    Successful GStreamer Pipelining needs your OpenCV to be built with GStreamer support. Checkout this FAQ for compiling OpenCV with GStreamer support.

    Thereby, You can easily check GStreamer support by running print(cv2.getBuildInformation()) python command and see if output contains something similar as follows:

    Video I/O:
    ...
         GStreamer:                   YES (ver 1.8.3)
    ...
    

    Be sure convert video output into BGR colorspace before pipelining as follows:

    NetGear_Async(source='udpsrc port=5000 ! application/x-rtp,media=video,payload=96,clock-rate=90000,encoding-name=H264, ! rtph264depay ! decodebin ! videoconvert ! video/x-raw, format=BGR ! appsink')
    

 

stream_mode

This parameter controls the Stream Mode, .i.e if enabled(stream_mode=True), the CamGear API will interpret the given source input as YouTube URL address.

Due to a FFmpeg bug that causes video to freeze frequently in OpenCV, It is advised to always use GStreamer backend for any livestream videos. Checkout this FAQ for compiling OpenCV with GStreamer support.

Data-Type: Boolean

Default Value: Its default value is False.

Usage:

Supported Streaming Websites

The complete list of all supported Streaming Websites URLs can be found here ➶

NetGear_Async(source='https://youtu.be/bvetuLwJIkA', stream_mode=True)

Its complete usage example is given here ➶.

 

backend

This parameter manually selects the backend for OpenCV's VideoCapture class (only if specified).

Data-Type: Integer

Default Value: Its default value is 0

Usage:

All supported backends are listed here ➶

Its value can be for e.g. backend = cv2.CAP_DSHOW for selecting Direct Show as backend:

NetGear_Async(source=0, backend = cv2.CAP_DSHOW)

 

options

This parameter provides the ability to alter various Source Tweak Parameters available within OpenCV's VideoCapture API properties.

Data-Type: Dictionary

Default Value: Its default value is {}

Usage:

All supported parameters are listed here ➶

The desired parameters can be passed to NetGear_Async API by formatting them as this parameter's attributes, as follows:

# formatting parameters as dictionary attributes
options = {"CAP_PROP_FRAME_WIDTH":320, "CAP_PROP_FRAME_HEIGHT":240, "CAP_PROP_FPS":60}
# assigning it
NetGear_Async(source=0, **options)

 

 

Parameters for PiGear backend

Enable this backend with enablePiCamera=True in NetGear_Async.

camera_num

This parameter selects the camera index to be used as the source, allowing you to drive these multiple cameras simultaneously from within a single Python session. Its value can only be zero or greater, otherwise, NetGear_Async API will throw ValueError for any negative value.

Data-Type: Integer

Default Value: Its default value is 0.

Usage:

# select Camera Module at index `1`
NetGear_Async(enablePiCamera=True, camera_num=1)

The complete usage example demonstrating the usage of the camera_num parameter is available here ➶.

 

resolution

This parameter controls the resolution - a tuple (i.e. (width,height)) of two values giving the width and height of the output frames.

Make sure both width and height values should be at least 64.

When using the Picamera2 backend, the resolution parameter will be OVERRIDDEN, if the user explicitly defines the output_size property of the sensor configurational parameter.

Data-Type: Tuple

Default Value: Its default value is (640,480).

Usage:

NetGear_Async(enablePiCamera=True, resolution=(1280,720)) # sets 1280x720 resolution

 

framerate

This parameter controls the framerate of the source.

Data-Type: integer/float

Default Value: Its default value is 30.

Usage:

NetGear_Async(enablePiCamera=True, framerate=60) # sets 60fps framerate

 

options

This dictionary parameter in the internal PiGear API backend allows you to control various camera settings for both the picamera2 and legacy picamera backends and some internal API tasks. These settings include:

A. Configurational Camera Parameters

  • These parameters are provided by the underlying backend library (depending upon backend in use), and must be applied to the camera system before the camera can be started.
  • These parameter include: Brightness, Contrast, Saturation, Exposure, Colour Temperature, Colour Gains, etc.
  • All supported parameters are listed in this Usage example ➶

B. User-defined Parameters

  • These user-defined parameters control specific internal behaviors of the API and perform certain tasks on the camera objects.
  • All supported User-defined Parameters are listed here ➶

 

 

Common Parameters

These are common parameters that works with every backend in NetGear_Async.

colorspace

This parameter selects the colorspace of the source stream.

Data-Type: String

Default Value: Its default value is None.

Usage:

All supported colorspace values are given here ➶

NetGear_Async(colorspace="COLOR_BGR2HSV")

Its complete usage example is given here ➶

 

logging

This parameter enables logging (if True), essential for debugging.

Data-Type: Boolean

Default Value: Its default value is False.

Usage:

NetGear_Async(logging=True)

 

time_delay

This parameter set the time delay (in seconds) before the NetGear_Async API start reading the frames. This delay is only required if the source required some warm-up delay before starting up.

Data-Type: Integer

Default Value: Its default value is 0.

Usage:

NetGear_Async(time_delay=1)  # set 1 seconds time delay