簡體   English   中英

沒找到圖片

[英]imread couldn't find image

我使用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;

}

嘗試:如果路徑正確,則C:\\\\Users\\\\pr\\\\Downloads\\\\im.png應該可以工作。

這是因為VS中的默認工作目錄是vcxproj文件的位置(值$(ProjectDir) )。

如果要通過VS(即按F5鍵)啟動應用程序,則應覆蓋項目的調試參數。 例如,您可以通過將Project menu -> Properties -> Configuration properties -> Debugging -> Working directory$(OutDir)來將應用程序的工作目錄設置為鏈接器創建的程序(exe)的位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM