简体   繁体   English

使用OpenCv的Matrix运算(加减法)OpenCV C ++

[英]Using the Matrix operations of OpenCv (Addition and Subtraction) OpenCV C++

I added two images together using the addweighted function of openCV 我使用openCV的addweighted功能将两个图像加在一起

addWeighted(ROI,1,watermark,0.5,0.0,ROI); 

however , when i try to do the reverse , I get patches of black instead of removing the second image from the resultant image . 但是,当我尝试进行反向操作时,我会得到黑色斑点,而不是从结果图像中删除第二个图像。

addWeighted(ROI,1,watermark,-0.5,0.0,ROI);

I have tried using subtract as well but I am getting the same result. 我也尝试过使用减法,但是得到了相同的结果。 The image below describes what I'm talking about. 下图描述了我在说什么。 Do note that my algorithm did not correctly detect all the watermarked areas, but for those which were detected correctly, I am unable to subtract the watermark from it. 请注意,我的算法无法正确检测所有带水印的区域,但是对于那些被正确检测的区域,我无法从中减去水印。

在此处输入图片说明

It would be greatly appreciated if you guys could advise me on what to do for the subtraction. 如果你们能建议我如何做减法,将不胜感激。

Thank you. 谢谢。

According to docs of addWeighted you are giving half weight to watermark (can you explain why?) and your last argument is depth type...not array...so it should be -1 if watermark and ROI are of the same depth or you put the depth value you want to put...if you note in the docs the final value is a saturated value ...that is if it exceeds 255 it is being pulled down to 255...so no wonder if you subtract you won't get the two exact value. 根据addWeighted的文档,您给watermark了一半的权重(您能解释为什么吗?),最后一个参数是深度类型...而不是数组...因此,如果watermarkROI的深度相同或为-1,则应该为-1。您放置了要放置的深度值...如果您在文档中注意到最终值是饱和值...也就是说,如果它超过255,它将被拉低到255 ...所以难怪您是否减去您将不会获得两个确切的值。

** EDIT:** for you I + 0.5W = R where I is the lena image, W is the watermark and R is the resultant image. **编辑:**为您I + 0.5W = R其中I是莉娜图像, W是水印, R是合成图像。 Since R is getting truncated above 255 so store the R in an integer matrix CV_32UC3 . 由于R在255以上被截断,因此将R存储在整数矩阵CV_32UC3 Since you are using OpenCV 2.1 so its better you perform the weighted addition by scanning the image rather than using OpenCV API. 由于您使用的是OpenCV 2.1,因此最好通过扫描图像而不是使用OpenCV API来执行加权加法。 That way you can save the R in an integer matrix where the max value you can get is (255 + 255), which will be easily stored. 这样,您可以将R保存在一个整数矩阵中,该矩阵可以得到的最大值是(255 + 255),可以很容易地存储它。 For display use the uchar matrix (truncated one) and for reversing the process use the integer matrix... 对于显示,请使用uchar矩阵(被截断的一个),对于逆向过程,请使用整数矩阵...

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM