问题
I'm trying to setup a simple OpenCV project using Microsoft Visual Studio 2008 in a 64-bit Windows 7 system. I don't have admin rights to the system and as such, I can't go for a fresh installation of OpenCV here.
However, I do have the bin, include and lib directories of OpenCV, compiled on a simillar platform.
I have launched a 'Visual C++ -> General -> Empty Project' and created a .cpp file which reads:
#include <opencv/cv.h>
#include <opencv/highgui.h>
void main()
{
cv::Mat frame = cv::imread("D:\\Images\\lena.bmp");
cv::imwrite("D:\\lena_bw.bmp",frame);
}
In the 'Property->Configuration Property->C/C++->General->Additional Include Directories', I have provided the link to the 'include' directory of OpenCV.
In the 'Property->Configuration Property->Linker->Input->Additional Dependencies', I have provided the path to opencv_core230.lib, opencv_highgui230.lib, opencv_imgproc230.lib etc.
The code builds fine, but when I run it, I get:
Unhandled exception at 0x734761e7 in OpenCVTest.exe: 0xC0000005: Access violation reading location 0xcccccccc.
No symbols are loaded for any call stack frame. The source code cannot be displayed.
I'm getting nowehere with my own ideas. I'm kinda new to the Visual Studio platform.
Please help me figure out a way to make this work.
++++++++++++++++++++++++++++++++++++++++++++++++
When running in 'release' mode, I get the following error during compilation:
1>HelloOpenCV.obj : error LNK2001: unresolved external symbol "public: __thiscall cv::_InputArray::_InputArray(class cv::Mat const &)" (??0_InputArray@cv@@QAE@ABVMat@1@@Z)
1>HelloOpenCV.obj : error LNK2001: unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree@cv@@YAXPAX@Z)
1>HelloOpenCV.obj : error LNK2001: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?imread@cv@@YA?AVMat@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z)
1>HelloOpenCV.obj : error LNK2001: unresolved external symbol "public: void __thiscall cv::Mat::deallocate(void)" (?deallocate@Mat@cv@@QAEXXZ)
1>HelloOpenCV.obj : error LNK2001: unresolved external symbol "bool __cdecl cv::imwrite(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &,class std::vector<int,class std::allocator<int> > const &)" (?imwrite@cv@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV_InputArray@1@ABV?$vector@HV?$allocator@H@std@@@3@@Z)
回答1:
I am giving you detailed setup instructions that don't need Admin-Rights. Avoid doing things in C drive.
1) Launch VS2010 and select “New project…”.
2) Select “Empty Project”, enter Name, select a location to place project. Press “OK”.
3) Now we have created a project from scratch. It is time to link the libraries and make our project use OpenCV. Switch to Property manager by clicking on the tab below. If you can’t find the tab, you can access Property manager from menu View.
4) The default properties are for 32-bit systems (note the Win32 suffixes), because you are using 64-bit system, from now on I am going to describe the configuration for 64-bit systems. If yours is x64 already or you want to work with 32 bit development, leave this step. From the “Build” menu, select “Configuration Manager”. Under “Active solution platform” Win32 should be selected by default. Click on it and select “New…”. Select “x64″ as the new platform and select Win32 to copy settings from. Make sure that “Create new project platforms” is checked.
5) INCLUDE
Under “Common Properties” -> “C/C++” -> “General”, edit “Additional Include Directories” and add browse this path to add “..\OpenCV\build\include”. It is important that you select the “include” folder under “build” folder, not any other “include” folder.
6) LINK LIB
Under “Common Properties” -> “Linker” -> “General”, edit “Additional Library Directories” and add “..\OpenCV\build\x64\vc9\lib”. Here “x64″ stands for 64-bit systems, if you are using 32-bit change it to x86. “vc9″ stands for Visual C++ 2008, leave it as it is assuming you are using VS2008, use vc10 for Visual Studio 2010.
7) LIB INPUT
Under “Common Properties” -> “Linker” -> “Input”, edit “Additional Dependencies” and add the following lib files:
[For Debug]
opencv_core242d.lib
opencv_highgui242d.lib
opencv_imgproc242d.lib
[For Release]
opencv_core242.lib
opencv_highgui242.lib
opencv_imgproc242.lib
Here, naming is as: LibName_Version_Debug.lib ie opencv_imgproc242d.lib is opencv_imgproc is library name, 242 is opencv version and d at last indicate debugging library, if you are not using debug mode, don't use library with "d". I have added very basic libs, you may need to add more according to your code.
8) The steps are the same for “Release” configuration except the linked library filenames. You just need to get rid of the “d” letters before the dot.
Your code should build without any complaints. But while running, you should get an error about a missing dll.
9) DLL
Locate exe/output in your project folder, it's name should be release/debug according to mode of your development and it should have an exe file which is output. Copy the dll files (ends with letter “d” if using debug mode) from “..\OpenCV\build\x64\vc9\bin” (for x64) OR “..\OpenCV\build\x64\vc9\bin” (for 32 bit) and to that folder .
回答2:
In opencv300 you need opencv_imgcodecs300.lib for imread()/imwrite().
来源:https://stackoverflow.com/questions/25506233/trouble-with-opencv-setup-on-visual-studio