halcon中将xld轮廓或者region区域绘制在图像上并保存

0、引言

首先是xld轮廓为无法直接绘制在图像上面,因为xld是亚像素级的(具体原因小白现在不清楚,个人觉得达到像素点级别才能绘制,毕竟图像都是像素点组成)
所以对于xld轮廓只能通过转化为region区域之后再绘制在图像上(与直接显示在图像窗口句柄上面的轮廓有一定区别)

1、相关算子

①get_contour_xld(Contour : : : Row, Col)
获得轮廓线的坐标
参数一(Contour ):输入轮廓
参数二(Row) :输出像素值横坐标
参数三(Col) :输出 像素值纵坐标

②gen_region_polygon( : Region : Rows, Columns : )
根据像素点生成区域
参数一(Region ):输出轮廓
参数二(Rows) :输入像素值横坐标
参数三(Columns ) :输入像素值纵坐标

③paint_region(Region, Image : ImageResult : Grayval, Type : )
将region绘制在图像上
参数一(Region ):输入轮廓
参数二(Image ) :输入图像
参数三(ImageResult ) :输出图像(区域绘制在图像)
参数四(Grayval) :设置输入灰度值
参数五(Type ) :设置输入填充方式

2、xld转region

/ContCircle输入的圆轮廓   Region为转化的区域/
get_contour_xld (ContCircle, Row1, Col)
gen_region_polygon (Region, Row1, Col)

xld与region对比如下
在这里插入图片描述

3、region绘制在图像上

1)单通道图像的绘制

单通道图像需要通过compose合成为彩色图像
如果将生成的绿色**[0,255,0]**轮廓绘制在单通道图像上面,如下

draw_circle (WindowHandle, Row, Column, Radius)
gen_circle (Circle, Row, Column, Radius)
paint_region (Circle, Image, ImageR, 0, 'fill')
paint_region (Circle, Image, ImageG, 255, 'fill')
paint_region (Circle, Image, ImageB, 0, 'fill')
compose3 (ImageR, ImageG, ImageB, MultiChannelImage)
*保存图像
write_image (MultiChannelImage1,'bmp' , 0, 'C:/Users/世纪森林/Desktop/picture/region转图像.bmp')

保存之后的图像如下
在这里插入图片描述

2)多通道图像的绘制

draw_circle (WindowHandle, Row, Column, Radius)
gen_circle (Circle, Row, Column, Radius)
paint_region (Circle, MultiChannelImage1, ImageResult, [0,255,0], 'fill')

3、xld绘制在图像上

*ContCircle为输入圆轮廓
gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, 6.28318, 'positive', 1)
*xld转region区域
get_contour_xld (ContCircle, Row1, Col)
gen_region_polygon (Region, Row1, Col)
*region绘制在图像
paint_region (Region, Image, ImageR, 0, 'fill')
paint_region (Region, Image, ImageG, 255, 'fill')
paint_region (Region, Image, ImageB, 0, 'fill')
compose3 (ImageR, ImageG, ImageB, MultiChannelImage1)
write_image (MultiChannelImage1,'bmp' , 0, 'C:/Users/世纪森林/Desktop/picture/xld转图像.bmp')

在这里插入图片描述

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
xiaoxingxing的头像xiaoxingxing管理团队
上一篇 2023年2月26日 上午9:00
下一篇 2023年2月26日 上午9:01

相关推荐