findFundamentalMat and drawMatches with mask

asked 2017-10-19 07:30:55 -0500

Grillteller gravatar image

I want to draw the inlier matches of my Fundamental Matrix to interpretate the results. I am using opencv 3.2 and C++. The parameter mask in findFundamentalMat is used if one uses a method like RANSAC to dermine the inliers and is of typevector<uchar> .

In the documentation it says that in drawMatches the parameter "matchesMask - Mask determining which matches are drawn. If the mask is empty, all matches are drawn." But here only a vector<char> is accepted. Do I have to convert my vector from uchar to char and how do I do that?

Here is my code:

   vector<uchar> inliers(matched_points_1.size());
   Mat F = findFundamentalMat(matched_points_1, matched_points_2, CV_FM_RANSAC, 3, 0.99, inliers);

   Mat matched_points;

   drawMatches(img_1, keypoints_1, img_2, keypoints_2, sym_matches, matched_points, Scalar::all(-1), Scalar::all(-1), inliers, 0);
   imshow("Matched points", matched_points);

If I try it like that it says: "Wrong argumenttypes."

If I change my inliers vector to vector<char> I get the error

OpenCV Error: Assertion failed (mtype == type0 || (CV_MAT_CN(mtype) == CV_MAT_CN(type0) && ((1 << type0) & fixedDepthMask) != 0)) in cv::_OutputArray::create, file C:\opencv\opencv-master\modules\core\src\matrix.cpp, line 2461

edit retag flag offensive close merge delete

Comments

I found it myself: Just change the vector<uchar> to vector<char> with:

vector<char> inliers_c(inliers.begin(), inliers.end());
drawMatches(img_1, keypoints_1, img_2, keypoints_2, sym_matches, matched_points_RANSAC, Scalar::all(-1), Scalar::all(-1), inliers_c, 0);
Grillteller gravatar imageGrillteller ( 2017-10-20 04:30:52 -0500 )edit

please post this as a answer and close the question. Thanks.

Lucas Amparo Barbosa gravatar imageLucas Amparo Barbosa ( 2018-11-26 11:08:11 -0500 )edit