OpenCV:将图像A的“仅一部分"添加/合并/合并到图像B [英] OpenCV : Add/merge/combine 'only part' of Image A to Image B

查看:106
本文介绍了OpenCV:将图像A的“仅一部分"添加/合并/合并到图像B的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经检查了一些有关通过OpenCV添加(合并/合并)两个图像的问题.但是我的问题在这里有点不同.我想仅将图像A的某些部分添加/合并/合并到图像B .考虑下面的示例:-

I have checked out some already answered questions regarding adding(combining/merging) two images withOpenCV. But my question is a bit different here. I want to add/merge/combine only some part of image A to image B. Consider the example below :-

在这张照片中,Image A-戴眼镜的人

In this picture, Image A - guy wearing spectacles

Image B-没有眼镜的家伙(豆先生) 因此,我要寻找的是algorithmOpenCV中的函数,通过它们,我可以使Image B仅具有> 眼镜(即, (也请不要-我不希望我的结果看起来像Image C一样,这是两个图像的变形版本.我只想从Image AImage B.其余所有内容都将保持为Image B中的状态) 非常感谢您的帮助:)

Image B - guy without spectacles (Mr. Bean) So, what I am looking for is some algorithm or function in OpenCV, by which I can make Image B having only spectacles of Image A (that is, merging part of Image A into Image B.) (Also, please not - I don't want my result to look like Image C here which is morphed version of both images. I just want to add spectacles from Image A to Image B. Rest everything will be as it is in Image B) Any help is highly appreciated :)

就我而言,编程语言无关紧要.我可以使用任何语言的C ++,Java,python,Ruby等. 如果您仍然不理解我的查询,我可以再解释一次. 期待一些好的解决方案.谢谢

In my case, programming language doesn't matter. I can work with any language C++, Java, python, Ruby etc. If you still didn"t understood my query, I can explain again. Looking forward to some good solution. Thanks

推荐答案

您的问题不是很清楚-您没有确切说明对输入图像的了解.

Your questions is not very clear - you don't specify exactly what you know about the input images.

假设您以某种方式标识了两个图像中要剪切的区域(这是最困难的部分),那么它就变成了琐碎的合成过程.基本算法使用遮罩",即与原始图像大小相同的黑白图像,在要保留的第一图像(背景)区域中为白色,在其他地方为黑色.您将第一个图像乘以遮罩,将第二个图像乘以遮罩的负片,然后对结果求和.

Assuming that you somehow identify the regions to cut in both images (and this is the hard part), then it becomes a trivial compositing procedure. The basic algorithm uses a "matte", i.e. an black/white image of the same size as the original one, white in the first image's (background) areas to keep, and black elsewhere. You multiply the first image by the matte, and the second one by the matte's negative, and you sum the results.

这篇关于OpenCV:将图像A的“仅一部分"添加/合并/合并到图像B的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆