gpt4 book ai didi

c++ - OpenCV 错误 : Assertion failed ((img. depth() == CV_8U || img.depth() == CV_32F)

转载 作者:行者123 更新时间:2023-11-28 03:01:05 26 4
gpt4 key购买 nike

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

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

最佳答案

您似乎没有成功加载图像。因此,请确保通过设置 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. 通过项目的命令参数:

    项目 > 配置属性 > 调试 > 命令参数 > 2.jpg 3.jpg

  2. 直接在源代码中:

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

关于c++ - OpenCV 错误 : Assertion failed ((img. depth() == CV_8U || img.depth() == CV_32F),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20832746/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com