一、图像区域方向计算
代码如下:
read_image (Test, 'D:/Pycharm/test.jpg')
dev_close_window()
get_image_size(Test,Width,Height)
dev_open_window(0,0,Height,Width,'white',WindowID)
*输入线段开始点与结束点坐标
RowA1 := 300
ColumnA1 := 10
RowA2 := 300
ColumnA2 := 501
dev_set_color('yellow')
disp_line(WindowID,RowA1,ColumnA1,RowA2,ColumnA2)
RowB1 := 300
ColumnB1 := 300
for i := 1 to 360 by 1
RowB2 := 300 + sin(rad(i)) * 200
ColumnB2 := 300 + cos(rad(i)) * 200
disp_line(WindowID,RowB1,ColumnB1,RowB2,ColumnB2)
*生成直线
gen_region_line(RegionLines1,RowB1,ColumnB1,RowB2,ColumnB2)
*计算区域的方向
orientation_region(RegionLines1,Phi1)
*计算直线的方向
line_orientation(RowB1,ColumnB1,RowB2,ColumnB2,Phi2)
*计算线段
line_position(RowB1,ColumnB1,RowB2,ColumnB2,RowCenter,ColCenter,Length1,Phi3)
*计算两直线夹角
angle_ll(RowA1,ColumnA1,RowB2,ColumnB2,RowB1,ColumnB1,RowB2,ColumnB2,Angle)
endfor
stop()
threshold(Test,Dark,0,70)
connection(Dark,Single)
dev_clear_window()
select_shape(Single,Selected,'area','and',5000,10000)
orientation_region(Selected,Phi)
area_center(Selected,Area,Row,Column)
dev_set_color('red')
dev_set_draw('margin')
dev_set_line_width(7)
Length := 8
disp_arrow(WindowID,Row,Column,Row + cos(Phi + 1.5708) * Length,Column + sin(Phi +1.5708 )* Length,3)
![](https://img-blog.csdnimg.cn/20210420134559320.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0N5bnRoaWFseV8=,size_16,color_FFFFFF,t_70)
![](https://img-blog.csdnimg.cn/20210420134644236.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0N5bnRoaWFseV8=,size_16,color_FFFFFF,t_70)
总结
以上就是今天要讲的内容,本文介绍了区域方向的计算,下一节介绍XLD轮廓。