/// <summary> /// Method is called whenever user presses the start processing button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbtn_Start_Click(object sender, EventArgs e) { log.Info("MainForm.tsbtn_Start_Click : User pressed start processing button."); if (Start()) { Camera1Display.Lock(); Camera2Display.Lock(); cmboCam1View.SelectedIndex = cmboCam1View.Items.IndexOf(DISPLAY_TYPE_PROCESSED); cmboCam2View.SelectedIndex = cmboCam2View.Items.IndexOf(DISPLAY_TYPE_PROCESSED); tsbtn_Stop.Enabled = true; tsbtn_Start.Enabled = false; tsbtn_Settings.Enabled = false; } }
/// <summary> /// Method is called whenever user presses the stop processing button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbtn_Stop_Click(object sender, EventArgs e) { log.Info("MainForm.tsbtn_Stop_Click : User pressed stop processing button."); Stop(); cmboCam1View.SelectedIndex = cmboCam1View.Items.IndexOf(DISPLAY_TYPE_NORMAL); cmboCam2View.SelectedIndex = cmboCam2View.Items.IndexOf(DISPLAY_TYPE_NORMAL); Camera1Display.UnLock(); Camera2Display.UnLock(); tsbtn_Stop.Enabled = false; tsbtn_Start.Enabled = true; ipQueue1.reset(); ipQueue2.reset(); tsbtn_Settings.Enabled = true; }
public MainForm() { log4net.Config.XmlConfigurator.Configure(); log.Info("MainForm.MainForm : Application opened as " + PROGRAM_NAME); InitializeComponent(); this.Text = PROGRAM_NAME; isCameraMode = false; zibReplayCam1.SetText(""); zibReplayCam2.SetText(""); Camera1Display.SetText(""); Camera2Display.SetText(""); SwitchDisplayMode(); guiSem = new Semaphore(0, 1); program_settings = new Settings(); // see how much memory is available on computer and take 80% of it float freeMem = 1000; try { System.Diagnostics.PerformanceCounter ramCounter = new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes"); freeMem = ramCounter.NextValue(); } catch (Exception inner) { log.Error("MainForm.Form1_Load : Unable to retrieve amount of free memory on system, defaulting to 1GB.", inner); } if (freeMem > 2100) { freeMem = 2100; } // each queue takes 6 MB per item in it int queueSize = 50;//Convert.ToInt32(freeMem * 0.90) / 32; mainQueue = new CircularQueue <QueueElement>("MAIN", queueSize); ipQueue1 = new CircularQueue <QueueElement>("IP1", queueSize); ipQueue2 = new CircularQueue <QueueElement>("IP2", queueSize); saveQueue = new CircularQueue <QueueElement>("save_queue", queueSize); // initialize camera and processor 1 cam1 = new Camera(); cam1.AddSubscriber(ipQueue1); cam1.AddSubscriber(mainQueue); imagep1 = new FailureDetector(DEFAULT_IMAGE_PROCESSOR1_NAME, ref cam1); imagep1.SetConsumerQueue(ipQueue1); imagep1.AddSubscriber(saveQueue); imagep1.AddSubscriber(mainQueue); imagep1.EnableAutoExposure(true); imagep1.EnableAutoROI(false); // initialize camera and processor 2 cam2 = new Camera(); cam2.AddSubscriber(ipQueue2); cam2.AddSubscriber(mainQueue); imagep2 = new FailureDetector(DEFAULT_IMAGE_PROCESSOR2_NAME, ref cam2); imagep2.SetConsumerQueue(ipQueue2); imagep2.AddSubscriber(saveQueue); imagep2.AddSubscriber(mainQueue); imagep2.EnableAutoExposure(true); imagep2.EnableAutoROI(false); // sets image queue saveEngine = new ImageHistoryBuffer(); saveEngine.SetConsumerQueue(saveQueue); // add thread error handlers cam1.ThreadError += new ThreadErrorHandler(Camera0ThreadError); cam2.ThreadError += new ThreadErrorHandler(Camera1ThreadError); imagep1.ThreadError += new ThreadErrorHandler(ImageProcessor0ThreadError); imagep2.ThreadError += new ThreadErrorHandler(ImageProcessor0ThreadError); saveEngine.ThreadError += new ThreadErrorHandler(SaveQueueThreadError); // start the cameras RefreshCameras(); // initialize camera and processor periods camera1Period = 0.066; camera2Period = 0.066; process1Period = 0.2; process2Period = 0.2; // need to update comboboxes cmboCam1View.Items.Add(DISPLAY_TYPE_NORMAL); cmboCam1View.Items.Add(DISPLAY_TYPE_PROCESSED); cmboCam1View.SelectedIndex = 0; cmboCam2View.Items.Add(DISPLAY_TYPE_NORMAL); cmboCam2View.Items.Add(DISPLAY_TYPE_PROCESSED); cmboCam2View.SelectedIndex = 0; cmbo_DataType.Items.Add(DISPLAY_TYPE_NORMAL); cmbo_DataType.Items.Add(DISPLAY_TYPE_PROCESSED); cmbo_DataType.SelectedIndex = 1; cmbo_VideoType.Items.Add(VIDEO_TYPE_TEST); cmbo_VideoType.Items.Add(VIDEO_TYPE_DEBUG); cmbo_VideoType.SelectedIndex = 0; cmbo_DataType.SelectedIndexChanged += cmbo_DataType_SelectedIndexChanged; cmbo_VideoType.SelectedIndexChanged += cmbo_VideoType_SelectedIndexChanged; isReplayManagerValid = false; guiSem.Release(); // setup timer update TimerCallback tcb = new TimerCallback(DisplayImage); imageUpdateTimer = new System.Threading.Timer(tcb, imageUpdateTimer, Timeout.Infinite, Timeout.Infinite); imageUpdateTimer.Change(1, 200); // setup garbage collector TimerCallback tcb2 = new TimerCallback(GarbageCollector); garbageCollector = new System.Threading.Timer(tcb2, garbageCollector, Timeout.Infinite, Timeout.Infinite); garbageCollector.Change(1, 100); // setup replay feedback TimerCallback tcb3 = new TimerCallback(ReplayFeedbackTimer); replayFeedbackTimer = new System.Threading.Timer(tcb3, replayFeedbackTimer, Timeout.Infinite, Timeout.Infinite); }
private bool Start() { log.Info("MainForm.Start : Starting image processors and save queue engine."); // set parameters for image processors MetaData metadata = MetaData.Instance; imagep1.SetContrast(metadata.MinimumContrast); imagep1.SetRange(metadata.ImagerNoise); imagep1.SetTargetIntensity(metadata.TargetIntenstiy); imagep2.SetContrast(metadata.MinimumContrast); imagep2.SetRange(metadata.ImagerNoise); imagep2.SetTargetIntensity(metadata.TargetIntenstiy); Rectangle r = Camera1Display.GetRegionToProcess(); if (r != Rectangle.Empty) { imagep1.EnableAutoROI(true); imagep1.SetRegionToProcess(r); } else { imagep1.EnableAutoROI(false); } r = Camera2Display.GetRegionToProcess(); if (r != Rectangle.Empty) { imagep2.EnableAutoROI(true); imagep2.SetRegionToProcess(r); } else { imagep2.EnableAutoROI(false); } try { imagep1.Start(1000 / metadata.TestFrequency); } catch (Exception inner) { string errMsg = "MainForm.Start : Error starting image processor 1."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); DisplayError(errMsg, ex); return(false); } Thread.Sleep(100); try { imagep2.Start(1000 / metadata.TestFrequency); } catch (Exception inner) { string errMsg = "MainForm.Start : Error starting image processor 2."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); DisplayError(errMsg, ex); return(false); } try { saveEngine.Start(5); } catch (Exception inner) { string errMsg = "MainForm.Start : Error starting save engine."; MainFormException ex = new MainFormException(errMsg, inner); log.Error(errMsg, ex); DisplayError(errMsg, ex); return(false); } return(true); }
/// <summary> /// Function should be called whenever the data from camera 1 changes. /// </summary> private void UpdateCamera1Image() { if (Camera1Display.InvokeRequired || gbCamera1.InvokeRequired) { UpdateCamera1ImageCallback d = new UpdateCamera1ImageCallback(UpdateCamera1Image); this.BeginInvoke(d, null); } else { // obtain ownership of gui control to enter critical section guiSem.WaitOne(); // verify camera 1 data is not null if (camera1Data != null) { switch (Cam1DisplayType) { case DISPLAY_TYPE_NORMAL: try { if (!camera1Data.IsProcessed) { Camera1Display.SetImage(camera1Data.GetRawDataImage()); } } catch (Exception inner) { log.Error("MainForm.UpdateCamera1Image : Unable to set camera 1 display image.", inner); } break; case DISPLAY_TYPE_PROCESSED: try { if (camera1Data.IsProcessed) { Camera1Display.SetImage(camera1Data.GetProcessedDataImage()); } } catch (Exception inner) { log.Error("MainForm.UpdateCamera1Image : Unable to set camera 1 display image.", inner); } break; default: break; } // update camera 1 information camera1Period = 0.85 * camera1Period + 0.15 * camera1Data.CameraElapsedTime_s; lblCam1FPS.Text = "Frames Per Second: " + String.Format("{0:0.00}", (1 / camera1Period)); if (camera1Data.ImageProcessorElapsedTime_s != 0) { process1Period = 0.95 * process1Period + 0.05 * camera1Data.ImageProcessorElapsedTime_s; lblCam1IPFPS.Text = "Image Processor FPS: " + String.Format("{0:0.00}", (1 / process1Period)); } lblCam1Exposure.Text = "Exposure: " + String.Format("{0:0.00}", camera1Data.ImageExposure_s * 1000); if (camera1Data.IsProcessed) { lblCam1Intensity.Text = "Intensity: " + camera1Data.ImageIntensity_lsb.ToString(); lblCam1CracksDetected.Text = "Crack Detected: " + camera1Data.ContainsCrack.ToString(); lblCam1PotentialCracks.Text = "Potential Cracks: " + camera1Data.PotentialCrackCount.ToString(); } } // release ownership of critical section guiSem.Release(); } }