Skip to main content

Camera control and PTZ

Products: Video Capture SDK .Net

Using Camera Control API, you can set the following camera parameters (the camera can support only some of them): Pan, Tilt, Roll, Zoom, Exposure, Iris, and Focus.

The Camera Control API should be used with started camera preview or capture.

Sample code

On the form, we are using several checkboxes, labels, and slider control. You can check the Main Demo source code.

1. Read default values and command ranges

int max;
int defaultValue;
int min;
int step;
CameraControlFlags flags;

if (await VideoCapture1.Video_CaptureDevice_CameraControl_GetRangeAsync(
CameraControlProperty.Zoom, out min, out max, out step, out defaultValue, out flags))
{
// set slider range
tbCCZoom.Minimum = min;
tbCCZoom.Maximum = max;
tbCCZoom.SmallChange = step;
tbCCZoom.Value = defaultValue;

// set min, max and current values on labels
lbCCZoomMin.Text = "Min: " + Convert.ToString(min);
lbCCZoomMax.Text = "Max: " + Convert.ToString(max);
lbCCZoomCurrent.Text = "Current: " + Convert.ToString(defaultValue);

// set command checkboxes
cbCCZoomManual.Checked = (flags & CameraControlFlags.Manual) == CameraControlFlags.Manual;
cbCCZoomAuto.Checked = (flags & CameraControlFlags.Auto) == CameraControlFlags.Auto;
cbCCZoomRelative.Checked = (flags & CameraControlFlags.Relative) == CameraControlFlags.Relative;
}

If the Auto flag is set, all other flags and values will be ignored.

2. Apply value set on slider (Auto checkbox should be disabled to set manual value or enabled to set camera default value)

CameraControlFlags flags = CameraControlFlags.None;

if (cbCCZoomManual.Checked)
{
flags = flags | CameraControlFlags.Manual;
}

if (cbCCZoomAuto.Checked)
{
flags = flags | CameraControlFlags.Auto;
}

if (cbCCZoomRelative.Checked)
{
flags = flags | CameraControlFlags.Relative;
}

await VideoCapture1.Video_CaptureDevice_CameraControl_SetAsync(CameraControlProperty.Zoom, tbCCZoom.Value, flags);

Required redists

How can the required redists be installed or deployed to the user's PC?


Visit our GitHub page to get more code samples.