private void stream() { image = new VisionImage(); try { imaqdxSession.ConfigureGrab(); } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); return; } for (; ;) { lock (streamStopLock) { try { imaqdxSession.Grab(image, true); if (analyse) { PixelValue2D pval = image.ImageToArray(); byte[,] u8array = Getthearray.convertToU8(pval.Rgb32); max = Getthearray.Findthemaximum(u8array); imageWindow.WriteToConsole(max.ToString("F6")); } } catch (InvalidOperationException e) { MessageBox.Show("Something bad happened. Stopping the image stream.\n" + e.Message); state = CameraState.FREE; return; } try { if (windowShowing) { imageWindow.AttachToViewer(image); } } catch (InvalidOperationException e) { MessageBox.Show("I have a leftover image without anywhere to display it. Dumping...\n\n" + e.Message); imaqdxSession.Acquisition.Stop(); state = CameraState.FREE; return; } if (state != CameraState.STREAMING) { imaqdxSession.Acquisition.Stop(); state = CameraState.FREE; return; } } } }
private void stream() { image = new VisionImage(); try { imaqdxSession.ConfigureGrab(); } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); return; } for (; ;) { lock (streamStopLock) { try { imaqdxSession.Grab(image, true); } catch (InvalidOperationException e) { MessageBox.Show("Something bad happened. Stopping the image stream.\n" + e.Message); state = CameraState.FREE; return; } try { if (windowShowing) { imageWindow.AttachToViewer(image); } } catch (InvalidOperationException e) { MessageBox.Show("I have a leftover image without anywhere to display it. Dumping...\n\n" + e.Message); imaqdxSession.Acquisition.Stop(); state = CameraState.FREE; return; } if (state != CameraState.STREAMING) { imaqdxSession.Acquisition.Stop(); state = CameraState.FREE; return; } } } }
/// <summary> /// 开始飞拍 /// </summary> public void StartFly() { bFly = true; try { // 设置外触发 _session.Acquisition.Unconfigure(); _session.Attributes["CameraAttributes::AcquisitionControl::TriggerMode"].SetValue(1); _session.Attributes["CameraAttributes::AcquisitionControl::TriggerSource"].SetValue(1); _session.ConfigureGrab(); Thread thd = new Thread(GrabThread); thd.Start(); } catch { } }
private void startButton_Click(object sender, EventArgs e) { try { // Open a new session and configure a grab _session = new ImaqdxSession(cameraComboBox.Text); _session.ConfigureGrab(); // Update UI state startButton.Enabled = false; stopButton.Enabled = true; // Start up background worker to acquire images acquisitionWorker.RunWorkerAsync(); } catch (ImaqdxException ex) { MessageBox.Show(ex.Message, "NI-IMAQdx Error"); } }
private void stream() { ushort[,] latestdata; double summedPixels = 0; SummedPixels = 0; image = new VisionImage(); try { imaqdxSession.ConfigureGrab(); } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); return; } for (; ;) { lock (streamStopLock) { try { imaqdxSession.Grab(image, true); } catch (InvalidOperationException e) { MessageBox.Show("Something bad happened. Stopping the image stream.\n" + e.Message); state = CameraState.FREE; return; } try { if (windowShowing) { imageWindow.AttachToViewer(image); if (imageWindow.imageViewer.Roi != null) { RectangleContour contour = imageWindow.imageViewer.Roi.GetBoundingRectangle(); int height = (int)contour.Height; int width = (int)contour.Width; PixelValue2D pval = image.ImageToArray(contour); if (image.Type == ImageType.U8) { ushort[,] ushortData = new ushort[pval.U8.GetLength(0), pval.U8.GetLength(1)]; for (int j = 0; j < pval.U8.GetLength(0); j++) { for (int i = 0; i < pval.U8.GetLength(1); i++) { ushortData[j, i] = (pval.U8)[j, i]; } } latestdata = ushortData; } else { latestdata = pval.U16; } summedPixels = 0; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { summedPixels = summedPixels + latestdata[j, i]; } } SummedPixels = summedPixels; } } } catch (InvalidOperationException e) { MessageBox.Show("I have a leftover image without anywhere to display it. Dumping...\n\n" + e.Message); imaqdxSession.Acquisition.Stop(); state = CameraState.FREE; return; } if (state != CameraState.STREAMING) { imaqdxSession.Acquisition.Stop(); state = CameraState.FREE; return; } } } }