C++ Halcon识别条形码示例

//初始化模型
CreateBarCodeModel(HTuple(), HTuple(), &hv_BarCodeHandle);
//设置最小对象面积大小
SetBarCodeParam(hv_BarCodeHandle, "element_size_min", 3200);
//设置校验开启
SetBarCodeParam(hv_BarCodeHandle, "check_char", "present");
//设置只识别一个
SetBarCodeParam(hv_BarCodeHandle, "stop_after_result_num", 1);
// Local iconic variables
HObject  ho_Image, ho_SymbolRegions;

// Local control variables
HTuple  hv_DecodedDataStrings;
HTuple code_Types;

code_Types[0] = "Code 128";
code_Types[1] = "Code 39";
FindBarCode(ho_Image, &ho_SymbolRegions, hv_BarCodeHandle, code_Types, &hv_DecodedDataStrings);
long codeLen = hv_DecodedDataStrings.Length();
    if (codeLen >0) {
        for (int i = 0;i < codeLen;i++) {
            HString str = hv_DecodedDataStrings[i].S();
            char* code = const_cast<char*>(str.Text());
            //正则校验
            std::regex code_reg("^[1-9]\\d{10,14}$");
            bool ret = std::regex_match(code, code_reg);
            if (ret) {

                qDebug(u8"%s", code);

                break;
            }
        }
    }

 

posted @ 2020-10-28 10:29  sunyheart  阅读(893)  评论(0编辑  收藏  举报