imread无法读取图像

imread fails to read image

本文关键字:图像 读取 imread      更新时间:2023-10-16

我一直在做一个项目来检测离线手写签名。我遇到了一个基本问题。我的程序无法使用imread()功能。它不会显示任何错误,但也不会加载图像。如果我检查图像,它会显示我指定的错误消息。我使用的是带有Microsoft Visual C++2010的OpenCV 2.4.10,而我使用的则是Windows 8。

这是我配置OpenCV的方式有问题吗?还是版本有问题?

我该如何克服这个问题?

如果你有任何用Microsoft Visual C++配置OpenCV的完美教程,请与我分享。这是我正在运行的代码。此外,在运行时,输出对话框显示"Native"已退出,代码为-1。现在我没有看到消息,"错误:无法加载图像..!!"。但问题仍未解决。

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
    Mat image;
    image = imread("C:UserssonyDownloadsShareitPhotoNew Doc 7_1.jpg",CV_LOAD_IMAGE_UNCHANGED);
    if (image.empty()) //check whether the image is loaded or not
    {
      cout << "Error : Image cannot be loaded..!!" << endl;
      //system("pause"); //wait for a key press
      return -1;
 }
      namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
      imshow("MyWindow", image); //display the image which is stored in the 'img' in the "MyWindow" window
      waitKey(0); //wait infinite time for a keypress
      destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
      return 0;
}

OpenCV文档提供了使用Visual Studio设置OpenCV的教程,还有一些示例代码使用cv::imread加载底部包含的图像。

我最近一直在使用opencv,这是迄今为止我发现的最好的Visual Studio opencv教程:

http://opencv-srf.blogspot.com.es/2013/05/installing-configuring-opencv-with-vs.html

主要,你需要做的是正确配置它如下:

设置环境变量在:我的电脑->属性->高级系统设置->环境变量->使用以下参数创建一个新的:变量名:OPENCV_DIR,变量值:C:\OPENCV\build\

编辑变量"Path",为此,在"变量名称"行的末尾添加以下内容:;%OPENCV_DIR%\x86\vc11\bin

然后您应该配置Visual Studio:

右键单击项目名称,然后单击"道具"在C/C++->常规->附加包含目录中,复制并粘贴"$(OPENCV_DIR)\Include"

在Linker->General->Additional Library Directories中,复制并粘贴$(OPENCV_DIR)\x86\vc11\lib

在Linker->Input->Additional dependencies中,单击Edit并添加您在"C:\opencv\build\x86\vc11\lib"中找到的库

注意:如果您的系统是64位而不是32位,请将"x86"替换为"x64"

你能发布你的代码来分析这个问题吗?