一个样品的斜面,因为有景深,所以无法同时聚焦到两条边。想办法聚焦到其中一条不太有特征的边,另一条边通过白色的特征来检测。
dev_open_window(0, 0, 800, 800, 'black', WindowHandle)
dev_set_color('red')
* Image Acquisition 01: Code generated by Image Acquisition 01
list_files ('D:/检测斜面两边之间的距离/img', ['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)
for Index := 0 to |ImageFiles| - 1 by 1
read_image (Image, ImageFiles[Index])
* Image Acquisition 01: Do something
rgb1_to_gray(Image, GrayImage)
* shock_filter(GrayImage, SharpenedImage, 0.7, 10, 'laplace', 1)
scale_image(GrayImage, ImageScaled, 3, -180)
draw_rake(Regions, WindowHandle, 30, 60, 15, Row1, Column1, Row2, Column2)
rake(ImageScaled, Regions1, 30, 60, 15, 1, 20, 'all', 'max', Row1, Column1, Row2, Column2, ResultRow, ResultColumn)
dev_set_color('yellow')
gen_cross_contour_xld(Cross, ResultRow, ResultColumn, 6, 0.01)
pts_to_best_line(Line, ResultRow, ResultColumn, 2, Row11, Column11, Row21, Column21)
dev_set_color('red')
draw_rake(Regions2, WindowHandle, 30, 60, 15, Row12, Column12, Row22, Column22)
rake(ImageScaled, Regions3, 30, 60, 15, 1, 20, 'all', 'max', Row12, Column12, Row22, Column22, ResultRow1, ResultColumn1)
dev_set_color('yellow')
gen_cross_contour_xld(Cross1, ResultRow1, ResultColumn1, 6, 0.785398)
pts_to_best_line(Line1, ResultRow1, ResultColumn1, 2, Row13, Column13, Row23, Column23)
stop()
dev_display(Line)
dev_display(Line1)
* gen_region_line(RegionLines, Row11, Column11, Row21, Column21)
* gen_region_line(RegionLines1, Row13, Column13, Row23, Column23)
* 计算两条边距离的算子,通过点算到最大距离与最小距离。
distance_ss( Row11, Column11, Row21, Column21, Row13, Column13, Row23, Column23, DistanceMin, DistanceMax)
disp_message(WindowHandle, DistanceMin, 'window',20, 20, 'black', 'true')
disp_message(WindowHandle, DistanceMax, 'window',40, 20, 'black', 'true')
disp_message(WindowHandle, Index, 'window',5, 20, 'black', 'true')
stop()
endfor
效果图:
此实例引入了外部算子。这部分算子是我在网上找到的,之前找的那个不知道哪里去了,现在重新找了一个。把他放网盘了,方便大家也方便自己下次使用。有需要 的可以自行下载。我是网上找的,如有侵权请联系我,看到会删。
链接:https://pan.baidu.com/s/1ac4BOp-7-RMT_P0qx1Xi_Q?pwd=3ok2
提取码:3ok2