Error transforming a vector via Homography matrix - C++ OpenCV -


i have 2 frames of video stream done moving (very slow) camera; after using (through opencv) sift algorithm , findhomography opencv function have transformation matrix describes movement done camera between 2 frames. find point of first frame in second one: code :

h = findhomography( point1, point2, cv_ransac );  //compute transformation matrix using                                        // matching points (the matrix correct, 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 3x1 vector coordinate                                          // of interest point in frame 1 srcmat= mat(vec).reshape(1).t();     //conversion of vec in mat (the vector correct, checked it) dstmat = h*srcmat;     //compute arrival point in frame 2  // error 

but, error written, receive 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 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?

your code bit convoluted. in particular, not sure size entries reshapemethod, , effect of transpose since specified before size of srcmat.

you try following:

cv::mat srcmat(3, 1, cv_32f); // allocate 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 not need allocate dstmatbeforehand ; automatically done opencv.
yuu should maybe check type of h, not sure cv::findhomography returns single or double-precision matrix, in case have replace floatby double , cv_32f cv_64f;


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -