遗忘海岸

江湖程序员 -Feiph(LM战士)

导航

直线与圆的拟合测量

dev_close_window ()
read_image (Image, 'gj2')
rgb1_to_gray (Image, Image)

get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width / 2, Height / 2, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_display (Image)
disp_continue_message (WindowHandle, 'black', 'true')

binary_threshold (Image, Region, 'max_separability', 'dark', UsedThreshold)
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions1, 'area', 'and', 237241, 282695)
area_center (SelectedRegions1, Area, Row, Column)
orientation_region (SelectedRegions1, Phi)
vector_angle_to_rigid (Row, Column, Phi, Row, Column, 0, HomMat2D)
affine_trans_region (SelectedRegions1, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
affine_trans_image (Image, ImageAffineTrans, HomMat2D, 'constant', 'false')

**没有啥用就是做个抠图
reduce_domain (ImageAffineTrans, RegionAffineTrans, ImageReduced)
dev_clear_window ()
stop()
* dev_display (SelectedRegions1)

**这里从矫正后图像开
edges_sub_pix (ImageAffineTrans, Edges, 'canny', 0.6, 20, 50)
disp_cross (WindowHandle, Row, Column, 6, 0)
**斜边是60,做三角,因为行方向在角度是正时要取减号(即行数减少方向)
disp_arrow (WindowHandle, Row, Column, Row - 60 * sin(Phi), Column + 60 * cos(Phi), 2)
select_shape_xld (Edges, SelectedXLD1, ['width','height'], 'and', [686.6,324.16], [850.88,369.62])
segment_contours_xld (SelectedXLD1, ContoursSplit, 'lines_circles', 5, 4, 2)


**拟合并绘制纵向直线
select_shape_xld (ContoursSplit, SelectedXLD, ['width','height'], 'and', [0,276.32], [27.91,345.69])
sort_contours_xld (SelectedXLD, SortedContours, 'character', 'true', 'row')
fit_line_contour_xld (SortedContours, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
*采用拟合数据绘制线
gen_contour_polygon_xld (ContH_L, [RowBegin[0],RowEnd[0]] , [ColBegin[0],ColEnd[0]])
gen_contour_polygon_xld (ContH_R, [RowBegin[1],RowEnd[1]] , [ColBegin[1],ColEnd[1]])

**拟合并绘制横向直线
select_shape_xld (ContoursSplit, SelectedXLD2, ['width','height'], 'and', [702.55,0], [811,39.47])
sort_contours_xld (SelectedXLD2, SortedContours1, 'character', 'true', 'row')
fit_line_contour_xld(SortedContours1, 'tukey', -1, 0, 5, 2, RowBegin1, ColBegin1, RowEnd1, ColEnd1, Nr1, Nc1, Dist1)
*采用拟合数据绘制线
gen_contour_polygon_xld (ContW_T, [RowBegin1[0],RowEnd1[0]] , [ColBegin1[0],ColEnd1[0]])
gen_contour_polygon_xld (ContW_B, [RowBegin1[1],RowEnd1[1]] , [ColBegin1[1],ColEnd1[1]])

**测量水平距离
distance_pl (RowBegin[0], ColBegin[0], RowBegin[1], ColBegin[1], RowEnd[1], ColEnd[1], Distance)
disp_message (200000, '两竖直边之间的距离 ' +Distance, 'window',300, 10, 'blue', 'false')
**车辆垂直距离
distance_pl (RowBegin1[0], ColBegin1[0],  RowEnd1[1], ColEnd1[1],RowBegin1[1], ColBegin1[1], Distance1)
disp_message (200000, '两水平边之间的距离 ' +Distance1, 'window',340, 10, 'blue', 'false')


**拟合圆
edges_sub_pix (ImageAffineTrans, Edges1, 'canny', 1, 20, 30)
select_shape_xld (Edges1, SelectedXLD3, ['height','circularity'], 'and', [9.97,0.11404], [92.11,0.3756])

**直接使用下面的就不需要做联合了
**select_shape_xld (Edges, SelectedXLD3, ['width','circularity'], 'and', [74.16,0.74402], [142.74,0.98006])
union_cocircular_contours_xld (SelectedXLD3, UnionContours, 1.6, 0.9, 0.9, 30, 40, 40, 'true', 2)

fit_circle_contour_xld (UnionContours, 'algebraic', -1, 0, 0, 3, 2, Row1, Column1, Radius, StartPhi, EndPhi, PointOrder)
gen_circle_contour_xld (ContCircle, Row1, Column1, Radius, 0, 6.28318, 'positive', 1)


distance_pl(Row1, Column1, RowBegin[0], ColBegin[0], RowEnd[0], ColEnd[0], DistanceR_left)
disp_message (200000, '圆心到左边直线的距离 ' +DistanceR_left+'半径'+Radius, 'window',400, 10, 'blue', 'false')



distance_pp(Row1, Column1, RowEnd1[0], ColEnd1[0],DistanceR_upendpoint)
angle_ll(RowBegin[1],ColBegin[1],RowEnd[1],ColEnd[1],RowBegin1[0],ColBegin1[0],RowEnd1[0],ColEnd1[0],m_angle)
disp_message (200000, '圆心到上边直线末尾点(左边点)的距离 ' +DistanceR_upendpoint+'半径'+Radius, 'window',440, 10, 'blue', 'false')
View Code

posted on 2021-08-12 15:47  遗忘海岸  阅读(88)  评论(0编辑  收藏  举报