C++ OpenCV错误:断言失败((img.depth()
当我尝试从在Visual Studio 2010中运行此代码时,出现以下错误C++ OpenCV错误:断言失败((img.depth(),c++,visual-studio-2010,opencv,image-processing,C++,Visual Studio 2010,Opencv,Image Processing,当我尝试从在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
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 );
我通过命令行参数向这个应用程序提供参数,类似于visual Studio中项目属性调试面板上的“代码”blink_detect.exe 2.jpg 3.jpgstudio@TomJMuthirenthi如果在VS中设置项目属性,则只需给出
2.jpg 3.jpg
。第一个参数将自动生成。@TomJMuthirenthi我在答案中添加了如何设置argv[]
。
argc = 3;
argv[1] = "2.jpg";
argv[2] = "3.jpg";