Ask Your Question

smishra87's profile - activity

2016-03-09 05:25:01 -0600 received badge  Popular Question (source)
2013-01-24 12:35:00 -0600 asked a question calcOpticalFlowPyrLK() assertion failure

I have a simple program which detects point in prevImg and finds the matching points in the nextImg using the calcOpticalFlowPyrLK() function. I use all the default params but no matter the setting I always end up with

"OpenCV Error: Assertion failed (mtype == type0 || (CV_MAT_CN(mtype) == CV_MAT_CN(type0) && ((1 << type0) & fixedDepthMask) != 0)) in create, file /tmp/buildd/ros-fuerte-opencv2-2.4.2-0lucid-20120908-1627/modules/core/src/matrix.cpp, line 1405"

The code is as follows;

#include <opencv2/opencv.hpp>
#include <iostream>

int main(int argc, char* argv[]) {

std::string file1_string("img0.pgm"), file2_string("img1.pgm");
std::string win1_string("showing img 1"),win2_string("showing img 2");
cv::Mat img1_gray_Mat, img2_gray_Mat,img1_bgr_Mat,img2_bgr_Mat;
img1_gray_Mat = cv::imread(file1_string.c_str(),CV_LOAD_IMAGE_GRAYSCALE);
img2_gray_Mat = cv::imread(file2_string.c_str(),CV_LOAD_IMAGE_GRAYSCALE);

cv::namedWindow(win1_string.c_str()), cv::namedWindow(win2_string.c_str());

int nfeatures=10;
float qualityLevel=0.01;
int minDistance=1;
int blockSize=3;
bool useHarrisDetector=false;
float k=0.04;
cv::GoodFeaturesToTrackDetector gfttDetector(nfeatures,qualityLevel,minDistance,blockSize,useHarrisDetector,k);

std::vector<cv::KeyPoint> keyPoints1_vec;
std::vector<char> status;
std::vector<float> err;
gfttDetector.detect(img1_gray_Mat,keyPoints1_vec);
cv::Size winSize(15,15);

std::vector<cv::Point2f> points1_vec, points2_vec;
for(std::vector<cv::KeyPoint>::iterator it=keyPoints1_vec.begin();it!=keyPoints1_vec.end();it++)
{
    points1_vec.push_back(it->pt);
    cv::circle(img1_gray_Mat,it->pt,2,cv::Scalar(0,0,255));
}
cv::calcOpticalFlowPyrLK(img1_gray_Mat,img2_gray_Mat,points1_vec,points2_vec, status, err, winSize);


cv::imshow(win1_string, img1_gray_Mat); cv::imshow(win2_string,img2_gray_Mat);
cv::waitKey(0);
cv::destroyAllWindows();
return 0;

}

C:\fakepath\img0.png(/upfiles/13590519803690812.png)