我终于让OpenCV工作但我遇到了一个问题,我的程序没有进行(没有结果)。该计划的结果应该是一个新窗口中的图像。片段:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], IMREAD_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
重点是,程序构建成功,但是当我调试它时,没有任何反应。我尝试启动无需调试(ctrl + F5,我正在使用MSVisual2012),弹出的是:
我该如何解决这个问题?它与错误的库链接有关吗?
答案 0 :(得分:0)
输出是&#34;用法:display_image ImageToLoadAndDisplay&#34;,这意味着程序没有获取文件名。你可以:
image = imread("C:\myfile.jpg", IMREAD_COLOR);
(并删除之前的行)
打开终端,cd
到可执行目录并运行yourprogram.exe myfile.jpg
在visual studio中设置命令参数。