《Halcon 100项目-2》Halcon查找零件个数

Halcon查找零件个数

read_image (Image20231225201927, 'D:/image/bilibili/photo/屏幕截图 2023-12-25 201927.png')
rgb1_to_gray (Image20231225201927, GrayImage)


threshold (GrayImage, Region, 0, 128)
draw_rectangle1 (200000, Row1, Column1, Row2, Column2)
gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
reduce_domain (GrayImage, Rectangle, ImageReduced)

create_shape_model (ImageReduced, 'auto',rad(0),rad(360), 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)
get_shape_model_contours (ModelContours, ModelID, 1)
area_center (Rectangle, Area, Row, Column)
vector_angle_to_rigid (0, 0, 0, Row, Column, 0, HomMat2D)
affine_trans_contour_xld (ModelContours, ContoursAffineTrans, HomMat2D)

dev_set_draw ('margin')
dev_set_line_width (5)
dev_display (GrayImage)
find_shape_model (GrayImage, ModelID, rad(0),rad(360), 0.5, 0, 0.5, 'least_squares', 0, 0.9, Row3, Column3, Angle, Score)

for Index := 0 to |Score|-1 by 1
    *初始化一个空的仿射变换矩阵
    hom_mat2d_identity (HomMat2DIdentity)
*     gen_circle (Circle, Row3[Index], Column3[Index], 30.5)
    hom_mat2d_translate (HomMat2DIdentity,Row3[Index], Column3[Index], HomMat2DTranslate)
    hom_mat2d_rotate (HomMat2DTranslate, Angle[Index], Row3[Index], Column3[Index], HomMat2DRotate)
    affine_trans_contour_xld (ModelContours, ContoursAffineTrans1, HomMat2DRotate)
    
    
endfor

《Halcon 100项目-2》Halcon查找零件个数_第1张图片
参考:https://blog.csdn.net/weixin_43197380/article/details/90292563
《Halcon 100项目-2》Halcon查找零件个数_第2张图片
《Halcon 100项目-2》Halcon查找零件个数_第3张图片

你可能感兴趣的:(【halcon】,Halcon)