private void InitializeCheckBoxes(CameraPropertyInfo camPropInfo) { if (m_propType == PropertyType.WhiteBalance && m_useValueB == true) { //white balance blue, the check boxes is shared with red SetCheckBoxVisibility(false); return; } if (m_propertyAutoCheckBox.Visible != camPropInfo.autoSupported) { m_propertyAutoCheckBox.Visible = camPropInfo.autoSupported; } if (m_propertyOnOffCheckBox.Visible != camPropInfo.onOffSupported) { m_propertyOnOffCheckBox.Visible = camPropInfo.onOffSupported; } if (m_propertyOnePushButton.Visible != camPropInfo.onePushSupported) { m_propertyOnePushButton.Visible = camPropInfo.onePushSupported; } //if (m_propertyOnePushButton.Visible) //{ // tooltip1.SetToolTip(m_propertyOnePushButton, "One Push"); //} }
private bool UpdateControls() { try { m_propInfo = m_camera.GetPropertyInfo(m_propType); if (!m_propInfo.present) { m_isEnabled = false; SetPropertyVisibility(false); return(false); } m_isEnabled = true; SetPropertyVisibility(true); InitializeCheckBoxes(m_propInfo); CameraProperty camProp = m_camera.GetProperty(m_propType); UpdateSpinButtonRange(m_propInfo); if (UpdateSpinButtonValue(camProp)) { // If UpdateSpinButtonValue() returns true, it means the value has been changed UpdateTrackBarValueFromSpinButton(); } UpdateCheckBoxes(camProp); UpdateUnitText(m_propInfo); } catch (FC2Exception ex) { if (ex.Type != ErrorType.PropertyNotPresent) { Debug.WriteLine(DateTime.Now + " - Update for " + m_propType + " failed with: " + ex.CauseType + " (" + ex.Message + ")"); Debug.WriteLine(ex.NativeErrorTrace); } m_isEnabled = false; SetPropertyVisibility(false); ex.Dispose(); return(false); } // This was added to disable controls on a convert to decimal exception. Bug# 26376. catch (ArgumentException ex) { m_isEnabled = false; SetPropertyVisibility(false); return(false); } return(true); }
private void UpdateSpinButtonRange(CameraPropertyInfo camPropInfo) { try { if (m_isAbsMode) { decimal newMin = Convert.ToDecimal(camPropInfo.absMin); decimal newMax = Convert.ToDecimal(camPropInfo.absMax); if (newMin != m_propertySpinButton.Minimum || newMax != m_propertySpinButton.Maximum) { m_propertySpinButton.Minimum = newMin; m_propertySpinButton.Maximum = newMax; } } else { decimal newMin = Convert.ToDecimal(camPropInfo.min); decimal newMax = Convert.ToDecimal(camPropInfo.max); if (newMin != m_propertySpinButton.Minimum || newMax != m_propertySpinButton.Maximum) { m_propertySpinButton.Minimum = newMin; m_propertySpinButton.Maximum = newMax; } } } catch (System.OverflowException ex) { throw new ArgumentException("Camera property min/max value was either too large or too small."); } // Forcing +/-1 increment for PAN control - Bug 18670 if (camPropInfo.type == PropertyType.Pan) { m_propertyTrackBar.Maximum = (int)m_propertySpinButton.Maximum; m_propertyTrackBar.Minimum = (int)m_propertySpinButton.Minimum; m_propertyTrackBar.LargeChange = 1; m_propertyTrackBar.SmallChange = 1; } }
/// <summary> /// Background worker function for getting live images /// </summary> private void GrabLoop(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; List <ManagedImage> imageList = new List <ManagedImage>(); int i = 0; while (this.grabImages) { try { // Get live image this.camera.RetrieveBuffer(this.rawImage); // Capture frame if recording if (this.Recording) { // Initialize video recording if (i == 0) { // Check if the camera supports the FRAME_RATE property CameraPropertyInfo propInfo = this.camera.GetPropertyInfo(PropertyType.FrameRate); float frameRateToUse = 15.0F; if (propInfo.present == true) { // Get the frame rate CameraProperty prop = this.camera.GetProperty(PropertyType.FrameRate); frameRateToUse = prop.absValue; } // Start AVI writer BackgroundWorker bwVideoWriter = new BackgroundWorker(); bwVideoWriter.DoWork += delegate(object s, DoWorkEventArgs e2) { this.SaveAviHelper(ref imageList, this.videoFileName, frameRateToUse); }; bwVideoWriter.RunWorkerAsync(); } ManagedImage tempImage = new ManagedImage(this.rawImage); imageList.Add(tempImage); i++; } else if (i > 0) { i = 0; this.Recording = false; } } catch (FC2Exception ex) { Logger.Out("Error: " + ex.Message); continue; } // Lock camera while saving processed image for access on other threads lock (this) { this.rawImage.Convert(PixelFormat.PixelFormatMono8, this.ProcessedImage); } worker.ReportProgress(0); } this.grabThreadExited.Set(); }
private void UpdateUnitText(CameraPropertyInfo camPropInfo) { m_propertyAbsUnitLabel.Text = camPropInfo.unitAbbr; }
void RunCamera(ManagedPGRGuid guid) { const uint NumImages = 100; try { using (ManagedCamera cam = new ManagedCamera()) { cam.Connect(guid); CameraInfo camInfo = cam.GetCameraInfo(); PrintCameraInfo(camInfo); // Start capturing images Console.WriteLine("Starting capture..."); cam.StartCapture(); List <ManagedImage> imageList = new List <ManagedImage>(); ManagedImage rawImage = 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; } ManagedImage tempImage = new ManagedImage(rawImage); imageList.Add(tempImage); Console.WriteLine("Grabbed image {0}", imageCnt); } // Stop capturing images Console.WriteLine("Stopping capture..."); // Check if the camera supports the FRAME_RATE property CameraPropertyInfo propInfo = cam.GetPropertyInfo(PropertyType.FrameRate); float frameRateToUse = 15.0F; if (propInfo.present == true) { // Get the frame rate CameraProperty prop = cam.GetProperty(PropertyType.FrameRate); frameRateToUse = prop.absValue; } Console.WriteLine("Using frame rate of {0}", frameRateToUse); string aviFileName; // Uncompressed videos are always saved with avi containers with or without // extensions specified in the filepath aviFileName = String.Format("SaveImageToAviEx_CSharp-Uncompressed-{0}", camInfo.serialNumber); SaveAviHelper(AviType.Uncompressed, ref imageList, aviFileName, frameRateToUse); // Motion JPEG videos are always saved with avi containers with or without // extensions specified in the filepath aviFileName = String.Format("SaveImageToAviEx_CSharp-Mjpg-{0}", camInfo.serialNumber); SaveAviHelper(AviType.Mjpg, ref imageList, aviFileName, frameRateToUse); // H.264 videos defaults to saving in mp4 containers if extensions are not // specified. Otherwise the extension specified by the user will be used. aviFileName = String.Format("SaveImageToAviEx_CSharp-H264-{0}", camInfo.serialNumber); SaveAviHelper(AviType.H264, ref imageList, aviFileName, frameRateToUse); } } catch (FC2Exception ex) { Console.WriteLine("There was an FC2 error: " + ex.Message); } }
void RunCamera(ManagedPGRGuid guid) { const uint k_numImages = 100; try { using (ManagedCamera cam = new ManagedCamera()) { cam.Connect(guid); CameraInfo camInfo = cam.GetCameraInfo(); PrintCameraInfo(camInfo); // Start capturing images Console.WriteLine("Starting capture..."); cam.StartCapture(); List <ManagedImage> imageList = new List <ManagedImage>(); ManagedImage rawImage = new ManagedImage(); for (int imageCnt = 0; imageCnt < k_numImages; imageCnt++) { cam.RetrieveBuffer(rawImage); ManagedImage tempImage = new ManagedImage(rawImage); imageList.Add(tempImage); Console.WriteLine("Grabbed image {0}", imageCnt); } // Stop capturing images Console.WriteLine("Stopping capture..."); // Check if the camera supports the FRAME_RATE property CameraPropertyInfo propInfo = cam.GetPropertyInfo(PropertyType.FrameRate); float frameRateToUse = 15.0F; if (propInfo.present == true) { // Get the frame rate CameraProperty prop = cam.GetProperty(PropertyType.FrameRate); frameRateToUse = prop.absValue; } Console.WriteLine("Using frame rate of {0}", frameRateToUse); string aviFileName; aviFileName = String.Format("SaveImageToAviEx_CSharp-Uncompressed-{0}", camInfo.serialNumber); SaveAviHelper(AviType.Uncompressed, ref imageList, aviFileName, frameRateToUse); aviFileName = String.Format("SaveImageToAviEx_CSharp-Mjpg-{0}", camInfo.serialNumber); SaveAviHelper(AviType.Mjpg, ref imageList, aviFileName, frameRateToUse); aviFileName = String.Format("SaveImageToAviEx_CSharp-h264-{0}", camInfo.serialNumber); SaveAviHelper(AviType.H264, ref imageList, aviFileName, frameRateToUse); } } catch (FC2Exception ex) { Console.WriteLine("There was an FC2 error: " + ex.Message); } }