C++ imread无法';找不到图像

C++ imread无法';找不到图像,c++,visual-studio,opencv,imread,C++,Visual Studio,Opencv,Imread,我使用visual studio 2013和opencv。我运行一个简单的代码来读取图像并显示它。我从Donloads文件将图像添加到项目的资源文件中。当我在代码下面运行时,image.data为空 #include "stdafx.h" #include <opencv2\core\core.hpp> #include <opencv2\highgui\highgui.hpp> #include <opencv2\opencv.hpp>

我使用visual studio 2013和opencv。我运行一个简单的代码来读取图像并显示它。我从Donloads文件将图像添加到项目的资源文件中。当我在代码下面运行时,
image.data
为空

  #include "stdafx.h"
   #include <opencv2\core\core.hpp>
  #include <opencv2\highgui\highgui.hpp>
 #include <opencv2\opencv.hpp>


int _tmain(int argc, _TCHAR* argv[])
{

cv::Mat image;
image = cv::imread("im.png", CV_LOAD_IMAGE_COLOR);   // Read the file

if (!image.data)                              // Check for invalid input
{
    std::cout << "Could not open or find the image" << std::endl;
    return -1;
}

cv::namedWindow("Display window", cv::WINDOW_AUTOSIZE);// Create a window for display.
imshow("Display window", image);                   // Show our image inside it.

cv::waitKey(0);                                          // Wait for a keystroke in the window
return 0;
#包括“stdafx.h”
#包括
#包括
#包括
int _tmain(int argc,_TCHAR*argv[]
{
cv::Mat图像;
image=cv::imread(“im.png”,cv\u LOAD\u image\u COLOR);//读取文件
if(!image.data)//检查输入是否无效
{

std::coutTry:
C:\\Users\\pr\\Downloads\\im.png
,如果路径正确,应该工作。

Try:
C:\\Users\\pr\\Downloads\\im.png
如果路径正确,应该工作。

这是因为VS中的默认工作目录是
vcxproj
文件的位置(值
$(ProjectDir)


如果希望通过VS(即通过
F5
键)启动应用程序,则应覆盖项目的调试参数。例如,您可以将应用程序的工作目录设置为程序的位置(exe)链接器通过将
Project menu->Properties->Configuration Properties->debug->Working directory
的值设置为
$(OutDir)
来创建,这是因为VS中的默认工作目录是
vcxproj
文件的位置(值
$(ProjectDir)


如果希望通过VS(即通过
F5
键)启动应用程序,则应覆盖项目的调试参数。例如,您可以将应用程序的工作目录设置为程序的位置(exe)链接器通过将
项目菜单->属性->配置属性->调试->工作目录的值设置为
$(OutDir)来创建的

最有可能的是当前目录不是您认为的目录。尝试对文件使用完整路径,看看是否有帮助。我尝试了C:\\Users\pr\Downloads\im.png,但不起作用。最有可能的是当前目录不是您认为的目录。尝试对文件使用完整路径,看看是否有帮助。我尝试了C:\\Users\pr\Downloads\im.pn但它没有起作用。