HALCON 11例程1 25industrial.hdev

来源:互联网 发布:房地产数据 知乎 编辑:程序博客网 时间:2024/05/19 02:21

* Read bar codes of type 2/5 Industrial                   //条形码的读取* create_bar_code_model ([], [], BarCodeHandle)   //建立一个读取条形码的句柄模型,后续对条形码的一切处理都是基于此。dev_close_window ()                        //关闭当前活跃的窗口dev_open_window (0, 0, 120, 300, 'black', WindowHandle)  //打开一个起点为(0,0),宽和高分别为120和300且背景为黑色句柄为WindowHandle。set_display_font (WindowHandle, 14, 'mono', 'true', 'false')  //显示字体的设置dev_set_draw ('margin')   //设置感兴趣区域的显示方式,margin为边缘显示,fill为填充。dev_set_line_width (3)    //线宽3号for I := 1 to 4 by 1        //for循环,意在共四张条形码图像待处理    read_image (Image, 'barcode/25industrial/25industrial0' + I) //从路径中读取条形码图像,赋予Image    get_image_size (Image, Width, Height)    //得到图像宽度与高度信息    dev_set_window_extents (0, 0, Width - 1, Height - 1)  //将显示窗口设置与图像等大小。    dev_display (Image)     //显示图像    dev_set_color ('green')   //设置外部输出颜色    * Read bar code, the resulting string includes the check character   set_bar_code_param (BarCodeHandle, 'check_char', 'absent')   //设置条形码读取算方法    这其中包括条形码字数大小,扫描方式,条形码种类设置,训练方法的设置,本函数中    使用 'check_char'且设置为'absent',我的理解为识别完条形码之后不再检测其正确性。    find_bar_code (Image, SymbolRegions, BarCodeHandle, '2/5 Industrial', DecodedDataStrings)        //根据建立的查找模型查找在图像Image中查找条形码,保存在DecodedDataStrings中。    disp_message (WindowHandle, DecodedDataStrings, 'window', 12, 12, 'black', 'false')//在窗口中显示检测到的条形码数值。    LastChar := strlen(DecodedDataStrings) – 1     //字符串长度-1    disp_message (WindowHandle, sum(gen_tuple_const(LastChar,' ')) + DecodedDataStrings{LastChar}, 'window', 12, 12, 'forest green', 'false') //将最后一位数值显示为绿色。    stop ()    * Read bar code using the check character to check the result, i.e.,    * the check character does not belong to the returned string anymore.    * If the check character is not correct, the bar code reading fails    dev_set_color ('green')  //设置显示颜色    set_bar_code_param (BarCodeHandle, 'check_char', 'present')  //设置条形码模型,'present'为检定条形码检测的正确性,    find_bar_code (Image, SymbolRegions, BarCodeHandle, '2/5 Industrial', DecodedDataStrings)   //扫描得到条形码数值,并保存于DecodedDataStrings中。    disp_message (WindowHandle, DecodedDataStrings, 'window', 36, 12, 'black', 'false')//显示    dev_set_color ('magenta')  //设置显示颜色为品红色。    if (I < 4)        stop ()    endifendforclear_bar_code_model (BarCodeHandle)  //清除所建立的条形码模型。


例程运行结果截图:



0 0
原创粉丝点击