Halcon示例:print_quality 字符验证

read_image (Image, 'fonts/arial_a1')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width / 2, Height / 2, 'black', WindowHandle)
dev_display (Image)
dev_set_draw ('margin')
gen_rectangle1 (Rectangle, 37, 69, 115, 141)
reduce_domain (Image, Rectangle, ImageReduced)
*Inspection检查————字符验证OCV
*创建一个新的OCV工具,此工具用在光学字符验证时来训练好的模型
create_ocv_proj ('A', OCVHandle)
*Inspection检查————字符验证OCV
*为OCV工具训练模型,此OCV工具通过create_ocv_proj或read_ocv创建
*traind_ocv_proj(Pattern : : OCVHandle, Name, Mode : )
*Pattern:单通道图像或图像数组,指定训练的模型
*OCVHandle:指定OCV工具句柄
*Name:指定待分析的对象名称
*Mode:指定训练模式
traind_ocv_proj (ImageReduced, OCVHandle, 'A', 'single')
dev_set_color ('red')
for I := 1 to 9 by 1
read_image (Image, 'fonts/arial_a' + I)
*Segmentation分割————Threshold二值化
binary_threshold (Image, Region, 'max_separability', 'dark', UsedThreshold)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 150, 99999)
sort_region (SelectedRegions, SortedRegions, 'character', 'true', 'row')
select_obj (SortedRegions, ObjectSelected, 1)
shape_trans (ObjectSelected, RegionTrans, 'rectangle1')
dilation_rectangle1 (RegionTrans, RegionDilation, 15, 15)
reduce_domain (Image, RegionDilation, ImageReduced)
*Inspection检查————字符验证OCV
*do_ocv_simple(Pattern : : OCVHandle, PatternName, AdaptPos, AdaptSize, AdaptAngle, AdaptGray, Threshold : Quality)
do_ocv_simple (ImageReduced, OCVHandle, 'A', 'true', 'true', 'true', 'true', 5, Quality)
set_tposition (WindowHandle, 15, 12)
write_string (WindowHandle, 'Quality = ' + Quality)
stop ()
endfor
*关闭有句柄OCVHandle指定的OCV工具,并释放其占用的内存空间
close_ocv (OCVHandle)

上一篇:iOS6和iOS7适应代码(6) —— NSLocalizedString


下一篇:图像融合之泊松融合(Possion Matting)