gpt4 book ai didi

c++ - 在 OpenCV 中将两个网络摄像头画面拼接在一起

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:30:00 33 4
gpt4 key购买 nike

使用下面的代码:

#include <opencv2/opencv.hpp>
#include <opencv2/stitching/stitcher.hpp>
#include <iostream>
#include <vector>

using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{
Mat fr1, fr2, pano;
bool try_use_gpu = false;
vector<Mat> imgs;
VideoCapture cap(0), cap2(1);

while (true)
{
cap >> fr1;
cap2 >> fr2;
imgs.push_back(fr1.clone());
imgs.push_back(fr2.clone());

Stitcher test = Stitcher::createDefault(try_use_gpu);
Stitcher::Status status = test.stitch(imgs, pano);

if (status != Stitcher::OK)
{
cout << "Error stitching - Code: " <<int(status)<<endl;
return -1;
}

imshow("Frame 1", fr1);
imshow("Frame 2", fr2);
imshow("Stitched Image", pano);

if(waitKey(30) >= 0)
break;
}
return 0;
}

此代码会抛出状态错误 1。我不知道那是什么意思,我也不知道为什么这东西在使用网络摄像头时遇到困难。怎么了?

-托尼

最佳答案

错误是在您的捕获过程中的某个地方,而不是拼接部分。此代码工作正常(使用 these 示例图像):

#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/stitching/stitcher.hpp>
#include <iostream>
#include <vector>

using namespace std;
using namespace cv;

int main()
{
Mat fr1 = imread("a.jpg");
Mat fr2 = imread("b.jpg");
Mat pano;
vector<Mat> imgs;

Stitcher stitcher = Stitcher::createDefault(); // The value you entered here is the default

imgs.push_back(fr1);
imgs.push_back(fr2);

Stitcher::Status status = stitcher.stitch(imgs, pano);

if (status != Stitcher::OK)
{
cout << "Error stitching - Code: " <<int(status)<<endl;
return -1;
}

imshow("Frame 1", imgs[0]);
imshow("Frame 2", imgs[1]);
imshow("Stitched Image", pano);
waitKey();

return 0;
}

Nik Bougalis 挖出的错误消息听起来像是拼接器无法连接图像。图像是否足够清晰以便拼接器找到对应关系?

如果您确定是,请进一步拆分您的问题以找出真正的错误。您可以调整拼接器以使用相机中的静止帧吗?你的相机捕捉正确吗?他们返回哪种类型的图像?

另一方面,拼接不太可能实时工作,这使得您在捕获期间的循环看起来有点不合适。您可能想要提前捕获帧并在后期处理中完成所有操作,或者期望进行大量手动优化以接近可观的帧速率。

关于c++ - 在 OpenCV 中将两个网络摄像头画面拼接在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15798792/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com