Halcon极坐标转换,图文解说,含点坐标的转换

极坐标的用途

把圆形的图片转换为矩形,便于字符识别和关键区域的提取。

 

在halcon中对应的算子

(1)极坐标的展开:polar_trans_image_ext(Image : PolarTransImage : Row, Column, AngleStart, AngleEnd, RadiusStart, RadiusEnd, Width, Height, Interpolation : )

(2)极坐标的逆变换:polar_trans_image_inv(PolarImage : XYTransImage : Row, Column, AngleStart, AngleEnd, RadiusStart, RadiusEnd, Width, Height, Interpolation : )

其中:Row, Column分别为圆环的中心行列坐标, AngleStart, AngleEnd为起始和终止的角度值,RadiusStart, RadiusEnd为起始和终止的半径角度值, Width, Height为输出图片的宽和高。

(3)点坐标的逆变换:polar_trans_contour_xld_inv(PolarContour : XYTransContour : Row, Column, AngleStart, AngleEnd, RadiusStart, RadiusEnd, WidthIn, HeightIn, Width, Height : )

 

我写的案例

dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
read_image (Image, '极坐标2.png')
get_image_size (Image, Width, Height)
draw_circle (WindowHandle, Row1, Column1, Radius)
gen_circle (Circle, Row1, Column1, Radius)
reduce_domain (Image, Circle, ImageReduced)
PI:=3.1415926
*逆时针,从0度到360度,转一圈
polar_trans_image_ext (ImageReduced, PolarTransImage, Row1, Column1, 0, 2*PI, 0, Radius, Width, Height, 'nearest_neighbor')
write_image (PolarTransImage, 'jpeg 100', 0, 'd:\\1.jpg')
*长和宽必须是原图像的长和宽,否则尺寸太小的话,图像容易超出,导致一片黑,看不到转换结果
polar_trans_image_inv (PolarTransImage, XYTransImage, Row1, Column1, 0, 2*PI, 0, Radius, Width, Height, 'nearest_neighbor')
write_image (XYTransImage, 'jpeg 100', 0, 'd:\\2.jpg')

*点坐标的转换
*Contour的原坐标是基于极坐标系,我们把它转到笛卡尔坐标系
gen_contour_polygon_xld (Contour, [155.568, 137.404, 30], [47.4712, 116.479, 260])
polar_trans_contour_xld_inv (Contour, XYTransContour, Row1, Column1, 0, 2*PI, 0, Radius, Width, Height, Width, Height)
stop()

变换前:

Halcon极坐标转换,图文解说,含点坐标的转换_第1张图片

变换后:

逆变换:会回原样

 

官方例程

ocr_cd_print_polar_trans.hdev

create_shape_model_xld.hdev

circular_barcode.hdev

 

参考文献

https://blog.csdn.net/qq_32939413/article/details/104092627

https://www.pianshen.com/article/3946344220/

 

你可能感兴趣的:(Halcon,极坐标,点坐标)