OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 18 Apr 2013 06:44:54 -0500Error transforming a vector via Homography matrix - C++http://answers.opencv.org/question/11873/error-transforming-a-vector-via-homography-matrix-c/I have 2 frames of a video stream done by a moving (very slow) camera; after using SIFT algorithm and findHomography OpenCv function i have the transformation matrix that describes the movement done by the camera between the 2 frames.
what i would like to do is to find a point of the first frame in the second one:
so my code is:
H = findHomography( point1, point2, CV_RANSAC ); //compute the transformation matrix using the
// matching points (the matrix is correct, i checked it)
Mat dstMat(3, 1, H.type());
vector<Point3f> vec;
Mat srcMat(3, 1, H.type());
vec.push_back(Point3f(Ptx,Pty,-1)); // fill the 3x1 vector with the coordinate
// of the interest point in frame 1
srcMat= Mat(vec).reshape(1).t(); //conversion of vec in Mat (the vector is correct, i checked it)
dstMat = H*srcMat; //compute the arrival point in frame 2 // ERROR
But, where error is written, i receive the following error:
OpenCV Error: Assertion failed (type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) in gemm, file /tmp/buildd/ros-fuerte-opencv2-2.4.2-1precise-20130312-1306/modules/core/src/matmul.cpp, line 711
terminate called after throwing an instance of 'cv::Exception'
what(): /tmp/buildd/ros-fuerte-opencv2-2.4.2-1precise-20130312-1306/modules/core/src/matmul.cpp:711: error: (-215) type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) in function gemm
Aborted (core dumped)
Why?Thu, 18 Apr 2013 06:07:53 -0500http://answers.opencv.org/question/11873/error-transforming-a-vector-via-homography-matrix-c/Comment by Rogeeeer for <p>I have 2 frames of a video stream done by a moving (very slow) camera; after using SIFT algorithm and findHomography OpenCv function i have the transformation matrix that describes the movement done by the camera between the 2 frames.
what i would like to do is to find a point of the first frame in the second one:
so my code is:</p>
<pre><code>H = findHomography( point1, point2, CV_RANSAC ); //compute the transformation matrix using the
// matching points (the matrix is correct, i checked it)
Mat dstMat(3, 1, H.type());
vector<Point3f> vec;
Mat srcMat(3, 1, H.type());
vec.push_back(Point3f(Ptx,Pty,-1)); // fill the 3x1 vector with the coordinate
// of the interest point in frame 1
srcMat= Mat(vec).reshape(1).t(); //conversion of vec in Mat (the vector is correct, i checked it)
dstMat = H*srcMat; //compute the arrival point in frame 2 // ERROR
</code></pre>
<p>But, where error is written, i receive the following error:
OpenCV Error: Assertion failed (type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) in gemm, file /tmp/buildd/ros-fuerte-opencv2-2.4.2-1precise-20130312-1306/modules/core/src/matmul.cpp, line 711
terminate called after throwing an instance of 'cv::Exception'
what(): /tmp/buildd/ros-fuerte-opencv2-2.4.2-1precise-20130312-1306/modules/core/src/matmul.cpp:711: error: (-215) type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) in function gemm</p>
<p>Aborted (core dumped)</p>
<p>Why?</p>
http://answers.opencv.org/question/11873/error-transforming-a-vector-via-homography-matrix-c/?comment=11877#post-id-11877It seems to be the type... Did you check H and srcMat elements size and channels ? Thu, 18 Apr 2013 06:44:54 -0500http://answers.opencv.org/question/11873/error-transforming-a-vector-via-homography-matrix-c/?comment=11877#post-id-11877Answer by Rogeeeer for <p>I have 2 frames of a video stream done by a moving (very slow) camera; after using SIFT algorithm and findHomography OpenCv function i have the transformation matrix that describes the movement done by the camera between the 2 frames.
what i would like to do is to find a point of the first frame in the second one:
so my code is:</p>
<pre><code>H = findHomography( point1, point2, CV_RANSAC ); //compute the transformation matrix using the
// matching points (the matrix is correct, i checked it)
Mat dstMat(3, 1, H.type());
vector<Point3f> vec;
Mat srcMat(3, 1, H.type());
vec.push_back(Point3f(Ptx,Pty,-1)); // fill the 3x1 vector with the coordinate
// of the interest point in frame 1
srcMat= Mat(vec).reshape(1).t(); //conversion of vec in Mat (the vector is correct, i checked it)
dstMat = H*srcMat; //compute the arrival point in frame 2 // ERROR
</code></pre>
<p>But, where error is written, i receive the following error:
OpenCV Error: Assertion failed (type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) in gemm, file /tmp/buildd/ros-fuerte-opencv2-2.4.2-1precise-20130312-1306/modules/core/src/matmul.cpp, line 711
terminate called after throwing an instance of 'cv::Exception'
what(): /tmp/buildd/ros-fuerte-opencv2-2.4.2-1precise-20130312-1306/modules/core/src/matmul.cpp:711: error: (-215) type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) in function gemm</p>
<p>Aborted (core dumped)</p>
<p>Why?</p>
http://answers.opencv.org/question/11873/error-transforming-a-vector-via-homography-matrix-c/?answer=11875#post-id-11875I think it's your reshape the problem : Here you ask 1 channel, same number of rows and let OpenCV decide for the columns.
Try reshape(1, 3) which will give you 1 channel, 3x3 matrix (check the order of the elements in the output matrix, I'm not sure it's the correct one)
Convert vector of Point3f if my memories are good will produce 1 element of 3 channels for each pointThu, 18 Apr 2013 06:36:56 -0500http://answers.opencv.org/question/11873/error-transforming-a-vector-via-homography-matrix-c/?answer=11875#post-id-11875