【问题标题】:OpenCV error : Assertion failed ((img.depth() == CV_8U || img.depth() == CV_32F)OpenCV 错误:断言失败 ((img.depth() == CV_8U || img.depth() == CV_32F)
【发布时间】:2014-01-02 14:14:50
【问题描述】:

当我尝试从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

【问题讨论】:

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


    【解决方案1】:

    您似乎没有成功加载图像。因此,请确保通过设置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 &gt; Configuration Properties &gt; Debugging &gt; Command Arguments &gt; 2.jpg 3.jpg

    2. 直接在源码中:

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

    【讨论】:

    • 我通过命令行参数给这个应用程序提供参数,它就像 Visual Studio 中项目属性的调试面板中的'code'blink_detect.exe 2.jpg 3.jpg'
    • @TomJMuthirenthi 如果您在 VS 中设置项目属性,您只需提供2.jpg 3.jpg。第一个参数将自动生成。
    • @TomJMuthirenthi 我在答案中添加了如何设置argv[]
    猜你喜欢
    • 2013-09-28
    • 2017-10-08
    • 2017-07-09
    • 2019-07-11
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 2018-05-20
    相关资源
    最近更新 更多