如圖,測量紅框中的角度,代碼如下:
*讀取並截取圖片
dev_close_window()
read_image (Image, 'C://Users//Administrator//Desktop//1測試圖.jpg')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
*獲取圖形的邊界
draw_rectangle1 (WindowHandle, Row1, Column1, Row2, Column2)
gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
reduce_domain (Image, Rectangle, ImageReduced)
threshold (ImageReduced, Regions, 80, 255)
*threshold (ImageReduced, Regions, 0, 112)
*獲取三角形各邊的信息
skeleton(Regions,TriangleSkeleton)
gen_contours_skeleton_xld(TriangleSkeleton,TriangleContours,1,'filter')
segment_contours_xld(TriangleContours,ContoursSplit,'lines_circles', 5, 4, 2)
select_contours_xld(ContoursSplit,SelectedContours, 'contour_length',20, 999, -0.5, 0.5)
fit_line_contour_xld (SelectedContours, 'tukey', -1, 10, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
*計算三角形角度
angle_ll (RowBegin[0], ColBegin[0], RowEnd[1], ColEnd[1], RowBegin[0], ColBegin[0], RowEnd[2], ColEnd[2], Angle1)
Angle1:=abs(deg(Angle1))
參考:https://www.cnblogs.com/hanzhaoxin/archive/2013/02/12/2910338.html