- void RunSingleCamera(ManagedPGRGuid guid)
- {
- const int NumImages = 10;
- ManagedCamera cam = new ManagedCamera();
- // Connect to a camera
- cam.Connect(guid);
- // Get the camera information
- CameraInfo camInfo = cam.GetCameraInfo();
- PrintCameraInfo(camInfo);
- // Get embedded image info from camera
- EmbeddedImageInfo embeddedInfo = cam.GetEmbeddedImageInfo();
- // Enable timestamp collection
- if (embeddedInfo.timestamp.available == true)
- {
- embeddedInfo.timestamp.onOff = true;
- }
- // Set embedded image info to camera
- cam.SetEmbeddedImageInfo(embeddedInfo);
- // Start capturing images
- cam.StartCapture();
- // Create a raw image
- ManagedImage rawImage = new ManagedImage();
- // Create a converted image
- ManagedImage convertedImage = new ManagedImage();
- for (int imageCnt = 0; imageCnt < NumImages; imageCnt++)
- {
- try
- {
- // Retrieve an image
- cam.RetrieveBuffer(rawImage);
- }
- catch (FC2Exception ex)
- {
- Console.WriteLine("Error retrieving buffer : {0}", ex.Message);
- continue;
- }
- // Get the timestamp
- TimeStamp timeStamp = rawImage.timeStamp;
- Console.WriteLine(
- "Grabbed image {0} - {1} {2} {3}",
- imageCnt,
- timeStamp.cycleSeconds,
- timeStamp.cycleCount,
- timeStamp.cycleOffset);
- // Convert the raw image
- rawImage.Convert(PixelFormat.PixelFormatBgr, convertedImage);
- // Create a unique filename
- string filename = String.Format(
- "FlyCapture2Test_CSharp-{0}-{1}.bmp",
- camInfo.serialNumber,
- imageCnt);
- // Get the Bitmap object. Bitmaps are only valid if the
- // pixel format of the ManagedImage is RGB or RGBU.
- System.Drawing.Bitmap bitmap = convertedImage.bitmap;
- // Save the image
- bitmap.Save(filename);
- }
- // Stop capturing images
- cam.StopCapture();
- // Disconnect the camera
- cam.Disconnect();
- }
复制代码
|