当我尝试从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
答案 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[]
:
通过项目的命令参数:
Project > Configuration Properties > Debugging > Command Arguments > 2.jpg 3.jpg
直接在源代码中:
argc = 3;
argv[1] = "2.jpg";
argv[2] = "3.jpg";