2013-04-18 60 views
0

我有2幀由移動(非常慢)的相機完成的視頻流;在使用(通過OpenCV)SIFT算法和findHomography OpenCv函數後,我有描述攝像機在兩幀之間完成移動的變換矩陣。 我想要做的是找到的第一個幀的點在第二個: 所以我的代碼是:通過Homography矩陣變換矢量時出錯 - C++ OpenCV

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 

但是,在寫入錯誤時,我收到以下錯誤: OpenCV的錯誤:斷言失敗(type == B.type()& &(type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2))in gemm,file/tmp/buildd/ros-什麼是():/ tmp/buildd/fmt.cpp,在調用'cv :: Exception'的實例後終止調用了什麼():/ tmp/buildd/ROS-福艾爾特馬-opencv2-2.4.2-1precise-20130312-1306 /模塊/核心/ SRC/matmul.cpp :711:error:(-215)type == B.type()& &(type == CV_32FC1 ||鍵入== CV_64FC1 ||鍵入== CV_32FC2 ||類型== CV_64FC2)函數GEMM

中止(核心轉儲)

爲什麼?

回答

0

你的代碼有點複雜。特別是,不確定輸入的大小是多少,然後是轉義的效果,因爲您還在srcMat的大小之前指定了大小。

你可以嘗試以下方法:

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 

需要注意的是,你並不真的需要事先分配dstMat;它由OpenCV自動完成。
悠也許應該還檢查的H的類型,我不知道,cv::findHomography返回單個或雙精度矩陣,在這種情況下,你必須doubleCV_32F通過CV_64F更換float;