[Halcon] Barcode 讀取 (1)
Halcon是一家德國提供影像處理軟體的公司,有提供許多運算元可以讓使用者直接就可以對影像或CCD進行操作。
下面是要介紹Halcon裡面和Barcode相關的簡易運算元:
1. create_bar_code_model( : : GenParamNames, GenParamValues : BarCodeHandle)
用於建立一個Barcode模組,以供檢查或設定Barcode的運算元(find_bar_code...等)來使用。
2. find_bar_code(Image : SymbolRegions : BarCodeHandle, : DecodedDataStrings)
在一張影像中偵測並讀取Barcode的訊號值。利用給予的影像物件(Image)、指定的編碼型態(CodeType)、指定的Barcode模組(BarCodeHandle)來取得並輸出判斷的結果回傳Barcode所在的範圍位置(SymbolRegions)跟解碼後的資料字串(DecodedDataStrings)。
底下是從Halcon範例中擷取的一小段code:
//為讀取Barcode創建一模組BarCodeHandle,前頭兩個參數可以用來添加此模組的參數。
create_bar_code_model ([], [], BarCodeHandle)
read_image (Image, 'barcode/code39/code39'+(I$'.2'))
//用於設定模組的參數,為了更能適應目前影像上的Barcode,此參數"element_size_max"、"element_size_mim"用於設定此模組尋找每一條bar或空格間最大、最小的寬度。若條碼很大張,則需要將 "element_size_max" 設大點。
set_bar_code_param (BarCodeHandle, 'element_size_max', 6)
//開始尋找條碼型態為Code 39的條碼,並將結果輸出至SymbolRegions、DecodedDataStrings中。
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'Code 39', DecodedDataStrings)
//tuple_ords將tuple字串轉換為ASCII碼的tuple
//tuple_length將ASCII碼的tuple長度取出到Length,可知道LenOfString中共有幾個字元。
//若用tuple_length( DecodedDataStrings , Length)則Length可知道,DecodedDataStrings中共有幾個字串。
tuple_ords (DecodedDataStrings, LenOfString)
tuple_length (LenOfString, Length)
若字元或是字串個數為0則代表,並沒有找到相關的Barcode資訊唷!
//完成後可利用此來清除使用中的資源
clear_bar_code_model (BarCodeHandle)
參考:
Halcon官網:http://www.mvtec.com/halcon/
下面是要介紹Halcon裡面和Barcode相關的簡易運算元:
1. create_bar_code_model( : : GenParamNames, GenParamValues : BarCodeHandle)
用於建立一個Barcode模組,以供檢查或設定Barcode的運算元(find_bar_code...等)來使用。
2. find_bar_code(Image : SymbolRegions : BarCodeHandle, : DecodedDataStrings)
在一張影像中偵測並讀取Barcode的訊號值。利用給予的影像物件(Image)、指定的編碼型態(CodeType)、指定的Barcode模組(BarCodeHandle)來取得並輸出判斷的結果回傳Barcode所在的範圍位置(SymbolRegions)跟解碼後的資料字串(DecodedDataStrings)。
底下是從Halcon範例中擷取的一小段code:
//為讀取Barcode創建一模組BarCodeHandle,前頭兩個參數可以用來添加此模組的參數。
create_bar_code_model ([], [], BarCodeHandle)
read_image (Image, 'barcode/code39/code39'+(I$'.2'))
//用於設定模組的參數,為了更能適應目前影像上的Barcode,此參數"element_size_max"、"element_size_mim"用於設定此模組尋找每一條bar或空格間最大、最小的寬度。若條碼很大張,則需要將 "element_size_max" 設大點。
set_bar_code_param (BarCodeHandle, 'element_size_max', 6)
//開始尋找條碼型態為Code 39的條碼,並將結果輸出至SymbolRegions、DecodedDataStrings中。
find_bar_code (Image, SymbolRegions, BarCodeHandle, 'Code 39', DecodedDataStrings)
//tuple_ords將tuple字串轉換為ASCII碼的tuple
//tuple_length將ASCII碼的tuple長度取出到Length,可知道LenOfString中共有幾個字元。
//若用tuple_length( DecodedDataStrings , Length)則Length可知道,DecodedDataStrings中共有幾個字串。
tuple_ords (DecodedDataStrings, LenOfString)
tuple_length (LenOfString, Length)
若字元或是字串個數為0則代表,並沒有找到相關的Barcode資訊唷!
//完成後可利用此來清除使用中的資源
clear_bar_code_model (BarCodeHandle)
參考:
Halcon官網:http://www.mvtec.com/halcon/