Halcon二維碼識別(創建-訓練-識別-清除)

**********************初階,創建-識別-清除***************************

create_data_code_2d_model ('QR Code', [], [], DataCodeHandle)

read_image(Image1,'C:/Users/研發/Pictures/Saved Pictures/二維碼/123456.PNG')

find_data_code_2d(Image1, SymbolXLDs1, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)

clear_data_code_2d_model (DataCodeHandle)



***********************進階,創建-訓練-識別-清除**********************

*訓練二維碼,只需將find_data_code_2d_model中的參數設爲train、all

Path:='D:\\IPI\\Halcon12Projects\\二維碼訓練模板.dcm'

*創建

create_data_code_2d_model ('QR Code', [], [], DataCodeHandle)

list_files ('D:/2dcode', 'files', Files)

for Index:=0 to |Files|-1 by 1

    read_image (Image, Files[Index])

    *訓練

    find_data_code_2d (Image,SymbolXLDs,DataCodeHandle,'train','all', ResultHandles, DecodedDataStrings)

endfor

*寫入本地

write_data_code_2d_model(DataCodeHandle,Path)




*使用訓練的模板進行識別,若識別失敗,則進行訓練當前圖像(若訓練後識別成功,則將訓練後的句柄寫入)

file_exists(Path, FileExists)

if(FileExists=1)

    *讀取本地

    read_data_code_2d_model (Path, DataCodeHandle)    

    list_files ('D:/2dcode', 'files', Files)

    for Index:=0 to |Files|-1 by 1

        read_image (Image, Files[Index])

        *使用訓練的句柄識別

        find_data_code_2d(Image, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)

        count_obj(SymbolXLDs, Number)

        *判斷圍繞二維碼的輪廓是否小於1

        if(Number<1)

            find_data_code_2d (Image,SymbolXLDs,DataCodeHandle,'train','all', ResultHandles, DecodedDataStrings)

            count_obj(SymbolXLDs,Number)

            if(Number>0)

                write_data_code_2d_model (DataCodeHandle,Path)

            endif

        endif

        if(Number<1)

            disp_message(3600,'NG', 'window', 12, 12, 'black', 'true')

        else

            disp_message(3600,'OK\r\n'+DecodedDataStrings, 'window', 12, 12, 'black', 'true')

            dev_display (SymbolXLDs)

        endif

    endfor

    write_data_code_2d_model (DataCodeHandle,Path)

else

    stop()

endif

*清除句柄,釋放內存

clear_data_code_2d_model (DataCodeHandle)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章