PDA

View Full Version : Multiple cameras & 'setupDevice.cpp'



bstichbury
February 25, 2003, 00:55:36
Hi
I'm wondering if the multiple camera code on your website has been done for VC++ as well as for VB. Otherwise I'll just have to do it myself...
My copy of 'setupDevice.cpp' in the IC14\Samples\Common directory is empty, could you check to see the problem isn't with the file archive?
Thanks
Brendon

Stefan Geissler
February 25, 2003, 07:27:21
Brendon,


If the file 'setupDevice.cpp' is empty, something has been gone wrong with IC Imaging Control setup on your machine. You can try to repair or reinstall IC Imaging Control by starting the setup.exe of it again.

There is no multi camera example in C++ available. But i think, this should be easy to create in a MDI application using the existing dialogs, that are implemented the 'vc6\demoapp' example.

bstichbury
February 26, 2003, 02:03:46
Thanks for the information - re-running setup.exe fixed up 'setupDevice.cpp'

I still have a further problem you might be able to help with (re the multiple camera code question)
I want to open two windows with the same camera, one to zoom and scroll about, the other just to show the entire field of view. I haven't been able to do this yet. Any suggestions would be great.

Thanks
Brendon

Stefan Geissler
February 26, 2003, 07:03:08
Brendon,

At first, you can not access one camera with two IC Imaging Controls at the same time.
But you can start in one window the live video as usuable. With the GrabberListerener::frameReady event you can also snap every frame into a memory buffer, that can be displayed separately. To display the memory buffer, refer to the OnPaint method of the demoapp\childview.cpp.

bstichbury
February 27, 2003, 01:30:58
Thanks once again Stefan
So is there a test whether a device is already attached to one control?
It isn't until I use 'startLive()' that I know it is already used, and it tells me by an exception in DShowLib.

Brendon

Stefan Geissler
February 27, 2003, 08:12:37
Brendon,

With the method Grabber::isDevValid() you can check, whether a valid device has been opened with an instance of a Grabber object.

bstichbury
February 28, 2003, 04:09:00
Hi Stefan
I don't think I am using the method Grabber::isDevValid() correctly.
I start with a device already open and running (called by startLive()), then go through the VidCapDevList and open each one with openDev() with a temporary Grabber object. Each time I open one I test it with the isDevValid() method and then close it. I find none of the devices return false on the isDevValid() method.
What am I doing wrong?

Brendon

Stefan Geissler
February 28, 2003, 07:47:32
Brendon,

You are right,. It is possible to open one device with different Grabber instances and the methods Grabber::isDevValid() and Grabber::isDevOpen() will return true. This is, because the devices are really open. But only one of the Grabber instances can play a live video stream.

If i understand you correctly, you want to open a various number of video capture devices. You need to check, whether one of your Grabber instances already uses a found video capture device. In general, there are two ways, to perform this.
1: Create a permanent list, that contains the names of the available video capture devices and for each device a flag, that is used to indicate, if the device is in use or not. The device names are unique. If a new device is connected to your PC, you need to update this list. To be notified, when a new device is connected to your PC, use the WM_DEVICECHANGE message (CWnd::OnDeviceChange).

2: Get all available devices in the know manner. Compare each device name in the list with the device names returned by your running Grabber instances (Grabber::getDev().c_str() returns the name of the current used video capture device). If a name in the video capture device list is not found in any Grabber instance, you have found an unused video capture device.

bstichbury
March 3, 2003, 23:33:04
Thanks for your help
I'll create the list with the flags as per your suggestion

Brendon

Stefan Geissler
March 7, 2003, 10:05:04
Brendon,

If you want to open every video capture device, that is connected to
your computer automatically at application start, you can this implement
as follows.
In the Application (*app.cpp) add at the end of the InitInstance() method:



DShowLib::Grabber grabber;
DShowLib::Grabber::tVidCapDevListPtr pVidCapDevList =
grabber.getAvailableVideoCaptureDevices();

for (int i=0; i < pVidCapDevList->size(); ++i)
{
AfxGetApp()->OpenDocumentFile( (*pVidCapDevList )[i].c_str());
}

This creates a new Document for all connected video capture devices.

Now, overwrite the method OnOpenDocument() of your document:



BOOL CMultipleCamerasDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
// The Documentmanager adds the complete application path the file name.
// This is nonsense for our application, so we strip it againg.
// m_CurrentVideoCaptureDevice is a CString
m_CurrentVideoCaptureDevice = lpszPathName;
int i = m_CurrentVideoCaptureDevice.ReverseFind('\\')+1;
m_CurrentVideoCaptureDevice = m_CurrentVideoCaptureDevice.Mid(i);

SetTitle( m_CurrentVideoCaptureDevice);
m_Grabber.openDev( m_CurrentVideoCaptureDevice );

// Set the first avaiable video format automatically
DShowLib::Grabber::tVidFmtListPtr pVidFmtList = m_Grabber.getAvailableVideoFormats();
if ( pVidFmtList!=0 )
{
int iSize = pVidFmtList->size();
if( iSize > 0)
{
m_Grabber.setVideoFormat( pVidFmtList->at(0) );
}
}

// Set the window handle of the child to display the live video in it
POSITION pos = GetFirstViewPosition();
if( pos != NULL)
{
m_Grabber.setHWND( GetNextView( pos )->m_hWnd);
}

return TRUE;
}

Stefan Geissler
March 7, 2003, 10:35:24
To aviod an errormessage at closing the application, you should also overwrite the OnCloseDocument() method;


void CMultipleCamerasDoc::OnCloseDocument()
{
m_Grabber.stopLive();
m_Grabber.closeDev();

CDocument::OnCloseDocument();
}

bstichbury
March 9, 2003, 23:46:23
Looks good
Thanks again
Brendon