Halcon 距离计算

Halcon 距离计算_第1张图片

read_image (Image, './img.png')

dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_set_line_width (3)
dev_display (Image)
set_display_font (WindowHandle, 20, 'mono', 'true', 'false')

* ------- 1.点与点的距离 -----------------------
* draw_point (WindowHandle, PointRow1, PointColumn1)
PointRow1 := 100
PointColumn1 := 210
PointRow2 := 150
PointColumn2 := 410

gen_cross_contour_xld (CrossP1, PointRow1, PointColumn1, 30, 0.785398)
gen_cross_contour_xld (CrossP2, PointRow2, PointColumn2, 30, 0.785398)
gen_contour_polygon_xld (RegionLines, [PointRow1,PointRow2], [PointColumn1, PointColumn2])
* gen_region_line (RegionLines, PointRow1, PointColumn1, PointRow2, PointColumn2)

distance_pp (PointRow1, PointColumn1, PointRow2, PointColumn2, Distance)
dev_display (Image)
dev_display (CrossP1)
dev_display (CrossP2)
dev_display (RegionLines)
disp_message (WindowHandle, Distance, 'window', 12, 12, 'black', 'true')
stop()

* ------- 2.点与线的距离 -----------------------
* draw_line (WindowHandle, LineRow1, LineColumn1, LineRow2, LineColumn2)
LineRow1:= 329.0
LineColumn1:= 119.0
LineRow2:= 103.5
LineColumn2:= 46.5

gen_contour_polygon_xld (RegionLines1, [LineRow1,LineRow2], [LineColumn1,LineColumn2])
* gen_region_line (RegionLines1, LineRow1, LineColumn1, LineRow2, LineColumn2)
* 距离计算
distance_pl (PointRow1, PointColumn1, LineRow1, LineColumn1, LineRow2, LineColumn2, DistancePL)

* 垂足点计算
projection_pl (PointRow1, PointColumn1, LineRow1, LineColumn1, LineRow2, LineColumn2, RowProj, ColProj)
gen_contour_polygon_xld (RegionLines2, [PointRow1,RowProj], [PointColumn1,ColProj])

dev_display (Image)
dev_display (CrossP1)
dev_display (RegionLines1)
dev_display (RegionLines2)
disp_message (WindowHandle, DistancePL, 'window', 12, 12, 'black', 'true')
stop()

* ------- 3.点与区域的距离 -----------------------
gen_region_polygon (Region,  [66, 110, 120, 100,24, 66], [466,450,529,606,509, 466])
fill_up (Region, RegionFillUp)


distance_pr (RegionFillUp, PointRow1, PointColumn1, DistanceMin, DistanceMax)

gen_contour_region_xld (RegionFillUp, Contours, 'border')
gen_contour_polygon_xld (ContourPoint, [PointRow1], [PointColumn1])
distance_cc_min_points (ContourPoint, Contours, 'fast_point_to_segment', \
                        DistanceMin1, Row1, Column1, Row2, Column2)

gen_cross_contour_xld (Cross, Row2, Column2, 30, 0.785398)
gen_contour_polygon_xld (RegionLinesPr, [PointRow1, Row2], [PointColumn1,Column2])

dev_display (Image)
dev_display (CrossP1)
dev_display (RegionFillUp)
dev_display (Cross)
dev_display (RegionLinesPr)
disp_message (WindowHandle, DistanceMin, 'window', 12, 12, 'black', 'true')
disp_message (WindowHandle, DistanceMax, 'window', 40, 12, 'black', 'true')
stop()

* ------- 4.线与区域的距离 -----------------------
LineRow1:=250
LineColumn1:= 491
LineRow2:= 228
LineColumn2:= 639

gen_region_line (RegionLines3, LineRow1, LineColumn1, LineRow2, LineColumn2)
gen_contour_polygon_xld (ContourBaseLine, [LineRow1, LineRow2], [LineColumn1, LineColumn2])
distance_lr (RegionFillUp, LineRow1, LineColumn1, LineRow2, LineColumn2, DistanceMin2, DistanceMax1)

* ------- 5.区域与区域的距离 -----------------------
distance_rr_min (RegionFillUp, RegionLines3, MinDistance, Row11, Column11, Row21, Column21)
gen_contour_polygon_xld (ContourRR, [Row11, Row21],[Column11, Column21] )
dev_display (Image)
dev_display (RegionFillUp)
dev_display (ContourBaseLine)
dev_set_color ('blue')
dev_display (ContourRR)

disp_message (WindowHandle, MinDistance, 'window', 12, 12, 'black', 'true')
disp_message (WindowHandle, DistanceMin2, 'window', 40, 12, 'black', 'true')

Halcon 距离计算_第2张图片

Halcon 距离计算_第3张图片

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