halcon图像合并(贴图到指定位置)

在51halcon上看到一个需求,须要将一张小图去背景后贴在大图的指定位置,经过博客https://www.cnblogs.com/lgyup/p/8472840.html启发,html

PS:本身试验使用每一个像素循环绘制方式发现效率太差改用博客使用的数组连续绘制的方式.数组

*读图 read_image (Image, 'C:/Users/yoga/Desktop/测试图像/月亮.png') read_image (ImagePart, 'C:/Users/yoga/Desktop/测试图像/飞机.png') dev_update_off () count_seconds (Seconds) *rgb分离 decompose3 (Image, ImageR, ImageG, ImageB) decompose3 (ImagePart, ImagePartR, ImagePartG, ImagePartB) *获取目标点 threshold (ImageR, Region, 128, 255) connection (Region, ConnectedRegions) select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 70) area_center (SelectedRegions, Area, Row, Column) *飞机去背景 auto_threshold (ImagePartR, Regions1, 2) select_shape_std (Regions1, SelectedRegions1, 'max_area', 70) connection (SelectedRegions1, ConnectedRegions1) select_shape_std (ConnectedRegions1, SelectedRegions2, 'max_area', 70) difference (ImagePartR, SelectedRegions2, RegionDifference) connection (RegionDifference, ConnectedRegions2) select_shape_std (ConnectedRegions2, SelectedRegions3, 'max_area', 70) get_region_points (SelectedRegions3, PartRows, PartColumns) count:=|PartRows| startRs:=gen_tuple_const(count, Row) startCs:=gen_tuple_const(count, Column) *将全部像素坐标加上偏移量 Rows:=startRs+PartRows Cols:=startCs+PartColumns *r绘制 get_grayval (ImagePartR, PartRows, PartColumns, Grayval) copy_image (ImageR, DupImageR) set_grayval (DupImageR, Rows, Cols, Grayval) *g绘制 get_grayval (ImagePartG, PartRows, PartColumns, Grayval1) copy_image (ImageG, DupImageG) set_grayval (DupImageG, Rows, Cols, Grayval1) *b绘制 get_grayval (ImagePartB, PartRows, PartColumns, Grayval2) copy_image (ImageB, DupImageB) set_grayval (DupImageB, Rows, Cols, Grayval2) compose3 (DupImageR, DupImageG, DupImageB, MultiChannelImage) count_seconds (Seconds1) tt:=(Seconds1-Seconds)*1000

 

最后效果以下测试

下面是原图spa

相关文章
相关标签/搜索