*创建一个条形码阅读器的模型。
create_bar_code_model ([], [], BarCodeHandle)
*'element_size_min'条码最小尺寸(宽度和间距)指 黑条或者白条的最小尺寸像素是1.5像素
set_bar_code_param (BarCodeHandle, 'element_size_min', 1.5)
*
* Initialization
dev_update_off ()
dev_close_window ()
*
* Read and display example images without any visible bar codes
read_image (Image, 'barcode/25interleaved/25interleaved_zeiss1')
*
* Set display defaults
dev_open_window_fit_image (Image, 0, 0, 600, 500, WindowHandle)
dev_display (Image)
dev_set_draw ('margin')
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
*得到窗口的行列坐标以及宽和高
get_window_extents (WindowHandle, Row, Column, Width, Height)
dev_open_window (0, Width + 5, 400, 300, 'white', WindowHandleText)
set_display_font (WindowHandleText, 14, 'mono', 'true', 'false')
*
* Display information about the example
*显示提示信息
Message[0] := 'This example demonstrates the use of the bar code parameter \'contrast_min\'.'
Message[1] := ' '
Message[2] := 'The parameter \'contrast_min\' can be used to reduce the runtime of find_bar_code in the presence of low contrast bar-like structures in an image. Moreover \'contrast_min\' can also be used to reduce the number of false positives in applications where the expected barcodes have a high contrast.'
MessageWrapped := regexp_replace(Message + ' ',['(.{0,35})\\s','replace_all'],'$1\n')
*在另外一个窗口显示信息
disp_message (WindowHandleText, MessageWrapped, 'window', 12, 12, 'black', 'false')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*设置活动窗口----让窗口处于活动状态
dev_set_window (WindowHandle)
dev_clear_window ()
dev_display (Image)
*
* Number of repetitions for runtime measurements
*运行时测量的重复次数
NumRepeat := 100
*
* First, set the minimum contrast of the bar code candidate regions
* to 0 (default)
*首先,将条形码候选区域的最小对比度设置为0(默认值)ContrastMinValue := 0
set_bar_code_param (BarCodeHandle, 'contrast_min', ContrastMinValue)
*
* The bar code reader finds many bar code candidate regions that have
* a low absolute contrast
Times := []
for I := 0 to NumRepeat by 1count_seconds (Start)find_bar_code (Image, SymbolRegions, BarCodeHandle, 'auto', DecodedDataStrings)count_seconds (End)Time := End - StartTimes := [Times,Time]
endfor
RunTimeContrastMinLow := 1000 * median(Times)
* Get candidate regions and display results
*获取候选区域并显示结果get_bar_code_object (BarCodeObjects, BarCodeHandle, 'all', 'candidate_regions')
count_obj (BarCodeObjects, Number)
dev_set_color ('red')
dev_set_line_width (5)
dev_display (BarCodeObjects)*设置活动窗口为另外一个窗口
dev_set_window (WindowHandleText)
dev_clear_window ()
Message := ['\'contrast_min\' = ' + ContrastMinValue + ':',' Found ' + Number + ' candidate(s) in ' + (RunTimeContrastMinLow$'.4') + ' ms']
disp_message (WindowHandleText, Message, 'window', 12, 12, '', 'false')
*
* Now, set the bar code reader parameter 'contrast_min' to a value
* greater than 0.0 to consider only candidates having an absolute
* contrast of at least that value.*对比度增加 能把一些干扰项去除,能够最快最准的找到一些条码
ContrastMinValue := 120
set_bar_code_param (BarCodeHandle, 'contrast_min', ContrastMinValue)
*
* Search again for bar codes. Now, a significantly smaller number of
* candidates should be found, and the overall runtime should be reduced.
Times := []
for I := 0 to NumRepeat by 1count_seconds (Start)find_bar_code (Image, SymbolRegions, BarCodeHandle, 'auto', DecodedDataStrings)count_seconds (End)Time := End - StartTimes := [Times,Time]
endfor
RunTimeContrastMinHigh := 1000 * median(Times)
* Get candidate regions and display results
dev_set_window (WindowHandle)
get_bar_code_object (BarCodeObjects, BarCodeHandle, 'all', 'candidate_regions')
count_obj (BarCodeObjects, Number)
dev_set_color ('forest green')
dev_set_line_width (3)
dev_display (BarCodeObjects)
smallest_rectangle1 (SymbolRegions, Row1, Column1, Row2, Column2)
get_bar_code_result (BarCodeHandle, 'all', 'decoded_types', DecodedTypes)
disp_message (WindowHandle, DecodedTypes + '\n' + DecodedDataStrings, 'image', Row1, Column2 + 20, 'black', 'true')
dev_set_window (WindowHandleText)
Message := ['\'contrast_min\' = ' + ContrastMinValue + ':',' Found ' + Number + ' candidate(s) in ' + (RunTimeContrastMinHigh$'.4') + ' ms']
disp_message (WindowHandleText, Message, 'window', 62, 12, 'forest green', 'false')
Message := 'Setting \'contrast_min\' to a higher value typically results in a faster execution and in fewer false positives.'
MessageWrapped := regexp_replace(Message + ' ',['(.{0,35})\\s','replace_all'],'$1\n')
disp_message (WindowHandleText, MessageWrapped, 'window', 122, 12, 'black', 'false')
*
* Close the bar code reader
clear_bar_code_model (BarCodeHandle)
*打开另外一个窗口
dev_open_window (0, Width + 5, 400, 300, 'white', WindowHandleText)
set_display_font (WindowHandleText, 14, 'mono', 'true', 'false')*显示提示信息
Message[0] := 'This example demonstrates the use of the bar code parameter \'contrast_min\'.'
Message[1] := ' '
Message[2] := 'The parameter \'contrast_min\' can be used to reduce the runtime of
find_bar_code in the presence of low contrast bar-like structures in an image. Moreover \'contrast_min\' can also be used to reduce the number of false positives in applications where the expected barcodes have a high contrast.'
MessageWrapped := regexp_replace(Message + ' ',['(.{0,35})\\s','replace_all'],'$1\n')*在另外一个窗口显示信息
disp_message (WindowHandleText, MessageWrapped, 'window', 12, 12, 'black', 'false')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()