/* 获取照片 Handles the event related to an image having been taken and waiting for processing. */ private void OnImageReadyEventCallback() { if (InvokeRequired) { /* If called from a different thread, we must use the BeginInvoke method to marshal the call to the proper thread. */ BeginInvoke(new ImageProvider.ImageReadyEventHandler(OnImageReadyEventCallback)); return; } try { /* Acquire the image from the image provider. Only show the latest image. The camera may acquire images faster than images can be displayed*/ ImageProvider.Image image = m_imageProvider.GetLatestImage(); /* Check if the image has been removed in the meantime. */ if (image != null) { if (m_event_bmpReceive != null) { m_event_bmpReceive(image); } m_imageProvider.ReleaseImage(); } } catch (Exception e) { //logWR.appendNewLogMessage("照片采集OnImageReadyEventCallback error : \r\n" + e.ToString()); } }
/* Handles the event related to an image having been taken and waiting for processing. */ private void OnImageReadyEventCallback() { /* Acquire the image from the image provider. Only show the latest image. The camera may acquire images faster than images can be displayed*/ ImageProvider.Image image = m_imageProvider.GetLatestImage(); /* Check if the image has been removed in the meantime. */ if (image != null) { /* Check if the image is compatible with the currently used bitmap. */ if (BitmapFactory.IsCompatible(m_bitmap, image.Width, image.Height, image.Color)) { /* Update the bitmap with the image data. */ BitmapFactory.UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); Finish = true; } else /* A new bitmap is required. */ { BitmapFactory.CreateBitmap(out m_bitmap, image.Width, image.Height, image.Color); BitmapFactory.UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); Finish = true; } /* The processing of the image is done. Release the image buffer. */ m_imageProvider.ReleaseImage(); /* The buffer can be used for the next image grabs. */ } }
/* Handles the event related to an image having been taken and waiting for processing. */ private void OnImageReadyEventCallback() { try { lock (sny_Obj) { //bGrabDone = false; System.Threading.Thread.Sleep(3); /* Acquire the image from the image provider. Only show the latest image. The camera may acquire images faster than images can be displayed*/ ImageProvider.Image image = m_imageProvider.GetLatestImage(); /* Check if the image has been removed in the meantime. */ if (image != null) { mhalcon_image2.GenEmptyObj(); mhalcon_image1.GenEmptyObj(); if (IsCompatible(m_bitmap, image.Width, image.Height, image.Color)) { mhalcon_image2 = UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); mhalcon_image1 = UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); // mCGigecamera.GenertateGrayBitmap(mhalcon_image, out mm_bitmap); /* To show the new image, request the display control to update itself. */ //pictureBox1.Refresh(); } else { CreateBitmap(out m_bitmap, image.Width, image.Height, image.Color); mhalcon_image2 = UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); mhalcon_image1 = UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); } ImgHeight = image.Height; ImgWidth = image.Width; /* The processing of the image is done. Release the image buffer. */ m_imageProvider.ReleaseImage(); //BitmapData bmpData = m_bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, bitmap.PixelFormat); /* Get the pointer to the bitmap's buffer. */ //IntPtr ptrBmp = bmpData.Scan0; OnImageReadyEvent(); } while (!bGrabDone) { Thread.Sleep(5); } Thread.Sleep(10); } } catch (Exception) { //ShowException(e, m_imageProvider.GetLastErrorMessage()); } }
/* Handles the event related to an image having been taken and waiting for processing. */ private void OnImageReadyEventCallback() { if (InvokeRequired) { /* Suspend the grab thread for a while to avoid blocking the computer by using up all processor resources. */ System.Threading.Thread.Sleep(20); /* This is only required for this sample. */ /* If called from a different thread, we must use the Invoke method to marshal the call to the proper thread. */ BeginInvoke(new ImageProvider.ImageReadyEventHandler(OnImageReadyEventCallback)); return; } try { /* Acquire the image from the image provider. */ ImageProvider.Image image = m_imageProvider.GetCurrentImage(); /* Check if the image has been removed in the meantime. */ if (image != null) { /* Check if the image is compatible with the currently used bitmap. */ if (BitmapFactory.IsCompatible(m_bitmap, image.Width, image.Height, image.Color)) { /* Update the bitmap with the image data. */ BitmapFactory.UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); /* To show the new image, request the display control to update itself. */ pictureBox.Refresh(); } else /* A new bitmap is required. */ { BitmapFactory.CreateBitmap(ref m_bitmap, image.Width, image.Height, image.Color); BitmapFactory.UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); /* Provide the display control with the new bitmap. This action automatically updates the display. */ pictureBox.Image = m_bitmap; } if (is_recording == true) { RotateFlipType t = RotateFlipType.RotateNoneFlipY; m_bitmap.RotateFlip(t); aw.AddFrame(m_bitmap); } /* The processing of the image is done. Release the image buffer. */ m_imageProvider.ReleaseImage(); /* The buffer can be used for the next image grabs. * If another image is in the output queue it can be acquired now using GetCurrentImage(). */ } } catch (Exception e) { ShowException(e, m_imageProvider.GetLastErrorMessage()); } }
/* Handles the event related to an image having been taken and waiting for processing. */ private void OnImageReadyEventCallback() { if (InvokeRequired) { /* If called from a different thread, we must use the Invoke method to marshal the call to the proper thread. */ BeginInvoke(new ImageProvider.ImageReadyEventHandler(OnImageReadyEventCallback)); return; } try { /* Acquire the image from the image provider. Only show the latest image. The camera may acquire images faster than images can be displayed*/ ImageProvider.Image image = m_imageProvider.GetLatestImage(); /* Check if the image has been removed in the meantime. */ if (image != null) { /* Check if the image is compatible with the currently used bitmap. */ if (BitmapFactory.IsCompatible(m_bitmap, image.Width, image.Height, image.Color)) { /* Update the bitmap with the image data. */ BitmapFactory.UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); /* To show the new image, request the display control to update itself. */ pictureBox.Refresh(); } else /* A new bitmap is required. */ { BitmapFactory.CreateBitmap(out m_bitmap, image.Width, image.Height, image.Color); BitmapFactory.UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); /* We have to dispose the bitmap after assigning the new one to the display control. */ Bitmap bitmap = pictureBox.Image as Bitmap; /* Provide the display control with the new bitmap. This action automatically updates the display. */ pictureBox.Image = m_bitmap; if (bitmap != null) { /* Dispose the bitmap. */ bitmap.Dispose(); } } /* The processing of the image is done. Release the image buffer. */ m_imageProvider.ReleaseImage(); /* The buffer can be used for the next image grabs. */ } } catch (Exception e) { ShowException(e, m_imageProvider.GetLastErrorMessage()); } }
/// <summary> /// 影像擷取完成通知 /// </summary> private void OnImageReadyEventCallback() { try { /* Acquire the image from the image provider. Only show the latest image. The camera may acquire images faster than images can be displayed*/ ImageProvider.Image image = m_imageProvider.GetLatestImage(); /* Check if the image has been removed in the meantime. */ if (image != null) { //利用 GC Handle , 釘住記憶體不讓釋放,取得該記憶體位址 GCHandle pinnedArray = GCHandle.Alloc(image.Buffer, GCHandleType.Pinned); IntPtr pointer = pinnedArray.AddrOfPinnedObject(); try { //'byte', 'complex', 'cyclic', 'direction', 'int1', 'int2', 'int4', 'int8', 'real', 'uint2' var imgType = "byte"; HImage img = new HImage(imgType, image.Width, image.Height, pointer); if (GrabImageChanged != null) { GrabImageChanged(m_imageProvider , new System.ComponentModel.ProgressChangedEventArgs(1, img)); } } catch (Exception ex) { errorNotify(ex); } finally { //用完要釋放,否則該記憶體不會被回收 pinnedArray.Free(); } /* The processing of the image is done. Release the image buffer. */ m_imageProvider.ReleaseImage(); /* The buffer can be used for the next image grabs. */ } } catch (Exception e) { OnGrabErrorEventCallback(e, m_imageProvider.GetLastErrorMessage()); } }
private void imageProvider_ImageReadyEvent() { // Consume the Pylon queue (no copy). ImageProvider.Image pylonImage = imageProvider.GetLatestImage(); if (pylonImage == null) { return; } ComputeDataRate(pylonImage.Buffer.Length); if (FrameProduced != null) { FrameProduced(this, new FrameProducedEventArgs(pylonImage.Buffer, pylonImage.Buffer.Length)); } imageProvider.ReleaseImage(); }
private bool GetInputImage(ImageProvider.Image image) { bool reSuccess = false; try { if (image != null) { Bitmap bImage = null; BitmapFactory.CreateBitmap(out bImage, image.Width, image.Height, image.Color); BitmapFactory.UpdateBitmap(bImage, image.Buffer, image.Width, image.Height, image.Color); InputImage = bImage; reSuccess = true; } } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message + GetBaslerException(), true, true); } return(reSuccess); }
private void imageProvider_ImageReadyEvent() { ImageProvider.Image pylonImage = imageProvider.GetLatestImage(); if (pylonImage == null) { waitHandle.Set(); return; } image = null; BitmapFactory.CreateBitmap(out image, pylonImage.Width, pylonImage.Height, pylonImage.Color); BitmapFactory.UpdateBitmap(image, pylonImage.Buffer, pylonImage.Width, pylonImage.Height, pylonImage.Color); imageProvider.ReleaseImage(); if (image != null) { int bufferSize = ImageFormatHelper.ComputeBufferSize(image.Width, image.Height, Kinovea.Services.ImageFormat.RGB24); imageDescriptor = new ImageDescriptor(Kinovea.Services.ImageFormat.RGB24, image.Width, image.Height, true, bufferSize); } waitHandle.Set(); }
private void imageProvider_ImageReadyEvent() { // Consume the Pylon queue (no copy). ImageProvider.Image pylonImage = imageProvider.GetLatestImage(); if (pylonImage == null) { return; } if (finishline.Enabled) { bool flush = finishline.Consolidate(pylonImage.Buffer); imageProvider.ReleaseImage(); if (flush) { ComputeDataRate(finishline.BufferOutput.Length); if (FrameProduced != null) { FrameProduced(this, new FrameProducedEventArgs(finishline.BufferOutput, finishline.BufferOutput.Length)); } } } else { ComputeDataRate(pylonImage.Buffer.Length); if (FrameProduced != null) { FrameProduced(this, new FrameProducedEventArgs(pylonImage.Buffer, pylonImage.Buffer.Length)); } imageProvider.ReleaseImage(); } }
/// <summary> /// Acquire the image from the image provider. /// </summary> /// <returns>current image</returns> public Bitmap GetCurrentFrame() { Bitmap currentFrame = null; try { int timeoutFrame = Environment.TickCount; ImageProvider.Image lastestFrame = null; while (lastestFrame == null) { lastestFrame = this.imageProvider.GetLatestImage(); if (Environment.TickCount - timeoutFrame > 10000) { break; //10s } } Bitmap tmpFrame = null; if (lastestFrame != null) { BitmapFactory.CreateBitmap(out tmpFrame, lastestFrame.Width, lastestFrame.Height, lastestFrame.Color); BitmapFactory.UpdateBitmap(tmpFrame, lastestFrame.Buffer, lastestFrame.Width, lastestFrame.Height, lastestFrame.Color); tmpFrame.RotateFlip(RotateFlipType.Rotate180FlipNone); // The processing of the image is done. Release the image buffer. this.imageProvider.ReleaseImage(); } currentFrame = tmpFrame; } catch (Exception ex) { throw ex; } return(currentFrame); }
/* Handles the event related to an image having been taken and waiting for processing. */ private void OnImageReadyEventCallback() { if (Display.FindForm().InvokeRequired) { /* If called from a different thread, we must use the Invoke method to marshal the call to the proper thread. */ Display.FindForm().BeginInvoke(new ImageProvider.ImageReadyEventHandler(OnImageReadyEventCallback)); return; } try { /* Acquire the image from the image provider. Only show the latest image. The camera may acquire images faster than images can be displayed*/ ImageProvider.Image image = Base.GetLatestImage(); /* Check if the image has been removed in the meantime. */ if (image != null) { /* Check if the image is compatible with the currently used bitmap. */ if (BitmapFactory.IsCompatible(m_bitmap, image.Width, image.Height, image.Color)) { /* Update the bitmap with the image data. */ BitmapFactory.UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); /* To show the new image, request the display control to update itself. */ if (Display.InvokeRequired) { Display.Invoke(new Action(() => { Display.Refresh(); })); } else { Display.Refresh(); } } else /* A new bitmap is required. */ { BitmapFactory.CreateBitmap(out m_bitmap, image.Width, image.Height, image.Color); BitmapFactory.UpdateBitmap(m_bitmap, image.Buffer, image.Width, image.Height, image.Color); Bitmap bitmap; if (Display.InvokeRequired) { Display.Invoke(new Action(() => { /* We have to dispose the bitmap after assigning the new one to the display control. */ bitmap = Display.BackgroundImage as Bitmap; /* Provide the display control with the new bitmap. This action automatically updates the display. */ Display.BackgroundImage = m_bitmap; if (bitmap != null) { /* Dispose the bitmap. */ bitmap.Dispose(); } })); } else { /* We have to dispose the bitmap after assigning the new one to the display control. */ bitmap = Display.BackgroundImage as Bitmap; /* Provide the display control with the new bitmap. This action automatically updates the display. */ Display.BackgroundImage = m_bitmap; if (bitmap != null) { /* Dispose the bitmap. */ bitmap.Dispose(); } } } /* The processing of the image is done. Release the image buffer. */ Base.ReleaseImage(); /* The buffer can be used for the next image grabs. */ } GetInputImage(image); InputImageUpData?.Invoke(this, EventArgs.Empty); } catch (Exception ex) { StackFrame[] stackFrames = new StackTrace(true).GetFrames(); clsLogFile.LogTryCatch(stackFrames, ex.Message + GetBaslerException(), true, true); } }
/* Handles the event related to an image having been taken and waiting for processing. */ private void OnImageReadyEventCallback() { if (InvokeRequired) { /* If called from a different thread, we must use the Invoke method to marshal the call to the proper thread. */ BeginInvoke(new ImageProvider.ImageReadyEventHandler(OnImageReadyEventCallback)); return; } try { /* Acquire the image from the image provider. Only show the latest image. The camera may acquire images faster than images can be displayed*/ ImageProvider.Image image = m_imageProvider.GetCurrentImage(); // m_imageProvider.GetLatestImage(); /* Check if the image has been removed in the meantime. */ if (image != null) { try { /* Display image */ //Pylon.ImageWindowDisplayImage<Byte>(0, image.Buffer, grabResult); //System.Object lockThis = new System.Object(); //lock (lockThis) // { //img_dmk は使わず、直接imgdata.imgにコピー Marshal.Copy(image.Buffer, 0, imgdata.img.ImageDataOrigin, image.Buffer.Length); // } /* The processing of the image is done. Release the image buffer. */ m_imageProvider.ReleaseImage(); /* The buffer can be used for the next image grabs. */ } catch (KeyNotFoundException) { MessageBox.Show("KeyNotFoundException:20"); } try { // 表示画像反転 実装場所 要検討 if (appSettings.Flipmode == OpenCvSharp.FlipMode.X || appSettings.Flipmode == OpenCvSharp.FlipMode.Y) { Cv.Flip(imgdata.img, imgdata.img, appSettings.Flipmode); } detect(); } catch (KeyNotFoundException) { MessageBox.Show("KeyNotFoundException:21"); } try{ detect(); imgdata_push_FIFO(); } catch (KeyNotFoundException) { MessageBox.Show("KeyNotFoundException:22"); } } } catch (Exception e) { ShowException(e, m_imageProvider.GetLastErrorMessage()); } }
/// <summary> /// Handles buffer updating from Managed Camera. /// </summary> public void HandleBufferUpdate(ImageProvider imageProvider) { image = imageProvider.GetLatestImage(); var ImageObject = _buffer [_bufferIndex]; if (image != null) { if (BitmapFactory.IsCompatible(ImageObject, image.Width, image.Height, image.Color)) { BitmapFactory.UpdateBitmap(ImageObject, image.Buffer, image.Width, image.Height, image.Color); } else { BitmapFactory.CreateBitmap(out Bitmap b, image.Width, image.Height, image.Color); BitmapFactory.UpdateBitmap(b, image.Buffer, image.Width, image.Height, image.Color); _buffer [_bufferIndex] = b; /*BitmapFactory.CreateBitmap (out Bitmap bitmap, image.Width, image.Height, image.Color); * BitmapFactory.UpdateBitmap (bitmap, image.Buffer, image.Width, image.Height, image.Color); */ //pictureBox.InvokeSet (bitmap); } _bufferIndex++; if (_bufferIndex >= _buffer.Length) { _bufferIndex = 0; } imageProvider.ReleaseImage(); // First check for preview saving, then call the function because: // Function increases the FPS Counter for next calls. if (!onPreviewSaving) { if (master.ShouldDrawOnBufferUpdate()) { var pictureIndex = _bufferIndex - 1; if (pictureIndex < 0) { pictureIndex = _buffer.Length - 1; } DrawPreviewImage(_buffer [pictureIndex]); } } /*if (FpsLimit > 1 && !project.Started && !onPreviewSaving) { * * fpsCounter++; * * if (fpsCounter >= FpsLimit) { * * OnPreviewImageReadyHandler (); * * fpsCounter = 0; * * } * } * else if (FpsLimit > 0 && !project.Started && !onPreviewSaving) { * * OnPreviewImageReadyHandler (); * * }*/ } }