Saturday, April 13, 2013

[Solved] Install OpenCV 2.4.7 using Visual Studio 2010 / 2012 in Windows 7 / 8 (FOR 32 bit machine only)

- This tutorial is only for 32 bit machines. If you have 64 bit OS then follow this link.
- Simplest way of OpenCV Tutorial follow this link. (For 32 bit OS)



Requirements-
1. OpenCV-2.4.7 
2. Cmake 
3. Visual Studio 2010 / 2012
4. Windows 7 / 8


Thanks to Hongbo Miao for this tutorial to install OpenCV 2.4.4 for Visual Studio 2012.


Important Note- After downloading and extracting OpenCV, delete the folder named "x64" inside "build" folder. Then go ahead.



Step-1


Extract OpenCV-2.4.7.exe to a folder let "C:/OpenCV". This OpenCV folder should contain many folders like build, include etc.

Install CMake. Open CMake and use settings below. Then click Configure.


image description
Choose Visual Studio 11 otherwise choose Visual Studio 10. Click Finish.
After getting red output, click Configure again. Wait a moment and then click Generate.
Close CMake and go to C:\MyOpenCV, open OpenCV.sln.
Choose Debug. (or By default it will be Debug)
image description
Right click on INSTALL. And choose Build.
image description
After build successful , go back and choose Release. Similarly, right click on INSTALL. And choose Build.
After build finish, close Visual Studio 2012.
Copy C:\MyOpenCV\install folder to C:\OpenCV. (This install folder contains your whole OpenCV, so there is no need of keeping folders other than install folder.)
So now you have a C:\OpenCV\install folder. You can delete C:\MyOpenCV whole folder if you want.

Step-2


Open Windows Explorer. Click on Computer and then System properties.
image description
Choose Advanced system settings.
image description
Click Environment Variables...
image description
Add only this to Environment Variables -> System variables -> Path
C:\OpenCV\install\bin
image description
image description

Step-3

For Release:


Create a new empty C++ project.

View -> Property Manager or right click on project name inside solution Explorer and choose property.
Double click Release
  1. C/C++ -> General -> Additional Include Directories for 2012 or VC++ Directories -> include directories for 2010, add
C:\OpenCV\install\include\opencv
C:\OpenCV\install\include
  1. Linker -> General -> Additional Library Directories
C:\OpenCV\install\lib
  1. Linker -> Input -> Additional Dependencies
opencv_calib3d247.lib
opencv_contrib247.lib
opencv_core247.lib
opencv_features2d247.lib
opencv_flann247.lib
opencv_gpu247.lib
opencv_highgui247.lib
opencv_imgproc247.lib
opencv_legacy247.lib
opencv_ml247.lib
opencv_nonfree247.lib
opencv_objdetect247.lib
opencv_photo247.lib
opencv_stitching247.lib
opencv_ts247.lib
opencv_video247.lib
opencv_videostab247.lib

For Debug:

View -> Property Manager
Double click Debug
  1. C/C++ -> General -> Additional Include Directories
C:\OpenCV\install\include\opencv
C:\OpenCV\install\include
  1. Linker -> General -> Additional Library Directories
C:\OpenCV\install\lib
  1. Linker -> Input -> Additional Dependencies
opencv_calib3d247d.lib
opencv_contrib247d.lib
opencv_core247d.lib
opencv_features2d247d.lib
opencv_flann247d.lib
opencv_gpu247d.lib
opencv_highgui247d.lib
opencv_imgproc247d.lib
opencv_legacy247d.lib
opencv_ml247d.lib
opencv_nonfree247d.lib
opencv_objdetect247d.lib
opencv_photo247d.lib
opencv_stitching247d.lib
opencv_ts247d.lib
opencv_video247d.lib
opencv_videostab247d.lib
Note the file names has extra "d" which means debug
                             and its over...


Note- Now restart the system and run the below program for testing.


Please share some experience on why to use OPEN CV/ MATLAB /C / C++!!!



Sample code:

//Reading an image
#include "opencv2\core\core.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "cv.h"
#include "highgui.h"
using namespace std;
using namespace cv;
void main()
{
Mat image = imread("00.jpg"); //Give the full path to the image file
namedWindow("mywin");
imshow("mywin", image);
waitKey(0);
}

Sample code:

//Playing Video
#include "cv.h" 
#include "opencv2\core\core.hpp"
#include "opencv2\highgui\highgui.hpp"

#include "highgui.h" 
using namespace cv;
int main() 
// Open the video file
VideoCapture capture("asmall.avi"); //Give the full path for the video file
// check if video successfully opened
if (!capture.isOpened())
return 1;
// Get the frame rate
bool stop(false);
Mat frame; // current video frame
namedWindow("Extracted Frame");
// Delay between each frame in ms
// corresponds to video frame rate
// for all frames in video
while (!stop) {
// read next frame if any 
if (!capture.read(frame))
break;
imshow("Extracted Frame",frame);
// introduce a delay in mili-second
waitKey(50);
}
// Close the video file.
// Not required since called by destructor
capture.release();
return 0; 
}

After Successfully installed comment below. So that I can keep on updating my blog.

Important apps for Android

STOP AUTORUN of APPS in ANDROID

37 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Wow, thanks mate! You really help me! :D

    Btw do you know how to install cvBlobslib or cvBlob on OpenCV 2.4.5 with Microsoft Visual Studio 2012 x64?

    ReplyDelete
  3. Thanks a lot, i haven't tested it yet but i think that it would be great if you add an example for the testing, other then that this is awesome.

    ReplyDelete
    Replies
    1. Hmm OK I will give a simple code to read and display an image... Thanks for the comment.

      Delete
    2. Sample code for playing video and showing an image is given.

      Delete
  4. love the tutorial. however on the samples. its kinda hard to compare. the default code on my compiler has this

    // OpenCvTest.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"


    int _tmain(int argc, _TCHAR* argv[])
    {
    return 0;
    }
    but the sample you gave does not contain it. im using visual studio 2010 x64 bit OS.

    ReplyDelete
  5. i think this sample would be a help.its a code for displaying image. i got this from a blog of Jepson's also discussing how to install but using the old version of OpenCV. i tested it and it worked. thanks for the tutorial. i could've have done it.

    #include "stdafx.h"
    #include
    #include
    #include


    int _tmain(int argc, _TCHAR* argv[])
    {
    IplImage *img = cvLoadImage("D:\\funny.jpg");
    cvNamedWindow("OpenCV",1);
    cvShowImage("OpenCV",img);

    cvWaitKey(0);
    cvDestroyWindow("OpenCV ");
    cvReleaseImage(&img);

    return 0;
    }
    here is the link :http://jepsonsblog.blogspot.com/2012/07/installation-guide-opencv-24-with.html.

    go to the bottom part of the page

    ReplyDelete
    Replies
    1. The code you have given is an out dated one. Use the sample given above. The syntax are more easier and the function names are related to Matlab like functions.

      Delete
    2. i did everything u told sir.... but still not able to get the results. the program u put as example is also no t wrking.it is telling " unable to start program C:\users\anil\Documents\Visual studio 2012\Projects\anil2\x64\Release\anil2.exe" or even Debug on place of release. please help me out sir.

      Delete
    3. Check if you have 32bit OS. If not follow the tutorial for 64bit OS. Install the updates of VS12 (update 2 and 3). It looks like a VS 12 problem not opencv.

      Delete
  6. Hi, I followed your steps to install opencv for VS2012. I keep getting this error once everything has been done.

    Error 1 error C1083: Cannot open include file: 'opencv2\core\core.hpp': No such file or directory

    This is for 32bit.

    ReplyDelete
    Replies
    1. There is a path problem. Please double check the path you have given. Follow the steps carefully.

      Delete
  7. Thanks a lot! The installation tutorial from the OpenCV website got me confused and had me figuring out for hours, your tutorial is great and easy to follow! though i had some trouble running the sample code for displaying an image because of my unfamiliarity with C++ but finally got it working.

    Thanks!

    ReplyDelete
  8. Hi Ansuman,

    Thanks for this wonderful tutorial. I seem to be encountering the same error as that of JP Talusan.

    Additionally, I would also like to mention that the directories you have included - C:\OpenCV\install\include\opencv, C:\OpenCV\install\include, C:\OpenCV\install\lib etc. in the tutorial seem to be in different places for me (I am using OpenCV 2.4.5). The required files for me are at - C:\opencv\include\opencv, C:\opencv\include and C:\opencv\build\x64\vc11\lib respectively. Apparently I don't have the folder 'install'. I changed the directories accordingly when copying them to visual studio. Is this the right thing to do ?

    Thanks for your time.

    ReplyDelete
    Replies
    1. Just download OpenCV from " http://adf.ly/P0Kc7 ". Extract it to specified paths as above in step-2. It will work fine.

      Delete
  9. I have given new link which contain the install folder. Please download that. Extract it in C drive. Then follow from Step 2.

    ReplyDelete
    Replies
    1. For more information and a good tutorial I have written. Please follow "http://adf.ly/RBCdf".

      Delete
    2. hello,

      thanks for your reply. none of the short links are working though..

      Delete
    3. Please visit my other post. That may help you.
      Which link is not working?
      Please specify so that I can check.
      All the adf.ly links are working in my knowledge.
      or your internet service provider has blocked it.

      Delete
  10. can you please put a tutorial for installing openframeworks .

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. Tnx a lot!!!

    tow things i have to comment:
    1) restart your computer after adding Environment Variables!
    without it, the program will not be running.

    2) you have to fix above opencv_core2453.lib to opencv_core245.lib (2453 => 245) in fild Linker -> Input -> Additional Dependencies for release.

    Tnx again, it's the first guideline that are Clear and successful.

    ReplyDelete
  13. i am getting an error...
    "Unable to start program 'C:\users\hai\documents\visual studio 2012\projects\rockk\x64\Debug\rockk.exe'
    The system cannot find the file specified"
    please help me to solve this problem. asap :-)

    ReplyDelete
    Replies
    1. i am getting the same error as Deepak Bigbang. please help me out with some solution.

      Delete
    2. Check if you have 32bit OS. If not follow the tutorial for 64bit OS. Install the updates of VS12 (update 2 and 3). It looks like a VS 12 problem not opencv.

      Delete
  14. Hey I am getting a Cmake Error.It says

    CMake Error: The source directory "C:/OpenCV" does not appear to contain CMakeLists.txt

    ReplyDelete
    Replies
    1. hey Solved the issue , a rookie mistake :)
      I had created another folder called "OpenCV" in which "opencv" folder was present .
      So in CMake i had to give "C:/OpenCV/opencv"

      Thanks

      Delete
  15. hi thanxs a lot .. ur post helped me a lot to install nd execute my first opencv program..
    but i have a problem.Whenever i start a new C++ project,the directory paths and libraries i added in the properties of my first program no longer exist.So do i need to add them everytime i create a new program or is it that i did any mistake while installing.(But one satisfying thing is that after adding paths,the program runs fine :) )

    ReplyDelete
    Replies
    1. Yes you need to add paths, every time u create a new project.

      Delete