Halcon倾斜文本矫正
1.图像预处理
读入图像后,通过边缘提取,轮廓筛选,获取字符所在的区域
edges_sub_pix (ImageReduced, Edges, 'canny', 9, 30, 90)
select_contours_xld (Edges, SelectedContours, 'contour_length', 150, 1200, -0.5, 0.
2.字符区域定位
对提取的轮廓进行旋转矩形拟合,生成不同的多边形区域,再通过判断矩形的长宽,获取字符区域
smallest_rectangle2_xld (SelectedContours, Row, Column, Phi, Length1, Length2)
gen_rectangle2 (Rectangle1, Row, Column, Phi, Length1, Length2)
select_shape (Rectangle1, SelectedRegions1, ['width','height'], 'and', [57.18,39.63], [141.22,127.39]
3.计算字符区域外接旋转矩形,旋转图像
union1 (SelectedRegions1, RegionUnion)
smallest_rectangle2 (RegionUnion, Row1, Column1, Phi1, Length11, Length21)
gen_rectangle2 (Rectangle2, Row1, Column1, Phi1, Length11, Length21)
area_center (Rectangle2, Area, Row2, Column2)
vector_angle_to_rigid (Row2, Column2, 0, Row2, Column2, -Phi2, HomMat2D)
affine_trans_region (Rectangle2, RegionAffineTrans, HomMat2D, 'nearest_neighbor')