软硬件平台搭建

系统:X64—win64

界面:VS2010 C#

视觉库:Halcon 11.0.2 

光源、镜头、 相机、采集、试验架、标定板。。。(先凑合着用)

Halcon测试程序:

**[1] USB2.0 UVC PC Camera
open_framegrabber ('DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'gray', -1, 'false', 'default', '[1] USB2.0 UVC PC Camera', 0, -1, AcqHandle)
grab_image_start (AcqHandle, -1)
Index:=0
for Index := 1 to 5 by 1
    grab_image_async (Image, AcqHandle, -1)
    dev_display (Image)
    get_image_size (Image, Width, Height)
    set_display_font (3600, 20, 'mono', 'true', 'false')
    disp_message (3600, ['帧:'+Index, 'Width:'+Width, 'Height:'+Height], 'window', 12, 12, 'green', 'true')
endfor
close_framegrabber (AcqHandle)

 C#测试程序:

  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Windows.Forms;
  9 using HalconDotNet;
 10 namespace grab_one
 11 {
 12     public partial class Form1 : Form
 13     {
 14         public Form1()
 15         {
 16             InitializeComponent();
 17         }
 18 
 19         private void button1_Click(object sender, EventArgs e)
 20         {
 21             HDevelopExport HD = new HDevelopExport();
 22             HD.InitHalcon();
 23             HD.RunHalcon(hWindowControl1.HalconWindow);
 24         }
 25 
 26         private void button2_Click(object sender, EventArgs e)
 27         {
 28             Application.Exit();
 29         }
 30     }
 31     public partial class HDevelopExport
 32     {
 33         public HTuple hv_ExpDefaultWinHandle;
 34 
 35         // Procedures 
 36         // External procedures 
 37         // Chapter: Graphics / Text
 38         // Short Description: This procedure writes a text message. 
 39         public void disp_message(HTuple hv_WindowHandle, HTuple hv_String, HTuple hv_CoordSystem,
 40             HTuple hv_Row, HTuple hv_Column, HTuple hv_Color, HTuple hv_Box)
 41         {
 42 
 43 
 44             // Local control variables 
 45 
 46             HTuple hv_Red = null, hv_Green = null, hv_Blue = null;
 47             HTuple hv_Row1Part = null, hv_Column1Part = null, hv_Row2Part = null;
 48             HTuple hv_Column2Part = null, hv_RowWin = null, hv_ColumnWin = null;
 49             HTuple hv_WidthWin = new HTuple(), hv_HeightWin = null;
 50             HTuple hv_MaxAscent = null, hv_MaxDescent = null, hv_MaxWidth = null;
 51             HTuple hv_MaxHeight = null, hv_R1 = new HTuple(), hv_C1 = new HTuple();
 52             HTuple hv_FactorRow = new HTuple(), hv_FactorColumn = new HTuple();
 53             HTuple hv_Width = new HTuple(), hv_Index = new HTuple();
 54             HTuple hv_Ascent = new HTuple(), hv_Descent = new HTuple();
 55             HTuple hv_W = new HTuple(), hv_H = new HTuple(), hv_FrameHeight = new HTuple();
 56             HTuple hv_FrameWidth = new HTuple(), hv_R2 = new HTuple();
 57             HTuple hv_C2 = new HTuple(), hv_DrawMode = new HTuple();
 58             HTuple hv_Exception = new HTuple(), hv_CurrentColor = new HTuple();
 59 
 60             HTuple hv_Color_COPY_INP_TMP = hv_Color.Clone();
 61             HTuple hv_Column_COPY_INP_TMP = hv_Column.Clone();
 62             HTuple hv_Row_COPY_INP_TMP = hv_Row.Clone();
 63             HTuple hv_String_COPY_INP_TMP = hv_String.Clone();
 64 
 65             // Initialize local and output iconic variables 
 66 
 67             //This procedure displays text in a graphics window.
 68             //
 69             //Input parameters:
 70             //WindowHandle: The WindowHandle of the graphics window, where
 71             //   the message should be displayed
 72             //String: A tuple of strings containing the text message to be displayed
 73             //CoordSystem: If set to 'window', the text position is given
 74             //   with respect to the window coordinate system.
 75             //   If set to 'image', image coordinates are used.
 76             //   (This may be useful in zoomed images.)
 77             //Row: The row coordinate of the desired text position
 78             //   If set to -1, a default value of 12 is used.
 79             //Column: The column coordinate of the desired text position
 80             //   If set to -1, a default value of 12 is used.
 81             //Color: defines the color of the text as string.
 82             //   If set to [], '' or 'auto' the currently set color is used.
 83             //   If a tuple of strings is passed, the colors are used cyclically
 84             //   for each new textline.
 85             //Box: If set to 'true', the text is written within a white box.
 86             //
 87             //prepare window
 88             HOperatorSet.GetRgb(hv_ExpDefaultWinHandle, out hv_Red, out hv_Green, out hv_Blue);
 89             HOperatorSet.GetPart(hv_ExpDefaultWinHandle, out hv_Row1Part, out hv_Column1Part,
 90                 out hv_Row2Part, out hv_Column2Part);
 91             HOperatorSet.GetWindowExtents(hv_ExpDefaultWinHandle, out hv_RowWin, out hv_ColumnWin,
 92                 out hv_WidthWin, out hv_HeightWin);
 93             HOperatorSet.SetPart(hv_ExpDefaultWinHandle, 0, 0, hv_HeightWin - 1, hv_WidthWin - 1);
 94             //
 95             //default settings
 96             if ((int)(new HTuple(hv_Row_COPY_INP_TMP.TupleEqual(-1))) != 0)
 97             {
 98                 hv_Row_COPY_INP_TMP = 12;
 99             }
100             if ((int)(new HTuple(hv_Column_COPY_INP_TMP.TupleEqual(-1))) != 0)
101             {
102                 hv_Column_COPY_INP_TMP = 12;
103             }
104             if ((int)(new HTuple(hv_Color_COPY_INP_TMP.TupleEqual(new HTuple()))) != 0)
105             {
106                 hv_Color_COPY_INP_TMP = "";
107             }
108             //
109             hv_String_COPY_INP_TMP = ((("" + hv_String_COPY_INP_TMP) + "")).TupleSplit("\n");
110             //
111             //Estimate extentions of text depending on font size.
112             HOperatorSet.GetFontExtents(hv_ExpDefaultWinHandle, out hv_MaxAscent, out hv_MaxDescent,
113                 out hv_MaxWidth, out hv_MaxHeight);
114             if ((int)(new HTuple(hv_CoordSystem.TupleEqual("window"))) != 0)
115             {
116                 hv_R1 = hv_Row_COPY_INP_TMP.Clone();
117                 hv_C1 = hv_Column_COPY_INP_TMP.Clone();
118             }
119             else
120             {
121                 //transform image to window coordinates
122                 hv_FactorRow = (1.0 * hv_HeightWin) / ((hv_Row2Part - hv_Row1Part) + 1);
123                 hv_FactorColumn = (1.0 * hv_WidthWin) / ((hv_Column2Part - hv_Column1Part) + 1);
124                 hv_R1 = ((hv_Row_COPY_INP_TMP - hv_Row1Part) + 0.5) * hv_FactorRow;
125                 hv_C1 = ((hv_Column_COPY_INP_TMP - hv_Column1Part) + 0.5) * hv_FactorColumn;
126             }
127             //
128             //display text box depending on text size
129             if ((int)(new HTuple(hv_Box.TupleEqual("true"))) != 0)
130             {
131                 //calculate box extents
132                 hv_String_COPY_INP_TMP = (" " + hv_String_COPY_INP_TMP) + " ";
133                 hv_Width = new HTuple();
134                 for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_String_COPY_INP_TMP.TupleLength()
135                     )) - 1); hv_Index = (int)hv_Index + 1)
136                 {
137                     HOperatorSet.GetStringExtents(hv_ExpDefaultWinHandle, hv_String_COPY_INP_TMP.TupleSelect(
138                         hv_Index), out hv_Ascent, out hv_Descent, out hv_W, out hv_H);
139                     hv_Width = hv_Width.TupleConcat(hv_W);
140                 }
141                 hv_FrameHeight = hv_MaxHeight * (new HTuple(hv_String_COPY_INP_TMP.TupleLength()
142                     ));
143                 hv_FrameWidth = (((new HTuple(0)).TupleConcat(hv_Width))).TupleMax();
144                 hv_R2 = hv_R1 + hv_FrameHeight;
145                 hv_C2 = hv_C1 + hv_FrameWidth;
146                 //display rectangles
147                 HOperatorSet.GetDraw(hv_ExpDefaultWinHandle, out hv_DrawMode);
148                 HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, "fill");
149                 HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "light gray");
150                 HOperatorSet.DispRectangle1(hv_ExpDefaultWinHandle, hv_R1 + 3, hv_C1 + 3, hv_R2 + 3,
151                     hv_C2 + 3);
152                 HOperatorSet.SetColor(hv_ExpDefaultWinHandle, "white");
153                 HOperatorSet.DispRectangle1(hv_ExpDefaultWinHandle, hv_R1, hv_C1, hv_R2, hv_C2);
154                 HOperatorSet.SetDraw(hv_ExpDefaultWinHandle, hv_DrawMode);
155             }
156             else if ((int)(new HTuple(hv_Box.TupleNotEqual("false"))) != 0)
157             {
158                 hv_Exception = "Wrong value of control parameter Box";
159                 throw new HalconException(hv_Exception);
160             }
161             //Write text.
162             for (hv_Index = 0; (int)hv_Index <= (int)((new HTuple(hv_String_COPY_INP_TMP.TupleLength()
163                 )) - 1); hv_Index = (int)hv_Index + 1)
164             {
165                 hv_CurrentColor = hv_Color_COPY_INP_TMP.TupleSelect(hv_Index % (new HTuple(hv_Color_COPY_INP_TMP.TupleLength()
166                     )));
167                 if ((int)((new HTuple(hv_CurrentColor.TupleNotEqual(""))).TupleAnd(new HTuple(hv_CurrentColor.TupleNotEqual(
168                     "auto")))) != 0)
169                 {
170                     HOperatorSet.SetColor(hv_ExpDefaultWinHandle, hv_CurrentColor);
171                 }
172                 else
173                 {
174                     HOperatorSet.SetRgb(hv_ExpDefaultWinHandle, hv_Red, hv_Green, hv_Blue);
175                 }
176                 hv_Row_COPY_INP_TMP = hv_R1 + (hv_MaxHeight * hv_Index);
177                 HOperatorSet.SetTposition(hv_ExpDefaultWinHandle, hv_Row_COPY_INP_TMP, hv_C1);
178                 HOperatorSet.WriteString(hv_ExpDefaultWinHandle, hv_String_COPY_INP_TMP.TupleSelect(
179                     hv_Index));
180             }
181             //reset changed window settings
182             HOperatorSet.SetRgb(hv_ExpDefaultWinHandle, hv_Red, hv_Green, hv_Blue);
183             HOperatorSet.SetPart(hv_ExpDefaultWinHandle, hv_Row1Part, hv_Column1Part, hv_Row2Part,
184                 hv_Column2Part);
185 
186             return;
187         }
188 
189         // Chapter: Graphics / Text
190         // Short Description: Set font independent of OS 
191         public void set_display_font(HTuple hv_WindowHandle, HTuple hv_Size, HTuple hv_Font,
192             HTuple hv_Bold, HTuple hv_Slant)
193         {
194 
195 
196             // Local control variables 
197 
198             HTuple hv_OS = null, hv_Exception = new HTuple();
199             HTuple hv_BoldString = new HTuple(), hv_SlantString = new HTuple();
200             HTuple hv_AllowedFontSizes = new HTuple(), hv_Distances = new HTuple();
201             HTuple hv_Indices = new HTuple(), hv_Fonts = new HTuple();
202             HTuple hv_FontSelRegexp = new HTuple(), hv_FontsCourier = new HTuple();
203 
204             HTuple hv_Bold_COPY_INP_TMP = hv_Bold.Clone();
205             HTuple hv_Font_COPY_INP_TMP = hv_Font.Clone();
206             HTuple hv_Size_COPY_INP_TMP = hv_Size.Clone();
207             HTuple hv_Slant_COPY_INP_TMP = hv_Slant.Clone();
208 
209             // Initialize local and output iconic variables 
210 
211             //This procedure sets the text font of the current window with
212             //the specified attributes.
213             //It is assumed that following fonts are installed on the system:
214             //Windows: Courier New, Arial Times New Roman
215             //Mac OS X: CourierNewPS, Arial, TimesNewRomanPS
216             //Linux: courier, helvetica, times
217             //Because fonts are displayed smaller on Linux than on Windows,
218             //a scaling factor of 1.25 is used the get comparable results.
219             //For Linux, only a limited number of font sizes is supported,
220             //to get comparable results, it is recommended to use one of the
221             //following sizes: 9, 11, 14, 16, 20, 27
222             //(which will be mapped internally on Linux systems to 11, 14, 17, 20, 25, 34)
223             //
224             //Input parameters:
225             //WindowHandle: The graphics window for which the font will be set
226             //Size: The font size. If Size=-1, the default of 16 is used.
227             //Bold: If set to 'true', a bold font is used
228             //Slant: If set to 'true', a slanted font is used
229             //
230             HOperatorSet.GetSystem("operating_system", out hv_OS);
231             // dev_get_preferences(...); only in hdevelop
232             // dev_set_preferences(...); only in hdevelop
233             if ((int)((new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(new HTuple()))).TupleOr(
234                 new HTuple(hv_Size_COPY_INP_TMP.TupleEqual(-1)))) != 0)
235             {
236                 hv_Size_COPY_INP_TMP = 16;
237             }
238             if ((int)(new HTuple(((hv_OS.TupleSubstr(0, 2))).TupleEqual("Win"))) != 0)
239             {
240                 //Set font on Windows systems
241                 if ((int)((new HTuple((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))).TupleOr(
242                     new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("Courier"))))).TupleOr(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual(
243                     "courier")))) != 0)
244                 {
245                     hv_Font_COPY_INP_TMP = "Courier New";
246                 }
247                 else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0)
248                 {
249                     hv_Font_COPY_INP_TMP = "Arial";
250                 }
251                 else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0)
252                 {
253                     hv_Font_COPY_INP_TMP = "Times New Roman";
254                 }
255                 if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0)
256                 {
257                     hv_Bold_COPY_INP_TMP = 1;
258                 }
259                 else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("false"))) != 0)
260                 {
261                     hv_Bold_COPY_INP_TMP = 0;
262                 }
263                 else
264                 {
265                     hv_Exception = "Wrong value of control parameter Bold";
266                     throw new HalconException(hv_Exception);
267                 }
268                 if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0)
269                 {
270                     hv_Slant_COPY_INP_TMP = 1;
271                 }
272                 else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("false"))) != 0)
273                 {
274                     hv_Slant_COPY_INP_TMP = 0;
275                 }
276                 else
277                 {
278                     hv_Exception = "Wrong value of control parameter Slant";
279                     throw new HalconException(hv_Exception);
280                 }
281                 try
282                 {
283                     HOperatorSet.SetFont(hv_ExpDefaultWinHandle, ((((((("-" + hv_Font_COPY_INP_TMP) + "-") + hv_Size_COPY_INP_TMP) + "-*-") + hv_Slant_COPY_INP_TMP) + "-*-*-") + hv_Bold_COPY_INP_TMP) + "-");
284                 }
285                 // catch (Exception) 
286                 catch (HalconException HDevExpDefaultException1)
287                 {
288                     HDevExpDefaultException1.ToHTuple(out hv_Exception);
289                     //throw (Exception)
290                 }
291             }
292             else if ((int)(new HTuple(((hv_OS.TupleSubstr(0, 2))).TupleEqual("Dar"))) != 0)
293             {
294                 //Set font on Mac OS X systems
295                 if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0)
296                 {
297                     hv_BoldString = "Bold";
298                 }
299                 else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("false"))) != 0)
300                 {
301                     hv_BoldString = "";
302                 }
303                 else
304                 {
305                     hv_Exception = "Wrong value of control parameter Bold";
306                     throw new HalconException(hv_Exception);
307                 }
308                 if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0)
309                 {
310                     hv_SlantString = "Italic";
311                 }
312                 else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("false"))) != 0)
313                 {
314                     hv_SlantString = "";
315                 }
316                 else
317                 {
318                     hv_Exception = "Wrong value of control parameter Slant";
319                     throw new HalconException(hv_Exception);
320                 }
321                 if ((int)((new HTuple((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))).TupleOr(
322                     new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("Courier"))))).TupleOr(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual(
323                     "courier")))) != 0)
324                 {
325                     hv_Font_COPY_INP_TMP = "CourierNewPS";
326                 }
327                 else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0)
328                 {
329                     hv_Font_COPY_INP_TMP = "Arial";
330                 }
331                 else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0)
332                 {
333                     hv_Font_COPY_INP_TMP = "TimesNewRomanPS";
334                 }
335                 if ((int)((new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))).TupleOr(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual(
336                     "true")))) != 0)
337                 {
338                     hv_Font_COPY_INP_TMP = ((hv_Font_COPY_INP_TMP + "-") + hv_BoldString) + hv_SlantString;
339                 }
340                 hv_Font_COPY_INP_TMP = hv_Font_COPY_INP_TMP + "MT";
341                 try
342                 {
343                     HOperatorSet.SetFont(hv_ExpDefaultWinHandle, (hv_Font_COPY_INP_TMP + "-") + hv_Size_COPY_INP_TMP);
344                 }
345                 // catch (Exception) 
346                 catch (HalconException HDevExpDefaultException1)
347                 {
348                     HDevExpDefaultException1.ToHTuple(out hv_Exception);
349                     //throw (Exception)
350                 }
351             }
352             else
353             {
354                 //Set font for UNIX systems
355                 hv_Size_COPY_INP_TMP = hv_Size_COPY_INP_TMP * 1.25;
356                 hv_AllowedFontSizes = new HTuple();
357                 hv_AllowedFontSizes[0] = 11;
358                 hv_AllowedFontSizes[1] = 14;
359                 hv_AllowedFontSizes[2] = 17;
360                 hv_AllowedFontSizes[3] = 20;
361                 hv_AllowedFontSizes[4] = 25;
362                 hv_AllowedFontSizes[5] = 34;
363                 if ((int)(new HTuple(((hv_AllowedFontSizes.TupleFind(hv_Size_COPY_INP_TMP))).TupleEqual(
364                     -1))) != 0)
365                 {
366                     hv_Distances = ((hv_AllowedFontSizes - hv_Size_COPY_INP_TMP)).TupleAbs();
367                     HOperatorSet.TupleSortIndex(hv_Distances, out hv_Indices);
368                     hv_Size_COPY_INP_TMP = hv_AllowedFontSizes.TupleSelect(hv_Indices.TupleSelect(
369                         0));
370                 }
371                 if ((int)((new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("mono"))).TupleOr(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual(
372                     "Courier")))) != 0)
373                 {
374                     hv_Font_COPY_INP_TMP = "courier";
375                 }
376                 else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("sans"))) != 0)
377                 {
378                     hv_Font_COPY_INP_TMP = "helvetica";
379                 }
380                 else if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("serif"))) != 0)
381                 {
382                     hv_Font_COPY_INP_TMP = "times";
383                 }
384                 if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("true"))) != 0)
385                 {
386                     hv_Bold_COPY_INP_TMP = "bold";
387                 }
388                 else if ((int)(new HTuple(hv_Bold_COPY_INP_TMP.TupleEqual("false"))) != 0)
389                 {
390                     hv_Bold_COPY_INP_TMP = "medium";
391                 }
392                 else
393                 {
394                     hv_Exception = "Wrong value of control parameter Bold";
395                     throw new HalconException(hv_Exception);
396                 }
397                 if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("true"))) != 0)
398                 {
399                     if ((int)(new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("times"))) != 0)
400                     {
401                         hv_Slant_COPY_INP_TMP = "i";
402                     }
403                     else
404                     {
405                         hv_Slant_COPY_INP_TMP = "o";
406                     }
407                 }
408                 else if ((int)(new HTuple(hv_Slant_COPY_INP_TMP.TupleEqual("false"))) != 0)
409                 {
410                     hv_Slant_COPY_INP_TMP = "r";
411                 }
412                 else
413                 {
414                     hv_Exception = "Wrong value of control parameter Slant";
415                     throw new HalconException(hv_Exception);
416                 }
417                 try
418                 {
419                     HOperatorSet.SetFont(hv_ExpDefaultWinHandle, ((((((("-adobe-" + hv_Font_COPY_INP_TMP) + "-") + hv_Bold_COPY_INP_TMP) + "-") + hv_Slant_COPY_INP_TMP) + "-normal-*-") + hv_Size_COPY_INP_TMP) + "-*-*-*-*-*-*-*");
420                 }
421                 // catch (Exception) 
422                 catch (HalconException HDevExpDefaultException1)
423                 {
424                     HDevExpDefaultException1.ToHTuple(out hv_Exception);
425                     if ((int)((new HTuple(((hv_OS.TupleSubstr(0, 4))).TupleEqual("Linux"))).TupleAnd(
426                         new HTuple(hv_Font_COPY_INP_TMP.TupleEqual("courier")))) != 0)
427                     {
428                         HOperatorSet.QueryFont(hv_ExpDefaultWinHandle, out hv_Fonts);
429                         hv_FontSelRegexp = (("^-[^-]*-[^-]*[Cc]ourier[^-]*-" + hv_Bold_COPY_INP_TMP) + "-") + hv_Slant_COPY_INP_TMP;
430                         hv_FontsCourier = ((hv_Fonts.TupleRegexpSelect(hv_FontSelRegexp))).TupleRegexpMatch(
431                             hv_FontSelRegexp);
432                         if ((int)(new HTuple((new HTuple(hv_FontsCourier.TupleLength())).TupleEqual(
433                             0))) != 0)
434                         {
435                             hv_Exception = "Wrong font name";
436                             //throw (Exception)
437                         }
438                         else
439                         {
440                             try
441                             {
442                                 HOperatorSet.SetFont(hv_ExpDefaultWinHandle, (((hv_FontsCourier.TupleSelect(
443                                     0)) + "-normal-*-") + hv_Size_COPY_INP_TMP) + "-*-*-*-*-*-*-*");
444                             }
445                             // catch (Exception) 
446                             catch (HalconException HDevExpDefaultException2)
447                             {
448                                 HDevExpDefaultException2.ToHTuple(out hv_Exception);
449                                 //throw (Exception)
450                             }
451                         }
452                     }
453                     //throw (Exception)
454                 }
455             }
456             // dev_set_preferences(...); only in hdevelop
457 
458             return;
459         }
460 
461         // Main procedure 
462         private void action()
463         {
464             HObject ho_Image = null;
465 
466             HTuple hv_AcqHandle = null, hv_Index = null;
467             HTuple hv_Width = new HTuple(), hv_Height = new HTuple();
468 
469             HOperatorSet.GenEmptyObj(out ho_Image);
470             HOperatorSet.CloseAllFramegrabbers();
471                 HOperatorSet.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8,
472                     "rgb", -1, "false", "default", "[0] USB2.0 UVC PC Camera", 0, -1, out hv_AcqHandle);
473                 HOperatorSet.GrabImageStart(hv_AcqHandle, -1);
474                 hv_Index = 0;
475                 for (hv_Index = 1; (int)hv_Index <= 5; hv_Index = (int)hv_Index + 1)
476                 {
477                     ho_Image.Dispose();
478                     HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1);
479                     HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandle);
480                     HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
481                     set_display_font(hv_ExpDefaultWinHandle, 20, "mono", "true", "false");
482                     disp_message(hv_ExpDefaultWinHandle, (((("帧:" + hv_Index)).TupleConcat("Width:" + hv_Width))).TupleConcat(
483                         "Height:" + hv_Height), "window", 12, 12, "green", "true");
484                 }
485                 HOperatorSet.CloseFramegrabber(hv_AcqHandle);
486             ho_Image.Dispose();
487         }
488         public void InitHalcon()
489         {
490             HOperatorSet.SetSystem("width", 512);
491             HOperatorSet.SetSystem("height", 512);
492         }
493 
494         public void RunHalcon(HTuple Window)
495         {
496             hv_ExpDefaultWinHandle = Window;
497             action();
498         }
499 
500     }
501 }

转载于:https://www.cnblogs.com/RobotSky/p/3489942.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值