2013-03-25 1 views
3

저는 잠시 동안 OpenCV로 작은 광학 흐름 예제를 만들려고했습니다. 모든 콘솔 창에서 다음 실패 주장을 인쇄 함수 호출 calcOpticalFlowPyrLK 제외하고 작동합니다OpenCV의 calcOpticalFlowPyrLK가 예외를 던졌습니다.

OpenCV Error: Assertion failed (mytype == typ0 || (CV_MAT_CN(mytype) == CV_MAT_CV(type0) && ((1 << type0) & fixedDepthMask) != 0)) in unknown function, file ......\src\opencv\modules\core\src\matrix.cpp, line 1421

나는 "caml00000.jpeg", "caml00001으로 표시 300 개 이미지로 분리 분석하고있어 비디오. jpeg ", ...,"caml00299.jpeg ". 여기에 내가 쓴 코드 :

#include <cv.h> 
#include "opencv2/highgui/highgui.hpp" 

using namespace cv; 
using namespace std; 

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

    char buff[100]; 
    int numFrames=300; 
    char fileFormat[]="images/caml%05d.jpeg"; 

    string winname="Test Window"; 

    vector<Mat> imgVec(numFrames); 

    auto itrImg=begin(imgVec); 
    auto itrEnd=end(imgVec); 
    vector<Point2f> featuresPrevious; 
    vector<Point2f> featuresCurrent; 

    namedWindow(winname, CV_WINDOW_AUTOSIZE); 
    int fileNum=0; 
    while(itrImg!=itrEnd){ 
     Mat& imgRef=*itrImg; //get this frame's Mat from the vector iterator 

     //Calculate the name of the file; 
     sprintf(buff,fileFormat,fileNum); 
     string fileName=buff; 
     //string fileName="kitty.jpg"; //attempted using a static picture as well 
     cout << fileName << endl; 

     Mat cImage=imread(fileName, CV_LOAD_IMAGE_GRAYSCALE); 
     cImage.convertTo(imgRef, CV_8U); //also tried CV_8UC1 
     featuresPrevious=std::move(featuresCurrent); 
     goodFeaturesToTrack(imgRef,featuresCurrent,30, 0.01, 30); //calculate the features for use in next iteration 
     if(!imgRef.data){ //this never executes, so there isn't a problem reading the files 
      cout << "File I/O Problem!" << endl; 
      getchar(); 
      return 1; 
     } 

     if(fileNum>0){ 
      Mat& lastImgRef=*(itrImg-1); //get the last frame's image 
      vector<Point2f> featuresNextPos; 
      vector<char> featuresFound; 
      vector<int> err; 
      calcOpticalFlowPyrLK(lastImgRef,imgRef,featuresPrevious,featuresNextPos,featuresFound,err); //problem line 
      //Draw lines connecting previous position and current position 
      for(size_t i=0; i<featuresNextPos.size(); i++){ 
       if(featuresFound[i]){ 
        line(imgRef,featuresPrevious[i],featuresNextPos[i],Scalar(0,0,255)); 
       } 
      } 
     } 

     imshow(winname, imgRef); 

     waitKey(1000/60); //not perfect, but it'll do 

     ++itrImg; 
     ++fileNum; 
    } 

    waitKey(0); 
    return 0; 
} 

나는이 예외에 대해 읽은 유일한 것은, 매트는 다른 형식에있을 때이 발생한다는 그러나 나는 정적 이미지를 읽고 해봤이다가 (에 대한 위의 코드를 참조 "kitty.jpg") 나는 여전히 동일한 실패 주장을합니다. 어떤 아이디어?

답변

8

변경 라인 vector<char> featuresFound;vector<uchar> featuresFound;vector<int> err;

Mat err;에 그 이유를 설명 할 수 있지만, 그것을 수행해야합니다 방법입니다.

편집 : @Sluki가 주석에서 말한 것처럼 - 오류 벡터는 부동 소수점 정밀도 std :: vector 또는 cv :: Mat에 저장되어야합니다.

+0

"벡터 오류;" ~ "매트 잘못;" 및 "벡터 featuresFound;" ~ "벡터 featuresFound;" 일했다! 고맙습니다. – Suedocode

+3

오류는 부동 소수점 정밀도로 계산되므로 int를 사용하여 저장할 수는 없지만 벡터 을 사용하면 Mat – sluki