آبان ۱۱، ۱۳۹۰

Installing OpenCV 2.3.0 in Windows with VisualStudio 2010


Download OpenCV source: http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.3/OpenCV-2.3.0-win-superpack.exe/download
Extract “opencv” folder  to fiels to C:\cv
Download and install CMake
Start the CMake GUI from Start menu
Select:
•Where is the source code: (the directory where CMakeLists.txt in OpenCV is stored), eg: "C:\Program Files\OpenCV2.2"
•Where to build the binaries: (the directory where the OpenCV library will be built), eg: "C:\Program Files\OpenCV2.2\build"
•Add these two entries:
     oUSE_FFMPEG with value 1
     oWITH_CUDA with value 0

Press Configure and select Visual Studio 2008 or 2010 project.
Enter any parameters, like if you want to build Python bindings, documentation, shared libraries, use TBB, CUDA, Eigen2 libraries, etc. (Note that TBB, 64-bit and CUDA may still be under development and therefore buggy)
Repeat pressing Configure until no more red rows are highlighted.
When ready, press Generate.
Open the "build" directory, where you will find your VS2008 or VS2010 "sln" file.
Open the sln file in VS2008 or VS2010, and Built the Solution. This should compile the OpenCV 2.2 library into the build folder.

WALK THROUGH FOLDERS YOU SHOULD INCLUDE IN VS AND REPLACE THEIR FILES WITH CURRENT BUILT FILES.

Building your own projects using OpenCV 2.2 in Visual Studio

After you have compiled the OpenCV 2.2 library using CMake, you should configure your Visual Studio projects to use OpenCV.
For the below instructions its assume that you installed OpenCV to the default location C:\OpenCV2.2 - if you selected something different (e.g. C:\Program Files\OpenCV2.2) then please adjust accordingly.
First of all create your new (full or empty) C/C++ project.
For an application project (*.exe) add this to your project properties:
Go to VC++ Directories
Add 2 new Include Directories (it's the path where you installed OpenCV, include folder):
C:\Program Files\OpenCV2.2\include
C:\Program Files\OpenCV2.2\include\opencv
Add 1 new Library Directory (it's the path where you installed OpenCV, lib folder):
C:\Program Files\OpenCV2.2\lib
Go to Linker in the left menu and select Input option
Add these entries on Additional Dependencies option:
C:\Program Files\OpenCV2.2\lib\opencv_core220d.lib
C:\Program Files\OpenCV2.2\lib\opencv_highgui220d.lib
C:\Program Files\OpenCV2.2\lib\opencv_video220d.lib
C:\Program Files\OpenCV2.2\lib\opencv_ml220d.lib
C:\Program Files\OpenCV2.2\lib\opencv_legacy220d.lib
C:\Program Files\OpenCV2.2\lib\opencv_imgproc220d.lib
Make the content of 'OpenCV_Helloworld.cpp' as such:

For a shared dynamically loadable library project (DLLs) add this to your project properties:
C/C++ - General - Additional include Directories:
C:\OpenCV2.2\include\opencv;C:\OpenCV2.2\include
Linker - General - Additional library Directories:
C:\OpenCV2.2\lib
Linker - Input - Additonal Dependencies (debug):
opencv_core220d.lib opencv_highgui220d.lib opencv_video220d.lib opencv_ml220d.lib opencv_legacy220d.lib opencv_imgproc220d.lib
Linker - Input - Additonal Dependencies (release):
opencv_core220.lib opencv_highgui220.lib opencv_video220.lib opencv_ml220.lib opencv_legacy220.lib opencv_imgproc220.lib

// OpenCV_Helloworld.cpp : Defines the entry point for the console application.
// Created for build/install tutorial, Microsoft Visual Studio and OpenCV 2.2.0

#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>

int _tmain(int argc, _TCHAR* argv[])
{
        // Open the file.
        IplImage *img = cvLoadImage("photo.jpg");
        if (!img) {
                printf("Error: Couldn't open the image file.\n");
                return 1;
        }
        // Display the image.
        cvNamedWindow("Image:", CV_WINDOW_AUTOSIZE);
        cvShowImage("Image:", img);
        // Wait for the user to press a key in the GUI window.
        cvWaitKey(0);
        // Free the resources.
        cvDestroyWindow("Image:");
        cvReleaseImage(&img);

        return 0;
}



Click on "Debug -> Build Solution" or "Release -> Build Solution" to compile your project. If there was a compile error then you did not set the header file includes correctly. If there was a linker error then you did not set the library path or lib files correctly.
If you get the message as ' 'msvcv100d.dll' ' or ' 'msvcr100d.dll' ' cannot be loaded then download these two dlls(search on google) and copy them to 'bin' folder.
Copy any JPG image as 'photo.jpg' to 'My Documents\Visual Studio 2010\Projects\OpenCV_Helloworld\OpenCV_Helloworld', or to wherever you saved the project to.
Click on "Debug -> Start Debugging" or "Debug -> Start without Debugger".
You should now see an OpenCV GUI window with the photo inside. If an error window pops up about DLL files then make sure you compiled the OpenCV library using CMake (above) and have the OpenCV DLL files on your system PATH or in the same folder as the EXE of your project. If the program runs but it says it cant find the image file, then make sure your image is in the same folder as the EXE, and that it is named 'photo.jpg'.

REF:
http://opencv.willowgarage.com/wiki/VisualC%2B%2B
http://opencv.willowgarage.com/wiki/InstallGuide

OpenCV 2.3.0 Binary for Windows (with ffmpeg support) : http://www.mediafire.com/?cxqtzea2uxd1cfk

هیچ نظری موجود نیست:

ارسال یک نظر