I have an application written in C++Builder 11.1.5, where I am trying to capture live video from 2 web cams.
There is an excellent tutorial which describes how to do this with 1 web cam at the following URL, and I have it working perfectly: Video Capturing.
Following that example, I use the following code on the form's OnCreate
event, which stores the information of all the available video capture devices on the computer:
NumbAvailableCameras = 0;
DeviceList = TCaptureDeviceManager::Current->GetDevicesByMediaType(TMediaType::Video);
for (i = 0; i < DeviceList->Count; i++) {
UniqueID = DeviceList->Items[i]->UniqueID;
UniqueDescription = DeviceList->Items[i]->Description;
UniqueName = DeviceList->Items[i]->Name;
ComboBox1->Items->Add(DeviceList->Items[i]->Name);
AvailableCameraIndices[NumbAvailableCameras] = i;
AvailableCameraNames[NumbAvailableCameras] = DeviceList->Items[i]->Name;
AvailableCameraDescriptions[NumbAvailableCameras] = UniqueDescription;
AvailableCameraIdentifiers[NumbAvailableCameras] = UniqueID;
CameraIndex[i] = i;
NumbAvailableCameras++;
}
Then, there is a button and its OnClick
event allows the starting up of the capturing:
CAM1VideoCamera = dynamic_cast<TVideoCaptureDevice*>
(TCaptureDeviceManager::Current->GetDevicesByName(ComboBox1->Selected->Text));
Now, I have 2 webcams whose names are identical, so the GetDevicesByName()
routine doesn't work as it picks off the first camera it finds with the selected name.
As an alternative, I have tried the following code, but it returns NULL
for the capture device:
CAM1VideoCamera = dynamic_cast<TVideoCaptureDevice*>
(TCaptureDeviceManager::Current->Devices[CameraIndex[0]]);
Any ideas as to how to do this properly?