生成一串测量矩形并在矩形里进行做一些处理

生成这样的一串矩形并在矩形里可以做一些测量,阈值或其他的运算,目前没有想到更好的方法,目前是使用draw_line (200000, Row1, Column1, Row2, Column2)
gen_region_line (RegionLines, Row1, Column1, Row2, Column2)
create_metrology_model (MetrologyHandle)
add_metrology_object_generic (MetrologyHandle, 'line', [Row1, Column1, Row2, Column2], 20, 5, 1, 30, [], [], Index)

可以间接的获得这些测量区域,使用此种方法也可以获得一些圆形的测量小矩形区域,具体代码如下

dev_update_on ()
read_image (Image1q, '1q.png')
rgb1_to_gray (Image1q, GrayImage)
draw_line (200000, Row1, Column1, Row2, Column2)
gen_region_line (RegionLines, Row1, Column1, Row2, Column2)
create_metrology_model (MetrologyHandle)
add_metrology_object_generic (MetrologyHandle, 'line', [Row1, Column1, Row2, Column2], 20, 5, 1, 30, [], [], Index)

apply_metrology_model (GrayImage, MetrologyHandle)
get_metrology_object_measures (Contours, MetrologyHandle, 'all', 'all', Row, Column)
* gen_cross_contour_xld (Cross, Row, Column, 6, 0.785398)
* get_metrology_object_result_contour (Contour, MetrologyHandle, 'all', 'all', 1.5)
* get_metrology_object_result (MetrologyHandle, 'all', 'all', 'result_type', 'all_param', Parameter)
dev_update_off ()
count_obj (Contours, Number)
count_seconds(S1)

for i := 1 to Number by 1
         get_image_size (GrayImage, Width, Height)
         select_obj (Contours, ObjectSelected, i)
         smallest_rectangle2_xld (ObjectSelected, Row3, Column3, Phi, Length1, Length2)                 
         gen_measure_rectangle2 (Row3, Column3, Phi, Length1, Length2, Width, Height, 'nearest_neighbor', MeasureHandle)
         measure_pos (GrayImage, MeasureHandle, 1, 30, 'all', 'all', RowEdge, ColumnEdge, Amplitude, Distance)
         gen_cross_contour_xld (Cross1, RowEdge, ColumnEdge, 6, Phi)         
endfor
count_seconds(S2)
Time:=S2-S1

第二种方法是将绘制的ROI进行旋转或平移变换来进行位置变动

生成一串测量矩形并在矩形里进行做一些处理_第1张图片

代码为:

read_image (Image, '无标题.png')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_display (Image)
draw_rectangle2 (WindowHandle, Row, Column, Phi, Length1, Length2)
dev_set_draw ('margin')
gen_rectangle2 (Rectangle, Row, Column, Phi, Length1, Length2)
hom_mat2d_identity (HomMat2DIdentity)
for Phi := 0 to 360 by 5
         
         hom_mat2d_rotate (HomMat2DIdentity, rad(Phi), 170, 370, HomMat2DRotate)
         affine_trans_region (Rectangle, RegionAffineTrans, HomMat2DRotate, 'nearest_neighbor')
         dev_display (RegionAffineTrans)
 *        stop()
endfor

 

你可能感兴趣的:(Halcon)