简体   繁体   English

无法使用opencv库运行C ++程序

[英]Can't run a C++ program with opencv library

I wrote a simple test program for opencv to see if it's working after I compiled my OpenCV 2.4 in visual studio 2010 pro. 我为opencv编写了一个简单的测试程序,看看它是否在我在Visual Studio 2010专业版中编译我的OpenCV 2.4之后才能正常工作。

The program goes like this: 该计划如下:

#include "StdAfx.h"    
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat im = imread("c:/full/path/to/lena.jpg");
    if (im.empty()) 
    {
        cout << "Cannot load image!" << endl;
        return -1;
    }
    imshow("Image", im);
    waitKey(0);
}

The thing is that the program compiles without problems ( I've set all the lib paths and include paths in visual studio), but when I try to run it, it gives me the following error message winow: "The program can't start because opencv_core240d.dll is missing from your computer. Try reinstalling the program to fix this problem" 问题是程序编译没有问题(我已经设置了所有的lib路径并在visual studio中包含路径),但是当我尝试运行它时,它给了我以下错误信息winow:“程序无法启动因为您的计算机缺少opencv_core240d.dll。请尝试重新安装该程序以解决此问题“

Now, I've read that this could be solved by setting the windows PATH variable to the directory where the actual .dll file is located by doing a cmd command: 现在,我已经读过这可以通过执行cmd命令将windows PATH变量设置为实际.dll文件所在的目录来解决:

SET PATH="C:\Program Files (x86)\OpenCV\opencv\build\bin\Debug"

The path specified is indeed the path where the .dll file is located however, I still get the error. 指定的路径确实是.dll文件所在的路径,但是,我仍然得到错误。

Help would really be appreciated since I've spent far too much time cocking around this... 我真的很感激,因为我花了太多时间在这周围徘徊......

You will have to run your program from the same command line from where you set the PATH(after setting the path, of course). 您必须从设置PATH的同一命令行运行程序(当然,在设置路径之后)。

If you are trying to run it from some other place, you should set the PATH env. 如果您尝试从其他地方运行它,则应设置PATH环境。 variable in the Control Panel -> System first(*), then restart your command line/IDE to have the new PATH in effect 控制面板中的变量 - >系统优先(*),然后重新启动命令行/ IDE以使新PATH生效

(*) Control Panel -> System -> Advanced System Settings -> Environment Variables on Windows 7 (*)控制面板 - >系统 - >高级系统设置 - > Windows 7上的环境变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM