OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 19 Oct 2017 07:30:55 -0500findFundamentalMat and drawMatches with maskhttp://answers.opencv.org/question/176621/findfundamentalmat-and-drawmatches-with-mask/ 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 type`vector<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
GrilltellerThu, 19 Oct 2017 07:30:55 -0500http://answers.opencv.org/question/176621/Fundamental Matrix Accuracyhttp://answers.opencv.org/question/57267/fundamental-matrix-accuracy/ I am working on 3d Reconstruction of Scene. I matched the feature of 2 images. I have the Keypoints1 and Keypoints2. I have Fundamental F and Essential Matrix E. Now I have to check X'FX =0. I know X' is the coordinate of second image and X is the coordinate of image of the first image. I have few questions can anyone please help me.
Is X' and X are the keypoints1 and keypoints2 ?
Is it (x, y) coordinate of that keypoints?
The product of X'FX, this will be in Mat format, if I not wrong. How this will be equal to 0?
Please can anyone help, sorry if my question is silly.
Thanks in advance.SUHASWed, 11 Mar 2015 06:06:43 -0500http://answers.opencv.org/question/57267/Validating the Funadamental Matrixhttp://answers.opencv.org/question/29876/validating-the-funadamental-matrix/I am calculating the fundamental matrix between two successive frames of a kinect, and according to Hartley and Zisserman the matrix should satisfy x'Fx=0.
I wrote up some quick code that I thought might do the job, but it's not working perfectly, which I will detail at the end of this question:
Mat RansakMask;
Mat F = findFundamentalMat(good_matches1,good_matches2,8,3.0,0.99,RansakMask);
cout << "Number of matches: " << RansakMask.size().height << endl;
int matches[2];
matches[0]=0;matches[1]=0;
for (int j = 0; j < (good_matches1.size()); j++)
{
if(RansakMask.at<uchar>(j, 0) != 1)continue;
cv::Mat p1(3,1, CV_64FC1), p2(3,1, CV_64FC1);
p1.at<double>(0) = good_matches1.at(j).x;
p1.at<double>(1) = good_matches1.at(j).y;
p1.at<double>(2) = 1.0;
p2.at<double>(0) = good_matches2.at(j).x;
p2.at<double>(1) = good_matches2.at(j).y;
p2.at<double>(2) = 1.0;
Mat m = (p1.t()*F*p2);
int i = (abs(m.at<double>(0))<0.5)?0:1;
matches[i]++;
}
cout << "Number of correct: " << matches[0] << endl << "Number of wrong: " << matches[1] << endl;
if(matches[1]>matches[0])
{
cout << "Fundamental Mat is wrong" << endl;
}
The basic idea was, out of all the inliers, compute which were accurate (<0.5f), and which weren't. If there are more accurate than wrong, we can proceed assuming F is relatively accurate.
However, when holding the camera still, this seems to work 9 frames out of 10, on the tenth frame usually giving an answer like (2 correct, 198 wrong) whereas every other frame is typically (198 correct, 2 wrong) etc.
When I move the camera, this turns into more of a 50% chance to be wrong. I don't want to have to throw away F every second frame, so I feel I must be missing something with this code.
Any advice would be appreciated. Thanks.FraserTWed, 12 Mar 2014 12:17:09 -0500http://answers.opencv.org/question/29876/