(1)1D灰度测量案例check_smd_tilt
* This program checks if SMDs are nearly horizontal or if they
* are tilted with respect to the camera.
* The images were taken with a small depth of field, therefore
* tilted SMDs are partly blurred.
* First, the SMDs are segmented from the image. Then, the
* amplitudes of the edges (first derivatives of the gray values)
* are computed. The edge amplitude is weak in blurred regions.
* Therefore, tilted SMDs can be detected by comparing the edge
* amplitudes in the left and right parts of the SMDs.
*
dev_update_off ()
dev_close_window ()
dev_open_window (0, 0, 640 * .7, 512 * .7, 'black', WindowHandle)
dev_set_draw ('margin')
dev_set_line_width (3)
dev_open_window (0, 640 * .7 + 12, 640 * .7, 512 * .7, 'black', GrayProfileWindow)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
set_display_font (GrayProfileWindow, 16, 'mono', 'true', 'false')
*
NumImages := 10
for Index := 1 to NumImages by 1
read_image (Image, 'smd/smd_tilted_' + Index$'02')
*
* Segment the SMD
var_threshold (Image, Region, 20, 20, 0.1, 2, 'dark')
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 15000, 99999999)
shape_trans (SelectedRegions, RegionTrans, 'convex')
reduce_domain (Image, RegionTrans, ImageReduced)
*
* Check if the SMD is tilted
*找出边缘,测量边缘图像的灰度
sobel_amp (ImageReduced, EdgeAmplitude, 'sum_abs', 3)
*根据条件找出最小内接矩形
smallest_rectangle2 (RegionTrans, Row, Column, Phi, Length1, Length2)
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1 - 3, 20)
gen_measure_rectangle2 (Row, Column, Phi, Length1 - 3, 20, 640, 512, 'nearest_neighbor