halcon将圆形的网格区域变成黑白棋盘
以下是使用halcon将圆形的网格区域变成黑白棋盘的示例代码:
* 生成圆形网格区域
gen_circle_contour_xld (Circle, 250, 250, 200)
gen_grid_points_circle (Circle, 20, 20, 0, GridPoints)
* 将网格点分组
group_points_distance (GridPoints, GridGroups, 15)
* 生成棋盘图案
gen_rectangle2 (Rectangle, -10, -10, 10, 10, 0)
gen_image_const (WhiteImage, "byte", 500, 500, 255)
gen_image_const (BlackImage, "byte", 500, 500, 0)
* 遍历网格区域,根据网格点分组的结果决定该位置填充黑色或白色
for i := 0 to |GridGroups|-1
select_obj (GridGroups[i], GridPointsSelected)
area_center (GridPointsSelected, _, _, Row, Col)
if (i%2)=0 then
paste_rectangle2 (BlackImage, Rectangle, Row-10, Col-10)
else
paste_rectangle2 (WhiteImage, Rectangle, Row-10, Col-10)
endif
endfor
* 合并黑白图像
add_image (WhiteImage, BlackImage, ResultImage)
* 显示结果
dev_display (ResultImage)
``
原文地址: https://www.cveoy.top/t/topic/dHzb 著作权归作者所有。请勿转载和采集!