gpt4 book ai didi

c++ - 无法读取图像 OpenCV

转载 作者:太空宇宙 更新时间:2023-11-04 13:41:10 24 4
gpt4 key购买 nike

我正在学习教程 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 文件放在同一层级,仍然没有成功。

最佳答案

像这样将您的图像放在 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

关于c++ - 无法读取图像 OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27605112/

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