void acquisitionWorker_DoWork(object sender, DoWorkEventArgs e) { // This is the main function of the acquisition background worker thread. // Perform image processing here instead of the UI thread to avoid a // sluggish or unresponsive UI. BackgroundWorker worker = (BackgroundWorker)sender; ImageData imdata; #if RANDDATA Random rand = new Random(); double voltage = 0.0; byte[,] im = new byte[480, 640]; PixelValue2D image = new PixelValue2D(im); #endif try { uint bufferNumber = 0; uint outBufferNumber; #if ACQDATA PixelValue2D subPixels = new PixelValue2D(new byte[480, 640]); uint imgnum = 0; int tmp; string pixelValue = ""; ImageType imageType = (ImageType)_session.Attributes[ImaqStandardAttribute.ImageType].GetValue(); PixelValue2D prePixels = _session.Acquisition.Extract(bufferNumber, out outBufferNumber).ToPixelArray(); bufferNumber++; double curVoltage, deltaVoltage; double preVoltage = analogInReader.ReadSingleSample()[0]; #endif // Loop until we tell the thread to cancel or we get an error. When this // function completes the acquisitionWorker_RunWorkerCompleted method will // be called. while (!worker.CancellationPending) { #if RANDDATA for (int x = 0; x < 640; x++) { for (int y = 0; y < 480; y++) { im[y, x] = (byte)rand.Next(0, 255); } } voltage = voltage + 1.0; outBufferNumber = bufferNumber; imdata.imageArray = im; imdata.voltageValue = voltage; imageDataQueue.Enqueue(imdata); imageViewer.Image.ArrayToImage(image); #endif // Get the next image, convert it to a VisionImage and then update the display. // Extracting an image is a 0-copy operation, and we need to copy the // image here for display purposes only. You can perform image processing // on the extractedImage without having to copy it. #if ACQDATA curVoltage = analogInReader.ReadSingleSample()[0]; deltaVoltage = curVoltage - preVoltage; preVoltage = curVoltage; PixelValue2D curPixels = _session.Acquisition.Extract(bufferNumber, out outBufferNumber).ToPixelArray(); for (int x = 0; x < 640; x++) { for (int y=0; y < 480; y++) { tmp = (int)curPixels.U8[y,x] - (int)prePixels.U8[y,x]; tmp = tmp * tmp; subPixels.U8[y, x] = (byte)(tmp > 255 ? 255 : tmp); } } prePixels = curPixels; if (((CheckBox)e.Argument).Checked) { imageViewer.Image.ArrayToImage(subPixels); } else { imageViewer.Image.ArrayToImage(curPixels); } // Enqueue ImageData imdata.imageArray = subPixels.U8; imdata.curVoltage = curVoltage; imdata.deltaVoltage = deltaVoltage; imageDataQueue.Enqueue(imdata); #endif // Update the UI by calling ReportProgress on the background worker. // This will call the acquisition_ProgressChanged method in the UI // thread, where it is safe to update UI elements. Do not update UI // elements directly in this thread as doing so could result in a // deadlock. worker.ReportProgress(0, new UIUpdateArgs(outBufferNumber, deltaVoltage)); bufferNumber++; } } catch (ImaqException ex) { // If an error occurs and the background worker thread is not being // cancelled, then pass the exception along in the result so that // it can be handled in the acquisition_RunWorkerCompleted method. if (!worker.CancellationPending) e.Result = ex; } }
private void Getthemaximum() { PixelValue2D pval = image.ImageToArray(); byte[,] u8array = Getthearray.convertToU8(pval.Rgb32); }