在OpenCV C+&#x2B中叠加两个图像。

发布于 2025-02-05 05:30:10 字数 1513 浏览 1 评论 0原文

我想使用OpenCV C ++制作全景图像。 我可以将两个图像缝合在一起,但是在缝合两个图像后,有一个黑色区域。 一种方法是裁剪图像,以便不再有黑色像素,然后我可以重复该过程,但是由于输出图像不是通过裁剪来构造矩形,因此我们松开了图像的某些部分。 我想到的第二种方法是转换第三张图像,然后编写一个函数,该功能检查哪个像素的值大于零,并将该值放在最终图像中。 这是我写的功能:

Mat SuperImpose(Mat ADDedImage, Mat inputImg) {

    for (int i = 0;i < ADDedImage.rows;i++)
    {
        for (int j = 0;j < ADDedImage.cols;j++)
        
        {
            if ((int)inputImg1.at<Vec3b>(i, j).val[2] > 0 || (int)inputImg1.at<Vec3b>(i, j).val[1] > 0 || (int)inputImg1.at<Vec3b>(i, j).val[0] > 0)
            {
                ADDedImage.at<Vec3b>(i, j)[0] = inputImg.at<Vec3b>(i, j)[0];
                ADDedImage.at<Vec3b>(i, j)[1] = inputImg.at<Vec3b>(i, j)[1];
                ADDedImage.at<Vec3b>(i, j)[2] = inputImg.at<Vec3b>(i, j)[2];

            }
        }
    }
}
return ADDedImage;

} 它有效,但有一个问题。

”

“最终图像”

在这里您可以看到两个输入图像和最终输出。在最终输出中,两个图像的边界中有一个黑色条纹,我不知道为什么会发生。我该如何修复?有什么更好的方法吗?

I want to make panorama images using opencv c++.
I can stitch two images together but after stitching two images there is a black region.
One way is to crop the image so there is no longer black pixels and then I can repeat the process, but since the output image is not rectangle by cropping we loose some part of the image.
Second way that came to my mind is that transform third image and then write a function that check which pixel has values bigger than zero and put that value in the final image.
Here is the function that I wrote:

Mat SuperImpose(Mat ADDedImage, Mat inputImg) {

    for (int i = 0;i < ADDedImage.rows;i++)
    {
        for (int j = 0;j < ADDedImage.cols;j++)
        
        {
            if ((int)inputImg1.at<Vec3b>(i, j).val[2] > 0 || (int)inputImg1.at<Vec3b>(i, j).val[1] > 0 || (int)inputImg1.at<Vec3b>(i, j).val[0] > 0)
            {
                ADDedImage.at<Vec3b>(i, j)[0] = inputImg.at<Vec3b>(i, j)[0];
                ADDedImage.at<Vec3b>(i, j)[1] = inputImg.at<Vec3b>(i, j)[1];
                ADDedImage.at<Vec3b>(i, j)[2] = inputImg.at<Vec3b>(i, j)[2];

            }
        }
    }
}
return ADDedImage;

}
It works but there is one issue.
image 1

image 2

final image

here you can see the two input images and the final output. in the final output there is a black stripe in the borders of the two images which I dont know why happen. How can I fix? is there any better way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文