How to control pan/tilt/zoom on Logitech cameras
Purpose
The Logitech QuickCam Orbit/Sphere camera series contain motors to mechanically control the pan and tilt angles of the camera lens. At the same time, most Logitech cameras support digital pan/tilt/zoom (PTZ) in addition to or instead of mechanical pan/tilt. This document explains how to control these features in your own applications using the standard DirectShow properties built into Windows.
Prerequisities
Hardware
You need a Logitech UVC camera connected to a Windows system to follow this how-to. Windows XP or Vista are recommended.
Any Logitech UVC camera will do for the digital pan/tilt/zoom functionality but in order to take full advantage of the mechanical pan/tilt feature you need a Logitech QuickCam Orbit/Sphere camera (all MP or AF models are fine).
Driver
Your camera needs to be running with the Logitech UVC driver version 11.1 or higher to follow this how-to. (Some versions of lvuvc.sys prior to 11.1 had a bug where negative pan/tilt angles were handled incorrectly.)
Please note that the Microsoft UVC driver will not work for the purpose of this how-to because it does not implement any of the digital or mechanical pan/tilt/zoom features.
Software
In order to compile the sample code you will need Visual Studio 2005 and a recent version of the Windows SDK (tested with 6.0 and 6.1).
There is nothing that intrinsically prevents you from following this how-to on older versions of these developer tools but you may have to change a few lines of (non webcam-specific) code, in particular because the sample uses some functions of the Visual Studio 2005 Safe C/C++ Libraries.
Description
Most of this how-to refers to the sample code for which you can find a link at the end of the article. The code archive also includes a pre-compiled binary in case you want to try the sample but you don't have the development tools at hand.
The sample uses the standard DirectShow API to enumerate all video input devices in the system and to access the corresponding camera control properties.
To see the sample in action, either run the provided PTZ.exe in the Release directory or compile the sample code and run the resulting PTZ.exe from a command line to see the output. In order to be able to see the effects of digital pan/tilt/zoom it is recommended to start a video stream in a video application like AMCap before running the tool. The mechanical pan/tilt obviously works whether the camera is streaming video or not.
We use the following DirectShow properties in the IAMCameraControl interface's PROPSETID_VIDCAP_CAMERACONTROL property set.
- KSPROPERTY_CAMERACONTROL_PAN
- KSPROPERTY_CAMERACONTROL_TILT
- KSPROPERTY_CAMERACONTROL_ZOOM
These properties are generic properties defined by Microsoft. The following behavior, however, is specific to the Logitech UVC driver:
- Specifying the KSPROPERTY_CAMERACONTROL_FLAGS_ABSOLUTE flag for the pan and tilt properties instructs the driver to use digital instead of mechanical pan/tilt.
Using these three controls you can control the following features:
- Mechanical pan
- Mechanical tilt
- Digital pan
- Digital tilt
- Digital zoom
With this information and the documentation provided in the Further information section below you are able to control these features from your own application. Don't forget to look at the inline code comments and links.
Further information
For further information on the DirectShow controls mentioned in this article, please refer to the MSDN documentation on DirectShow:
- DirectShow
- Using the System Device Enumerator
- IAMCameraControl Interface
- PROPSETID_VIDCAP_CAMERACONTROL Property Set
If you have questions or problems with this sample, you can post them in the Windows Webcam Development forum. We do not guarantee support for this sample but we will try to respond to your questions.