2016-07-20 6 views
0

私は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イメージを作成するにはどうすればよいですか?

+0

コードと完全なエラーログを表示してください。 –

+0

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

+0

これは私のコードです.. projectPoints(objectPoints、rVec、tVec、intrisicMat、distCoeffs、imagePoints); Mat pointsMat = Mat(imagePoints); imwrite( "E:/softwares/1.8.0.71/bin/depthImage.png"、pointsMat); – MThomas

答えて

1

コメントに書いたことで、Matをファイルに書き込もうとしているようです。問題は、Vector<Point2f>からのMatは、どの画像フォーマット(グレースケール、RGBまたはRGBA)とも互換性がない2チャンネルのマトリックスを与えることです。

また、メインの投稿を編集して(マークダウンを使用して)コードを表示してください。読みやすく、さらに役立ちます。

+0

このデータを使ってMat画像を作成するにはどうすればいいですか? – MThomas

+0

この2チャンネルの意味を教えてもらえますか?イメージとして表示するとはどういうことでしょうか?値をシリアル化されたMatオブジェクトとして保存しようとしているだけの場合は、XMLまたはYML形式で保存する目的のcv :: FileStorageクラスがあります(http://docs.opencv.org/2.4/modulesを参照してください)。 /core/doc/xml_yaml_persistence.html)。 – Cedric

+0

私の目標は、3D clodポイントを2D画像データに変換することです。私は2D画像を保存して、2D深度画像を視覚化したいと思います。 – MThomas

関連する問題