private void HandleHook(IntPtr hook, SetWinEventHookEventType eventType, IntPtr window, int objectId, int childId, uint threadId, uint time) { if (_disposed == false) { lock (_stateLock) { if (_started) { var eventArgs = new GrabbedEventArgs { EventType = eventType, Window = window, ObjectId = objectId, ChildId = childId, ThreadId = threadId, Time = time }; if (Grabbed != null) { Grabbed(this, eventArgs); } } } } }
/* 码流数据回调 */ private void OnImageGrabbedN(Object sender, GrabbedEventArgs e) { //_mutex.WaitOne(); //_frameList.Add(e.GrabResult.Clone()); //_mutex.ReleaseMutex(); OnImageGrabbed?.Invoke(e.GrabResult.Clone().ToBitmap(false)); }
private void Receiver(Object sender, GrabbedEventArgs e) { if (app.Run) { DateTime time_start = DateTime.Now;//計時開始 取得目前時間 Mat Src = new Mat(); Src.Create(e.GrabResult.Width, e.GrabResult.Height, MatType.CV_8UC1); Marshal.Copy(e.GrabResult.Image, 0, Src.Data, e.GrabResult.Image.Length); form1.Receiver(0, Src); #region 計算耗時 DateTime time_end = DateTime.Now;//計時結束 取得目前時間 string time_consuming = ((TimeSpan)(time_end - time_start)).TotalMilliseconds.ToString("0"); form1.UpdateTime(0, time_consuming); #endregion #region 清理資源 time_consuming = null; Src = null; GC.Collect(); #endregion } }
/// <summary> /// 相机取图写入注册表后回调事件 /// </summary> /// <param name="ptr"></param> public void OnImageGrabbed(Object sender, GrabbedEventArgs e) { try { if (_re.Acquire_Image == Acquire.Folder_Image) { MessageBox.Show("当前取图方式不是注册表取图,请先设置成注册表取图"); return; } _stopWatch.Restart(); HObject ho_Image; HOperatorSet.GenEmptyObj(out ho_Image); IntPtr ptr = Marshal.AllocHGlobal(Convert.ToInt32(_re._Width * _re._Height)); var frame = e.GrabResult; Marshal.Copy(frame.Image, 0, ptr, Convert.ToInt32(_re._Width * _re._Height)); HOperatorSet.GenImage1(out ho_Image, "byte", _re._Width, _re._Height, ptr); Marshal.FreeHGlobal(ptr); halconWinControl_11.HalconWindow1.DispObj(ho_Image); halconWinControl_11.Ho_Image.Dispose(); halconWinControl_11.Ho_Image = ho_Image; _stopWatch.Stop(); BeginInvoke(new Action(delegate { m_CtrlHStatusLabelCtrl.Text = _stopWatch.ElapsedMilliseconds.ToString(); _IDaHua.ResetCamerStream(); })); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// 码流数据回调 private void OnImageGrabbed(Object sender, GrabbedEventArgs e) { // 转换帧数据为Bitmap var bitmap = e.GrabResult.ToBitmap(false); /* * //转Bitmap图像为Emgucv图像,并进行二值化 * Image<Rgb, byte> original_img = new Image<Rgb, byte>( bitmap ); * var gray_img = original_img.Convert<Gray, Byte>(); * var threshold_img = original_img.Convert<Gray, Byte>(); * * CvInvoke.cvThreshold( gray_img, threshold_img, 20, 255, Emgu.CV.CvEnum.THRESH.CV_THRESH_BINARY); * * //转Emgucv图像为Bitmap图像 * var show_img = threshold_img.ToBitmap(); */ // 显示图片数据 if (InvokeRequired) { BeginInvoke(new MethodInvoker(() => { try { if (_g == null) { _g = pbImage.CreateGraphics(); } /* * _g.DrawImage( show_img, new Rectangle(0, 0, pbImage.Width, pbImage.Height), * new Rectangle(0, 0, show_img.Width, show_img.Height), GraphicsUnit.Pixel); * show_img.Dispose(); */ _g.DrawImage(bitmap, new Rectangle(0, 0, pbImage.Width, pbImage.Height), new Rectangle(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel); bitmap.Dispose(); //pbImage.Image = bitmap; } catch (Exception exception) { Catcher.Show(exception); } })); } }
//相机回流事件 private void OnImageGrabbed(object sender, GrabbedEventArgs e) { HObject image; try { HOperatorSet.GenImage1(out image, "byte", e.GrabResult.Width, e.GrabResult.Height, e.GrabResult.Raw); halconHelper.BarRecognition(image); m_dev.ExecuteSoftwareTrigger(); } catch (Exception ex) { ex.ToString(); } }
/* 码流数据回调 */ private void OnImageGrabbed(Object sender, GrabbedEventArgs e) { m_mutex.WaitOne(); m_frameList.Add(e.GrabResult.Clone()); m_mutex.ReleaseMutex(); }
private void HandleHook(IntPtr hook, SetWinEventHookEventType eventType, IntPtr window, int objectId, int childId, uint threadId, uint time) { if (disposed == false) { lock (stateLock) { if (started) { var eventArgs = new GrabbedEventArgs { EventType = eventType, Window = window, ObjectId = objectId, ChildId = childId, ThreadId = threadId, Time = time }; if (Grabbed != null) { Grabbed(this, eventArgs); } } } } }