0
votes

I have 2 frames of a video stream done by a moving (very slow) camera; after using (through OpenCV) 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?

1

1 Answers

0
votes

Your code is a bit convoluted. In particular, it is not sure what size entries the reshapemethod, and then the effect of the transpose since you also specified before the size of srcMat.

You could try the following:

cv::Mat srcMat(3, 1, CV_32F); // Allocate a 3x1 column vector (floating point)

srcMat.at<float>(0,0) = Ptx;
srcMat.at<float>(1,0) = Pty;
srcMat.at<float>(2,0) = -1.0;

dstMat = H * srcMat;  // Perform matrix-vector multiplication

Note that you do not really need to allocate dstMatbeforehand ; it is automatically done by OpenCV.
Yuu should maybe check also for the type of H, I am not sure that cv::findHomography returns a single or double-precision matrix, in which case you have to replace floatby double and CV_32F by CV_64F;