public byte[,] SingleSnapshot(string attributesPath, bool addToImageList) { imageWindow.WriteToConsole("Taking snapshot"); imageWindow.WriteToConsole("Applied camera attributes from " + attributesPath); SetCameraAttributes(attributesPath); try { if (state == CameraState.FREE || state == CameraState.READY_FOR_ACQUISITION) { image = new VisionImage(); state = CameraState.READY_FOR_ACQUISITION; try { imaqdxSession.Snap(image); if (windowShowing) { imageWindow.AttachToViewer(image); } if (addToImageList) { imageList.Add(image); } image.WriteFile("test.bmp"); PixelValue2D pval = image.ImageToArray(); byte[,] u8array = Getthearray.convertToU8(pval.Rgb32); double max = Getthearray.Findthemaximum(u8array); imageWindow.WriteToConsole(max.ToString("F6")); state = CameraState.FREE; return(u8array); } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); throw new ObjectDisposedException(""); } catch (ImaqdxException e) { MessageBox.Show(e.Message); throw new ImaqdxException(); } catch (VisionException e) { MessageBox.Show(e.VisionErrorText); throw e; } } else { return(null); } } catch (TimeoutException) { return(null); } }
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; } } } }
public byte[,] SingleSnapshot(string attributesPath, bool addToImageList) { imageWindow.WriteToConsole("Taking snapshot"); imageWindow.WriteToConsole("Applied camera attributes from " + attributesPath); SetCameraAttributes(attributesPath); try { if (state == CameraState.FREE) { image = new VisionImage(); state = CameraState.READY_FOR_ACQUISITION; try { imaqdxSession.Snap(image); if (windowShowing) { imageWindow.AttachToViewer(image); } if (addToImageList) { imageList.Add(image); } PixelValue2D pval = image.ImageToArray(); state = CameraState.FREE; return(pval.U8); } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); throw new ObjectDisposedException(""); } catch (ImaqdxException e) { MessageBox.Show(e.Message); throw new ImaqdxException(); } } else { return(null); } } catch (TimeoutException) { return(null); } }
public byte[,] SingleSnapshot(string attributesPath, bool addToImageList) { imageWindow.WriteToConsole("Taking snapshot"); imageWindow.WriteToConsole("Applied camera attributes from " + attributesPath); SetCameraAttributes(attributesPath); try { if (state == CameraState.FREE) { image = new VisionImage(); state = CameraState.READY_FOR_ACQUISITION; try { imaqdxSession.Snap(image); if (windowShowing) { imageWindow.AttachToViewer(image); } if (addToImageList) { imageList.Add(image); } PixelValue2D pval = image.ImageToArray(); state = CameraState.FREE; return pval.U8; } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); throw new ObjectDisposedException(""); } catch (ImaqdxException e) { MessageBox.Show(e.Message); throw new ImaqdxException(); } } else return null; } catch (TimeoutException) { return null; } }
private void Getthemaximum() { PixelValue2D pval = image.ImageToArray(); byte[,] u8array = Getthearray.convertToU8(pval.Rgb32); }
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; } } } }
public ushort[,] SingleSnapshot(string attributesPath, bool addToImageList) { imageWindow.WriteToConsole("Taking snapshot"); imageWindow.WriteToConsole("Applied camera attributes from " + attributesPath); SetCameraAttributes(attributesPath); Stopwatch watch = new Stopwatch(); try { if (state == CameraState.FREE) { image = new VisionImage(); state = CameraState.READY_FOR_ACQUISITION; try { watch.Start(); imaqdxSession.Snap(image); watch.Stop(); if (windowShowing) { long snaptime = watch.ElapsedMilliseconds; imageWindow.AttachToViewer(image); imageWindow.WriteToConsole(snaptime.ToString()); } if (addToImageList) { imageList.Add(image); } PixelValue2D pval = image.ImageToArray(); state = CameraState.FREE; 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]; } } return(ushortData); } if (image.Type == ImageType.U16) { return(pval.U16); } else { return(null); } } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); throw new ObjectDisposedException(""); } catch (ImaqdxException e) { MessageBox.Show(e.Message); throw new ImaqdxException(); } catch (VisionException e) { MessageBox.Show(e.VisionErrorText); throw new TimeoutException(); } } else { return(null); } } catch (TimeoutException) { return(null); } }
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; } } } }
public byte[,] SingleSnapshot(string attributesPath, bool addToImageList) { imageWindow.WriteToConsole("Taking snapshot"); imageWindow.WriteToConsole("Applied camera attributes from " + attributesPath); SetCameraAttributes(attributesPath); try { if (state == CameraState.FREE || state == CameraState.READY_FOR_ACQUISITION) { image = new VisionImage(); state = CameraState.READY_FOR_ACQUISITION; try { imaqdxSession.Snap(image); if (windowShowing) { imageWindow.AttachToViewer(image); } if (addToImageList) { imageList.Add(image); } image.WriteFile("test.bmp"); PixelValue2D pval = image.ImageToArray(); byte[,] u8array = Getthearray.convertToU8(pval.Rgb32); double max = Getthearray.Findthemaximum(u8array); imageWindow.WriteToConsole(max.ToString("F6")); state = CameraState.FREE; return u8array; } catch (ObjectDisposedException e) { MessageBox.Show(e.Message); throw new ObjectDisposedException(""); } catch (ImaqdxException e) { MessageBox.Show(e.Message); throw new ImaqdxException(); } catch (VisionException e) { MessageBox.Show(e.VisionErrorText); throw e; } } else return null; } catch (TimeoutException) { return null; } }