read_image (img, 'Location_1102.313_1350.506_0.bmp')
rgb1_to_gray (img, GrayImage)
get_image_size (GrayImage, Width, Height)
****选取中间十字区域****
gen_rectangle1 (TMP_Region, 673.583, 904.873, 1368.42, 1573.65)
reduce_domain (GrayImage, TMP_Region, ImageReduced)
binary_threshold (ImageReduced, Region, 'max_separability', 'light', UsedThreshold)
fill_up (Region, RegionFillUp2)
**********************水平区域****************************
opening_rectangle1 (RegionFillUp2, RegionOpening, 150, 1)
fill_up (RegionOpening, RegionFillUp)
shape_trans (RegionFillUp, RegionTrans1, 'convex')
gen_contour_region_xld (RegionTrans1, Contours, 'border')
segment_contours_xld (Contours, ContoursSplit, 'lines', 3, 5, 4)
***求最长两条xld***
length_xld (ContoursSplit, Length)
tuple_sort_index (Length, Indices)
tuple_select_range (Indices, |Indices|-2, |Indices|-1, Selected)
select_obj (ContoursSplit, ObjectSelected, Selected+1)
***直线拟合***
fit_line_contour_xld (ObjectSelected, 'gauss', -1, 2, 1, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
**********************垂直区域****************************
opening_rectangle1 (Region, RegionOpening1, 1, 150)
fill_up (RegionOpening1, RegionFillUp1)
shape_trans (RegionFillUp1, RegionTrans, 'convex')
gen_contour_region_xld (RegionTrans, Contours1, 'border')
segment_contours_xld (Contours1, ContoursSplit1, 'lines_circles', 5, 4, 2)
length_xld (ContoursSplit1, Length1)
tuple_sort_index (Length1, Indices1)
tuple_select_range (Indices1, |Indices1|-2, |Indices1|-1, Selected1)
select_obj (ContoursSplit1, ObjectSelected1, Selected1+1)
fit_line_contour_xld (ObjectSelected1, 'tukey', -1, 0, 5, 2, RowBegin1, ColBegin1, RowEnd1, ColEnd1, Nr1, Nc1, Dist1)
********************************求四条直线交点*******************************
dev_clear_window ()
dev_display (GrayImage)
******第一个点*******
intersection_lines (RowBegin[0], ColBegin[0], RowEnd[0], ColEnd[0], RowBegin1[0], ColBegin1[0], RowEnd1[0], ColEnd1[0],Rows1,Cols1, IsOverlapping1)
gen_cross_contour_xld (Cross1, Rows1, Cols1, 6, 0)
******第二个点*******
intersection_lines (RowBegin[0], ColBegin[0], RowEnd[0], ColEnd[0], RowBegin1[1], ColBegin1[1], RowEnd1[1], ColEnd1[1],Rows2,Cols2, IsOverlapping2)
gen_cross_contour_xld (Cross2, Rows2, Cols2, 6, 0)
******第三个点*******
intersection_lines (RowBegin[1], ColBegin[1], RowEnd[1], ColEnd[1], RowBegin1[0], ColBegin1[0], RowEnd1[0], ColEnd1[0],Rows3,Cols3, IsOverlapping3)
gen_cross_contour_xld (Cross3, Rows3, Cols3, 6, 0)
******第四个点*******
intersection_lines (RowBegin[1], ColBegin[1], RowEnd[1], ColEnd[1], RowBegin1[1], ColBegin1[1], RowEnd1[1], ColEnd1[1],Rows4,Cols4, IsOverlapping4)
gen_cross_contour_xld (Cross4, Rows4, Cols4, 6, 0)
******中心点******
r:=(Rows1+Rows2+Rows3+Rows4)/4.0
c:=(Cols1+Cols2+Cols3+Cols4)/4.0
gen_cross_contour_xld (Cross, r, c, 6, 0.785398)
<Halcon练习>Mark区域定位(直线拟合相交)
最新推荐文章于 2023-03-16 14:50:06 发布