我在教程here之后使用Visual Studio设置OpenCV(我有2013社区版和OpenCV 2.4.10)。
我有以下文件夹结构:
OpenCVTest
-OpenCVTest.sln
+x64
+Debug
- opencv_core2410d.dll
- opencv_highgui2410d.dll
- OpenCVTest.exe
- OpenCVTest.ilk
- OpenCVTest.pdb
- feck.png
我的来源:
#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;
}
当我在VS或命令行中运行它时,我收到以下错误:
C:\Users\mr\Documents\Visual Studio 2013\Projects\OpenCVTest\x64\Debug>OpenCVTest.exe feck.png
Could not open or find the image
有人知道为什么会这样吗?
更新
我试过提供完整的路径:
image = imread("C:\Users\mr\Documents\Visual Studio 2013\Projects\OpenCVTest\feck.png", IMREAD_COLOR); // Read the file
并将图像放在与.sln文件相同的级别,仍然没有运气。
答案 0 :(得分:0)
将图像放在OpenCVTest文件夹中,如下所示:
C:\ Users \ mr \ Documents \ Visual Studio 2013 \ Projects \ OpenCVTest \ OpenCVTest \ feck.png
-OpenCVTest.sln
-OpenCVTest <- **HERE**
-ipch
+x64
+Debug
- opencv_core2410d.dll
- opencv_highgui2410d.dll
- OpenCVTest.exe
- OpenCVTest.ilk
- OpenCVTest.pdb
- feck.png
答案 1 :(得分:0)
在教程here中,在“本地方法”下,它显示为:
然后,您需要指定链接器应该在其中的库 成。要执行此操作,请转到链接器‣输入和“附加” 依赖关系“条目添加您要使用的所有模块的名称:
opencv_core231d.lib
opencv_imgproc231d.lib
opencv_highgui231d.lib
opencv_ml231d.lib
opencv_video231d.lib
opencv_features2d231d.lib
opencv_calib3d231d.lib
opencv_objdetect231d.lib
opencv_contrib231d.lib
opencv_legacy231d.lib
opencv_flann231d.lib
我将这些从opencv_core{version}d.lib
更改为opencv_core{version}.lib
(不是调试库),现在似乎工作正常。我可以单步执行Visual Studio中的代码,代码似乎可以正常工作。