* Image Acquisition 01: Code generated by Image Acquisition 01
list_files ('D:/Study/鐵片方型尋找', ['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])
rgb1_to_gray(Image, GrayImage)
intensity(Image,GrayImage,Mean, Deviation)
threshold(GrayImage,Region,0,Mean+Deviation*0.5)
difference(GrayImage,Region,diffReg)
fill_up(diffReg, RegionFillUp)
reduce_domain(GrayImage, RegionFillUp, ImageReduced)
threshold(ImageReduced,Region2,0,Mean)
fill_up(Region2, RegionFillUp1)
boundary(RegionFillUp1, RegionBorder, 'inner')
connection(RegionBorder, ConnectedRegions)
select_shape(ConnectedRegions,SelectedRegions,'contlength','and',190, 250)
count_obj(SelectedRegions, Number)
if (Number > 0)
dev_display(GrayImage)
for index := 1 to Number by 1
select_obj(SelectedRegions, ObjectSelected, index)
gen_contour_region_xld(ObjectSelected,Contours, 'border')
shape_trans_xld(Contours,XLDTrans,'rectangle2')
smallest_rectangle2_xld (XLDTrans, Row, Col, Phi, Len1, Len2)
tuple_sin (Phi, Sin)
tuple_cos (Phi, Cos)
* 四点中心坐标 左,右,上,下
L_Row := Row - (Len2 * Cos)
L_Col := Col - (Len2 * Sin)
B_Row := Row + (Len1 * Sin)
B_Col := Col - (Len1 * Cos)
T_Row := Row - (Len1 * Sin)
T_Col := Col + (Len1 * Cos)
R_Row := Row + (Len2 * Cos)
R_Col := Col + (Len2 * Sin)
gen_arrow_contour_xld (Arrow1, L_Row, L_Col, R_Row, R_Col, 1, 1)
gen_arrow_contour_xld (Arrow2, B_Row, B_Col, T_Row, T_Col, 1, 1)
gen_contour_polygon_xld (ContourL, [L_Row + 10 * Sin/2, L_Row - 10 * Sin/2], [L_Col - 10 * Cos/2, L_Col + 10 * Cos/2])
gen_contour_polygon_xld (ContourR, [R_Row + 10 * Sin/2, R_Row - 10 * Sin/2], [R_Col - 10 * Cos/2, R_Col + 10 * Cos/2])
gen_contour_polygon_xld (ContourT, [T_Row - 10 * Cos/2, T_Row + 10 * Cos/2], [T_Col - 10 * Sin/2, T_Col + 10 * Sin/2])
gen_contour_polygon_xld (ContourB, [B_Row - 10 * Cos/2, B_Row + 10 * Cos/2], [B_Col - 10 * Sin/2, B_Col + 10 * Sin/2])
dev_set_color ('blue')
dev_display (Arrow1)
dev_display (ContourL)
dev_display (ContourR)
dev_set_color ('green')
dev_display (Arrow2)
dev_display (ContourT)
dev_display (ContourB)
disp_message (3600, Len1 * 2, 'image', T_Row, T_Col, 'red', 'false')
disp_message (3600, Len2 * 2, 'image', R_Row, R_Col, 'magenta', 'false')
* dev_display(ObjectSelected)
wait_seconds(1)
endfor
endif
endfor
留言列表