- * Image Acquisition 01: Code generated by Image Acquisition 01
- list_files ('C:/Users/Administrator/Desktop/新建文件夹', ['files','follow_links'], ImageFiles)
- tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
- dev_get_window (WindowHandle)
- set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
- for Index := 0 to |ImageFiles| - 1 by 1
- read_image (Image, ImageFiles[Index])
- **图像预处理,中值滤波
-
- get_image_size (Image, Width, Height)
-
- mean_image (Image, ImageMean, 10, 180)
- **增强图像对比度
- emphasize (ImageMean, ImageEmphasize, 77, 77, 15)
- **提取亚像素轮廓算子
- edges_sub_pix (ImageEmphasize, Edges, 'canny', 2, 30, 60)
- **合并端点在一起的轮廓
- union_adjacent_contours_xld (Edges, UnionContours, 2, 1, 'attr_keep')
- **计算轮廓或多边形XLD的长度
- length_xld (UnionContours, Length)
- **按升序对元组的所有元素进行排序
- tuple_sort_index (Length, Indices)
- **反转一个数组
- tuple_inverse (Indices, Inverted)
- select_obj (UnionContours, ObjectSelected, Inverted[0]+1)
- **拟合直线
- fit_line_contour_xld (ObjectSelected, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
- select_obj (UnionContours, ObjectSelected2, Inverted[1]+1)
- **拟合直线
- fit_line_contour_xld (ObjectSelected2, 'tukey', -1, 0, 5, 2, RowBegin1, ColBegin1, RowEnd1, ColEnd1, Nr, Nc, Dist)
- **生成直线
- gen_contour_polygon_xld(Line, [RowBegin,RowEnd ], [ColBegin, ColEnd])
- **生成直线
- gen_contour_polygon_xld(Line2, [RowBegin1, RowEnd1], [ColBegin1, ColEnd1])
- **计算两条直线之间的距离
- distance_ss(RowBegin, ColBegin, RowEnd, ColEnd, RowBegin1, ColBegin1, RowEnd1, ColEnd1, DistanceMin, DistanceMax)
-
- get_contour_xld (Line, Row, Col)
- DD:=[]
- for Index1 := 0 to |Row|-1 by 1
- distance_pl (Row[Index1], Col[Index1], RowBegin1, ColBegin1, RowEnd1, ColEnd1, Distance)
- DD:=[DD,Distance]
- endfor
- D:=mean(DD)
-
- dev_display (Image)
- dev_display(Line)
- dev_display(Line2)
- dev_disp_text ('距离D='+D$'.2f', 'image', Height/2, ColBegin1+120, 'red', [], [])
- stop()
- endfor
复制代码 |