Halcon相机硬触发采集图片

 1         public static void Start()
 2         {
 3             Thread thdGrab = new Thread(new ThreadStart(GrabImage));
 4             thdGrab.IsBackground = true;
 5             thdGrab.Start();
 6             Thread thdCal = new Thread(new ThreadStart(Process));
 7             thdCal.IsBackground = true;
 8             thdCal.Start();
 9         }
10         private static void GrabImage()
11         {
12             HImage _imageA = new HImage();
13             HImage _imageB = new HImage();
14             HObject hv_objectA = null;
15             HObject hv_objectB = null;
16             HOperatorSet.GrabImageStart(hv_AcqHandle_A, -1);
17             HOperatorSet.GrabImageStart(hv_AcqHandle_B, -1);
18             //Run acquisition loop.
19             while (cAuto.bStart)
20             {
21                 Thread.Sleep(10);
22                 try
23                 {
24                     HOperatorSet.GrabImageAsync(out hv_objectA, hv_AcqHandle_A, -1.0);
25                     HOperatorSet.GrabImageAsync(out hv_objectB, hv_AcqHandle_B, -1.0);
26                     if (hv_objectA != null && hv_objectB != null)//采集OK
27                     {
28                         cAuto.UpdateGUI((int)cAuto.UpdateItem.Log_Info, "Camera_A,Camera_B grab image OK...");
29                         HObjectToHImage(hv_objectA, ref _imageA);
30                         HObjectToHImage(hv_objectB, ref _imageB);
31                         hv_objectA = null;
32                         hv_objectB = null;
33                         List<HImage> lstImgs = new List<HImage>();
34                         lstImgs.Add(_imageA.Clone());
35                         lstImgs.Add(_imageB.Clone());
36                         EnqueueImage(lstImgs);//入队列
37                     }
38                 }
39                 catch(Exception ex) //处理超时引发的异常
40                 {
41                     continue;
42                 }
43             }
44         }
45         private static void Process()
46         {
47             while(cAuto.bStart)
48             {
49                 Thread.Sleep(20);
50                 if (IsQueueImageEmpty()) { continue; }
51                 List<HImage> lstImage = DequeueImage(); //出队列
52                 //do something
         } 54 } 55 private static void HObjectToHImage(HObject obj, ref HImage img) 56 { 57 HTuple pointer, type, width, heght; 58 HOperatorSet.GetImagePointer1(obj, out pointer, out type, out width, out heght); 59 img.GenImage1(type, width, heght, pointer); 60 } 61

 

posted @ 2018-07-04 13:20  summer91  阅读(4968)  评论(0编辑  收藏  举报