yus*_*suf 18 c++ opencv visual-studio-2013
我想在Visual Studio 2013中编译一个opencv Console C++程序.这是我的代码:
#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, const char** argv)
{
Mat img = imread("rgb_1.png", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img'
if (img.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", img); //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;
}
Run Code Online (Sandbox Code Playgroud)
虽然我已经在Computer和Visual Studio目录中定义了属性中的所有目录,但是我收到了__CODE__错误.
我该如何解决这个问题?
谢谢
Rev*_*ohn 18
在Windows下,您可以从以下位置复制它:
<your install directory>\opencv30\build\x64\vc12\bin
Run Code Online (Sandbox Code Playgroud)
并将其放入Visual Studio解决方案中(我假设您使用的是x64/Release配置):
<your solution directory>\x64\Release
Run Code Online (Sandbox Code Playgroud)
或者您可以将上述OpenCV添加到PATH环境变量中
luc*_*g3r 10
我有同样的问题.
我是版本320.一旦设置了所有环境变量,请确保您的Additional Include Directories,Additional Library Directories并且Additional Dependencies都是正确的.对我来说,他们是$(OPENCV_BUILD)\include;,$(OPENCV_BUILD)\x64\vc14\lib;和opencv_world320d.lib;分别.
我的OPENCV_BUILD路径变量是C:\opencv320\build将环境变量设置为%OPENCV_BUILD%\x64\vc14\bin (.dll文件所在的位置).去的Additional东西放在你的项目/解决方案右键单击并选择properties -> C/C++第一和properties -> Linker -> General和Input其他两个.
重新启动Visual Studio,如果一切都正确实现,那么您应该能够运行该程序,它应该启动.
编辑:
根据您使用的内容,我必须在下拉列表中切换x86到.x64Solution Platforms
小智 7
您可以检查系统变量以确认所在的目录 opencv_world300.dll(可能C:\opencv\build\x64\vc12\bin).
如果它存在但问题仍然没有解决,请尝试将所有.dll文件放在目录中C:\WINDOWS\system32
小智 5
如果这个问题仍然相关,我就找到了方法。
我猜你是用网站上的教程OpenCV来设置的OpenCV。运行命令提示符并执行命令后,它会创建环境变量,OpenCV但不会将其添加到路径中。因此,如果您转到该路径并在 vc12(对我来说是 vc14)中添加 bin 的位置,保存它,然后重新启动 Visual Studio,它就可以工作。