如何在opencv中合并两个图像而不损失强度

问题描述 投票:0回答:2

我在opencv中有两个图像:图像A图像B

图像 A相机的输出帧。
图像 B 是通过 masking 一张图像获得的 alpha 透明图像。
在遮罩 图像 B 之前,它被

cvWarpPerspective()

扭曲
  • 我尝试过
    cvAddWeighted()
    -当你给出alpha和beta值时它会失去强度
  • 我尝试过aishack-即使在这里你也会失去输出图像的整体强度
  • 我尝试了silveiraneto.net-对我的情况没有帮助

请帮我解决一些问题,使我在混合后不会失去输出图像的强度。

提前致谢

opencv image-processing merge image-editing
2个回答
2
投票

当你说,你失去了强度......你留下了一个问题,你是如何失去它的?

你是否在某种意义上失去了强度:

当您添加图像时,您会达到最大强度,其余的将被丢弃。 (8 位像素加法示例:Pix1 = 200 i,Pix2 = 150 i。“Pix1 + Pix2 = 350”,但最大值为 255,因此 Pix1 + Pix2 = 255)

将图像 A 添加到图像 B 中后,图像 A 的先前值会受到损害,而图像 B 只覆盖了图像的某些部分。 (以 8 位图像为例:Pix1 = 200 i,Pix2 = 150,(Pix1 + Pix2)/2 = 175,但当第二个图像的像素值为零时,Pix2 = 0。则 (Pix1 + Pix2 )/2 = 100,即原图像值的一半)

其中一项观察结果应该告诉您需要做什么。 我不太清楚,根据你提到的功能,他们使用哪种方法。


2
投票

我终于得到答案了。它由5个步骤组成....

步骤 - 1

cvGetPerspectiveTransform(q,pnt,warp_matrix); 
//where pnt is four point x and y cordinates and warp_matrix is a 3 x 3 matrix

步骤 - 2

cvWarpPerspective(dst2, neg_img, warp_matrix,CV_INTER_LINEAR)
//dst2 is overlay image ,neg_img is a blank image 

步骤 - 3

cvSmooth(neg_img,neg_img,CV_MEDIAN); //smoothing the image

步骤 - 4

cvThreshold(neg_img, cpy_img, 0, 255, CV_THRESH_BINARY_INV);
//cpy_img is a created image from image_n

步骤 - 5

cvAnd(cpy_img,image_n,cpy_img);// image_n is a input image
cvOr(neg_img,cpy_img,image_n);

输出 - image_n(不损失输入图像的强度)

© www.soinside.com 2019 - 2024. All rights reserved.