OpenCV错误:断言失败((img.depth()== CV_8U || img.depth()== CV_32F)

时间:2013-12-30 03:05:02

标签: c++ visual-studio-2010 opencv image-processing

当我尝试从here在Visual Studio 2010中运行此代码时。我收到以下错误

OpenCV Error: Assertion failed ((img.depth() == CV_8U || img.depth() == CV_32F)
&& img.type() == templ.type()) in cv::matchTemplate, file ..\..\..\..\opencv\mod
ules\imgproc\src\templmatch.cpp, line 249
An exception occured

1 个答案:

答案 0 :(得分:2)

您似乎无法成功加载图片。因此,请确保通过设置argv[]正确传入图像。请注意以下代码行:

   if(argc <= 1)  
      {  
      std::cout<<"\n Help "<<std::endl;  
      std::cout<<"\n ------------------------------------\n"<<std::endl;  
      std::cout<<"./blink_detect open_eye.jpg close_eye.jpg\n"<<std::endl;  
     std::cout<<"Eg :: ./blink_detect 2.jpg 3.jpg\n"<<std::endl;  
      std::cout<<"\n ------------------------------------\n"<<std::endl;  
      exit(0);  
      }   
    ... ...
    img1 = imread( argv[1], 1 );  
    img2 = imread( argv[2], 1 );  

修改:您可以通过两种方式设置argv[]

  1. 通过项目的命令参数:

    Project > Configuration Properties > Debugging > Command Arguments > 2.jpg 3.jpg

  2. 直接在源代码中:

    argc = 3;
    argv[1] = "2.jpg";
    argv[2] = "3.jpg";