首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Vector<point2f>断言创建材质失败错误

从Vector<point2f>断言创建材质失败错误
EN

Stack Overflow用户
提问于 2016-07-21 00:38:09
回答 1查看 722关注 0票数 0

我正在尝试将Point2f imagePoints写入openCV中的Mat图像。我点击了下面的链接。

Create Mat from vector

但是我得到了‘断言失败’的错误。请帮帮忙。

代码:

代码语言:javascript
复制
std::vector<cv::Point3d> objectPoints;
std::vector<cv::Point2d> imagePoints;

cv::Mat intrisicMat(3, 3, cv::DataType<double>::type);
intrisicMat.at<double>(0, 0) = param.focalLength.first;
intrisicMat.at<double>(0, 1) = 0;
intrisicMat.at<double>(0, 2) = param.principalPoint.first;

intrisicMat.at<double>(1, 0) = 0;
intrisicMat.at<double>(1, 1) = param.focalLength.second;
intrisicMat.at<double>(1, 2) = param.principalPoint.second;

intrisicMat.at<double>(2, 0) = 0;
intrisicMat.at<double>(2, 1) = 0;
intrisicMat.at<double>(2, 2) = 1;

cv::Mat rVec(3, 1, cv::DataType<double>::type); // Rotation vector
rVec.at<double>(0) = 0;
rVec.at<double>(1) = 0;
rVec.at<double>(2) = 0;

cv::Mat tVec(3, 1, cv::DataType<double>::type); // Translation vector
tVec.at<double>(0) = 0;
tVec.at<double>(1) = 0;
tVec.at<double>(2) = 0;

cv::Mat distCoeffs(5, 1, cv::DataType<double>::type);   // Distortion vector
distCoeffs.at<double>(0) = param.distortionRadial.at(0);
distCoeffs.at<double>(1) = param.distortionRadial.at(1);
distCoeffs.at<double>(2) = param.distortionTangential.first;
distCoeffs.at<double>(3) = param.distortionTangential.second;
distCoeffs.at<double>(4) = param.distortionRadial.at(2);


projectPoints(objectPoints, rVec, tVec, intrisicMat, distCoeffs, imagePoints);
Mat depthImage = Mat(imagePoints);
imwrite("E:/softwares/1.8.0.71/bin/depthImage.jpg", depthImage);
cout << "depthImage.channels()=" << depthImage.channels() << endl;

错误:

代码语言:javascript
复制
OpenCV Error: Assertion failed (image.channels() == 1 || image.channels() == 3 || image.channels() == 4) in cv::imwrite_, file E:\softwares\opencv-3.1.0\opencv-3.1.0\modules\imgcodecs\src\loadsave.cpp, line 455

我的图像有两个通道。所以ImWrite()抛出了断言失败的错误。如果不是这样,我如何使用image points创建Mat图像?

EN

回答 1

Stack Overflow用户

发布于 2016-07-21 01:51:53

根据您在注释中所写的内容,您似乎正在尝试将您的Mat写入一个文件。问题是,来自Vector<Point2f>Mat会给出一个双通道矩阵,这与任何图像格式(灰度、RGB或RGBA)都不兼容。

此外,请编辑您的主要帖子,以显示代码(使用标记),以便它更容易阅读,然后帮助你。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38486150

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档