资源文件
链接:https://pan.baidu.com/s/1gULHk3NQn__N-L5TFB_SAw
提取码:z4rs
dev_set_color ('red')
dev_close_window ()
dev_set_line_width (3)
dev_open_window (0, 0, 940, 500, 'black', WindowHandle)
set_display_font (WindowHandle, 21, 'mono', 'true', 'false')
* 1.读取区域文件并处理 ***************************
read_object (RegionCapsule, 'RegionCapsule.hobj')
* 形状变换
shape_trans (RegionCapsule, RegionCapsule, 'convex')
* 区域 转换为 XLD
gen_contour_region_xld (RegionCapsule, Contours, 'border')
* xld 平滑
smooth_contours_xld (Contours, SmoothedContours, 51)
* xld 转换为 区域
gen_region_contour_xld (SmoothedContours, Region, 'filled')
* 截取上半区域
area_center (RegionCapsule, Area1, CenterRow, CenterColumn)
region_features (RegionCapsule, 'width', Width)
region_features (RegionCapsule, 'height', Height)
* 绘制上半区域矩形
gen_rectangle1 (RectangleUp, CenterRow - Height/2, \
CenterColumn - Width / 2, \
CenterRow - Height/3, \
CenterColumn + Width / 2)
* 获取上半区域
intersection (RectangleUp, Region, RegionIntersection1)
* 获取区域凸包点
get_region_convex (RegionIntersection1, Rows, Columns)
* 2.获取区域 极值点 (坐标排序)***************************
* 坐标点 排序 上点
sort_pairs (Rows, Columns, '1', Sorted1, Sorted2)
TopRow := Sorted1[0]
TopCol := Sorted2[0]
* 坐标点 排序 左点
sort_pairs (Rows, Columns, '2', Sorted1, Sorted2)
LeftRow := Sorted1[0]
LeftCol := Sorted2[0]
* 坐标点 排序 右点
PointCount := |Rows|
RightRow := Sorted1[PointCount -1]
RightCol := Sorted2[PointCount -1]
* 绘制三个点
gen_cross_contour_xld (CrossTop, TopRow, TopCol, 16, 0.785398)
gen_cross_contour_xld (CrossLeft, LeftRow, LeftCol, 16, 0.785398)
gen_cross_contour_xld (CrossRight, RightRow, RightCol, 16, 0.785398)
* 计算角
angle_ll (LeftRow, LeftCol, TopRow, TopCol,\
RightRow, RightCol,TopRow, TopCol, Angle1)
* 弧度转为角度
tuple_deg(Angle1, Deg)
ShowMes := Deg $ '.1f'
* 显示结果
dev_clear_window ()
dev_display (RegionIntersection1)
dev_set_color ('blue')
dev_display (CrossTop)
dev_display (CrossLeft)
dev_display (CrossRight)
disp_message (WindowHandle, '角度:' + ShowMes, 'window', 20, 50, 'red', 'true')
stop()
* 3.获取区域 极值点(区域排序)***************************
* 设置半径列表
RadiusLst := []
for RI:=0 to |Rows|-1 by 1
RadiusLst := [RadiusLst, 3.5]
endfor
* 绘制圆形
gen_circle (CircleS, Rows, Columns, RadiusLst)
* 区域排序
sort_region (CircleS, SortedRegions, 'first_point', 'true', 'row')
* 选择排序后区域
select_obj (SortedRegions, TopRegion, 1)
area_center (TopRegion, Area2, TopRow, TopCol)
* 左边区域
sort_region (CircleS, SortedRegions, 'first_point', 'true', 'column')
select_obj (SortedRegions, LeftRegion, 1)
area_center (LeftRegion, Area2, LeftRow, LeftCol)
* 右边区域
sort_region (CircleS, SortedRegions, 'first_point', 'false', 'column')
select_obj (SortedRegions, RightRegion, 1)
area_center (RightRegion, Area2, RightRow, RightCol)
* 显示结果
dev_clear_window ()
dev_set_color ('red')
dev_display (RegionIntersection1)
dev_set_color ('blue')
dev_display (TopRegion)
dev_display (LeftRegion)
dev_display (RightRegion)