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

OpenCV error : Assertion failed ((img.depth() == CV_8U || img.depth() == CV_32F)

本文关键字:CV depth img 错误 8U 断言 失败 OpenCV      更新时间:2023-10-16

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

OpenCV Error: Assertion failed ((img.depth() == CV_8U || img.depth() == CV_32F)
&& img.type() == templ.type()) in cv::matchTemplate, file ........opencvmod
ulesimgprocsrctemplmatch.cpp, line 249
An exception occured

您似乎没有成功加载图像。因此,请确保通过设置正确传入图像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.jpgn"<<std::endl;  
     std::cout<<"Eg :: ./blink_detect 2.jpg 3.jpgn"<<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";