void RunAllCameras(ManagedBusManager busMgr, uint numOfCameras) { const int k_numImages = 10; ManagedCamera[] cameras = new ManagedCamera[numOfCameras]; // Connect to all detected cameras and attempt to set them to // a common video mode and frame rate for (uint i = 0; i < numOfCameras; i++) { cameras[i] = new ManagedCamera(); ManagedPGRGuid guid = busMgr.GetCameraFromIndex(i); // Connect to a camera cameras[i].Connect(guid); // Get the camera information CameraInfo camInfo = cameras[i].GetCameraInfo(); PrintCameraInfo(camInfo); // Set all cameras to a specific mode and frame rate so they // can be synchronized try { cameras[i].SetVideoModeAndFrameRate(VideoMode.VideoMode640x480Y8, FrameRate.FrameRate15); } catch (System.Exception ex) { Console.WriteLine("Error configuring cameras."); Console.WriteLine("This example requires cameras to be able to set to 640x480 Y8 at 15fps."); Console.WriteLine("If your camera does not support this mode, please edit the source code and recompile the application.\n"); return; } } // Put StartSyncCapture in a try-catch block in case // cameras failed to synchronize try { ManagedCamera.StartSyncCapture(numOfCameras, cameras); } catch (System.Exception ex) { Console.WriteLine("Error starting cameras."); Console.WriteLine("This example requires cameras to be able to set to 640x480 Y8 at 15fps."); Console.WriteLine("If your camera does not support this mode, please edit the source code and recompile the application."); Console.WriteLine("Press any key to exit."); Console.ReadKey(); return; } ManagedImage tempImage = new ManagedImage(); // Retrieve images from attached cameras for (int imageCnt = 0; imageCnt < k_numImages; imageCnt++) { for (int camCount = 0; camCount < numOfCameras; camCount++) { // Retrieve an image cameras[camCount].RetrieveBuffer(tempImage); // Display the timestamps for all cameras to show that the // captured image is synchronized for each camera TimeStamp timeStamp = tempImage.timeStamp; Console.Out.WriteLine("Cam {0} - Frame {1} - TimeStamp {2} {3}", camCount, imageCnt, timeStamp.cycleSeconds, timeStamp.cycleCount); } } for (uint i = 0; i < numOfCameras; i++) { // Stop capturing images cameras[i].StopCapture(); // Disconnect the camera cameras[i].Disconnect(); } }
static int StartSyncCaptureAndGrab(ref ManagedCamera[] cameras, uint numCameras) { const int NumImages = 50; ManagedBusManager busMgr = new ManagedBusManager(); // Connect to all detected cameras and attempt to set them to // a common video mode and frame rate for (uint i = 0; i < numCameras; i++) { cameras[i] = new ManagedCamera(); ManagedPGRGuid guid = busMgr.GetCameraFromIndex(i); // Connect to a camera cameras[i].Connect(guid); // Get the camera information CameraInfo camInfo = cameras[i].GetCameraInfo(); PrintCameraInfo(camInfo); // Set all cameras to a specific mode and frame rate so they // can be synchronized. This function is only used for firewire and usb2 cameras try { cameras[i].SetVideoModeAndFrameRate(VideoMode.VideoMode640x480Y8, FrameRate.FrameRate15); } catch (System.Exception /*ex*/) { Console.WriteLine("Error configuring cameras."); Console.WriteLine("This example requires cameras to be able to set to 640x480 Y8 at 15fps."); Console.WriteLine("If your camera does not support this mode, please edit the source code and recompile the application."); return(-1); } } // Put StartSyncCapture in a try-catch block in case // cameras failed to synchronize try { Console.WriteLine("Starting sync capture..."); //sync firewire cameras ManagedCamera.StartSyncCapture(numCameras, cameras); } catch (System.Exception /*ex*/) { Console.WriteLine("Error starting cameras."); Console.WriteLine("This example requires cameras to be able to set to 640x480 Y8 at 15fps."); Console.WriteLine("If your camera does not support this mode, please edit the source code and recompile the application."); return(-1); } ManagedImage tempImage = new ManagedImage(); // Retrieve images from attached cameras for (int imageCnt = 0; imageCnt < NumImages; imageCnt++) { for (int camCount = 0; camCount < numCameras; camCount++) { try { // Retrieve an image cameras[camCount].RetrieveBuffer(tempImage); } catch (FC2Exception ex) { Console.WriteLine("Error retrieving buffer : {0}", ex.Message); continue; } // Display the timestamps for all cameras to show that the // captured image is synchronized for each camera TimeStamp timeStamp = tempImage.timeStamp; Console.Out.WriteLine("Camera {0} - Frame {1} - TimeStamp {2} {3}", camCount, imageCnt, timeStamp.cycleSeconds, timeStamp.cycleCount); } } for (uint i = 0; i < numCameras; i++) { // Stop capturing images cameras[i].StopCapture(); // Disconnect the camera cameras[i].Disconnect(); } return(0); }