私はopenCVのMat画像にPoint2f imagePointsを書き込もうとしていました。私は以下のリンクに従っていた。ベクトルからマットを作成<point2f>アサーションに失敗しました。エラー
Create Mat from vector<point2f>
しかし、私は取得していますエラー 'アサーションに失敗しました'。助けてください。
コード:
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;
エラー:
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
私のイメージは、2つのチャンネルを持っています。だから、ImWrite()はアサーション失敗のエラーを投げています。このような場合にイメージポイントを使用してMatイメージを作成するにはどうすればよいですか?
コードと完全なエラーログを表示してください。 –
OpenCVエラー:アサーションが失敗しました(image.channels()== 1 || image.channels()== 3 || image.channels()== 4)cv :: imwrite_、ファイルE:\ softwares \ opencv- 3.1.0 \ opencv-3.1.0 \ modules \ imgcodecs \ src \ loadsave.cpp、行455 – MThomas
これは私のコードです.. projectPoints(objectPoints、rVec、tVec、intrisicMat、distCoeffs、imagePoints); Mat pointsMat = Mat(imagePoints); imwrite( "E:/softwares/1.8.0.71/bin/depthImage.png"、pointsMat); – MThomas