- read_image (Image, '如何区分四条边.png')
- get_image_size (Image, Width, Height)
- *定位目标区域
- binary_threshold (Image, RegionBinThresh, 'max_separability', 'light', UsedThreshold)
- closing_circle (RegionBinThresh, RegionClosing, 1.5)
- opening_circle (RegionClosing, RegionOpening, 3.5)
- shape_trans (RegionOpening, RegionTrans, 'convex')
- *创建边缘轮廓
- gen_contour_region_xld (RegionTrans, Contours, 'border')
- segment_contours_xld (Contours, ContoursSplit, 'lines', 5, 4, 2)
- select_contours_xld (ContoursSplit, SelectedContours, 'contour_length', 200, 999999, -0.5, 0.5)
- *近似共线轮廓合并, 减少短小线条干扰
- union_collinear_contours_xld (SelectedContours, UnionContours, 10, 1, 5, 0.1, 'attr_forget')
- elliptic_axis_xld (UnionContours, Ra, Rb, Phi)
- area_center_xld (Contours, Area, Row, Column, PointOrder)
- gen_cross_contour_xld (Cross, Row, Column, 64, rad(45))
- select_shape_xld (UnionContours, SelectedXLD_H, ['phi'], 'or', [rad(-45)], [rad(45)]) //*水平
- select_shape_xld (UnionContours, SelectedXLD_V, ['phi','phi'], 'or', [rad(-90), rad(45)], [rad(-45), rad(90)]) //*竖直
- select_shape_xld (SelectedXLD_H, SelectedXLD_T, 'row1', 'and', 0, Row) //*上: Top
- select_shape_xld (SelectedXLD_H, SelectedXLD_B, 'row1', 'and', Row, Height) //*下: Bottom
- select_shape_xld (SelectedXLD_V, SelectedXLD_L, 'column1', 'and', 0, Column) //*左: Left
- select_shape_xld (SelectedXLD_V, SelectedXLD_R, 'column1', 'and', Column, Width) //*右: Right
- count_obj (SelectedXLD_T, NumberT)
- count_obj (SelectedXLD_B, NumberB)
- count_obj (SelectedXLD_L, NumberL)
- count_obj (SelectedXLD_R, NumberR)
- if (NumberT<=0 or NumberB<=0 or NumberL<=0 or NumberR<=0)
- stop ()
- return ()
- endif
复制代码
elliptic_axis_xld计算出的Phi分别为[-1.50736, -0.0011843, 0.0213292, 0.0]
左侧边Phi为0.0213292被当作水平轮廓筛选出,这个问题出在哪里,如何能正确区分出上下左右,求大佬指导
如何区分四条边.png
左侧边计算不正确.jpg
|