上面是一张倾斜的点阵字体
我们通过halcon来将改图片中的字体读取出来
dev_update_off ()
read_image (Image, 'F:/halcon/7.OCR字符提取/斜体.png')
rgb1_to_gray (Image, GrayImage)
fast_threshold (GrayImage, Region, 10, 120, 20)
*获取到字体的倾斜角度,因为要想识别,需要先转正,返回的是弧度
text_line_slant (Region, Image, 25, -0.523599, 0.523599, SlantAngle)
*转正图片
hom_mat2d_identity (HomMat2DIdentity)
*基于弧度,生成矩形
*-SlantAngle代表在原有倾斜的字体上+一个负的值,实现 30 + -30 =0,从而扭正图片
hom_mat2d_slant (HomMat2DIdentity, -SlantAngle, 'x', 0, 0, HomMat2DSlant)
*根据矩形,对图像进行仿射变换,得到变换后的图像
affine_trans_image (Image, ImageAffineTrans, HomMat2DSlant, 'nearest_neighbor', 'false')
*对图像阈值处理,方便后续识别
fast_threshold (ImageAffineTrans, Region1, 30, 65, 20)
dilation_rectangle1 (Region1, RegionDilation, 2, 8)
erosion_rectangle1 (RegionDilation, RegionErosion, 2, 4)
connection (RegionErosion, ConnectedRegions)
*处理完毕,可以提取了
sort_region (ConnectedRegions, SortedRegions, 'first_point', 'true', 'column')
read_ocr_class_mlp ('DotPrint_NoRej.omc', OCRHandle)
do_ocr_multi_class_mlp (SortedRegions, ImageAffineTrans, OCRHandle, Class, Confidence)
dev_display (Image)
dev_get_window (WindowHandle)
disp_message (WindowHandle, Class, 'image', 12, 12, 'black', 'true')
clear_ocr_class_mlp (OCRHandle)