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

相關文章
相關標籤/搜索