halcon图像矫正

 图像矫正

**55表示最大文字的高度
text_line_orientation (RegionTrans, InputImage, 55, rad(-30), rad(30), OrientationAngle)
rotate_image (InputImage, ImageRotate, -OrientationAngle/rad(180)*180, 'constant')

 xld矫正,发现这个不是很灵.

get_image_size (InputImage, imageWidth, imageHeight)
binary_threshold (InputImage, Region2, 'max_separability', 'dark', UsedThreshold2)
fill_up (Region2, RegionFillUp)
erosion_circle (RegionFillUp, RegionErosion, 3.5)
gen_contour_region_xld (RegionErosion, Contours, 'border')
*将轮廓分割为边
segment_contours_xld (Contours, ContoursSplit, 'lines', 5, 30, 2)
XCoordCorners := []
YCoordCorners := []
*获取边的数量
count_obj (ContoursSplit, Number)
*存储每条边的起点位置
for index:=1 to Number by 1
   select_obj(ContoursSplit, ObjectCurrent, index)
   *拟合每条边
   fit_line_contour_xld (ObjectCurrent, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
   *存储每条边的顶点x坐标
   tuple_concat (XCoordCorners, RowBegin, XCoordCorners)
   *存储每条边的顶点y坐标
   tuple_concat (YCoordCorners, ColBegin, YCoordCorners)
endfor
* 投影变换给四个特征点与校正后的坐标建立关联
XOff:= 100
YOff:= 100*imageHeight/imageWidth
hom_vector_to_proj_hom_mat2d (XCoordCorners, YCoordCorners, [1,1,1,1], [YOff,YOff,imageHeight-YOff,imageHeight-YOff], [XOff,imageWidth-XOff,imageWidth-XOff,XOff], [1,1,1,1], 'normalized_dlt', HomMat2D)
*投影变换
projective_trans_image (InputImage, OuputImage, HomMat2D, 'bilinear', 'false', 'false')
* 显示校正结果
dev_display (OuputImage)
return ()

矫正前的图片:halcon图像矫正_第1张图片

 矫正后的图片

halcon图像矫正_第2张图片

你可能感兴趣的:(Halcon,halcon)