Thursday, June 27, 2013

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

Installing OpenCV 2.4.5 using Visual Studio 2010 / 2012 in 

Windows 7/8 64 Bit OS



-  Simplest way of installing OpenCV Tutorial follow this link. (For 32 bit OS)
- The Detailed tutorial on installing OpenCV in 32bit OS machine follow the link.

Requirements-
1. OpenCV
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 "x86" inside "build" folder. Then go ahead.




Step-1


Extract OpenCV-2.4.7 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 Win64 for 64bit OS otherwise choose Visual Studio 11 / 10. Click Finish.
image description
After a while, click Configure again. Wait a moment and then click Generate.
(For Windows 8 user) - Now copy that folder to your windows 8 machine. Now do the following steps.
Close CMake and go to C:\MyOpenCV, open OpenCV.sln.
Choose Debug.
image description
Right click INSTALL. And choose Build.
image description
After build successful , go back and choose Release. Similarly, right click 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


Create your own project in Visual Studio 2012.
Build menu -> Configuration Manager
Change the Active solution platform. Click on Win32, Select New.... Use the settings below and click OK.
image description

Step-4

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 | x64
  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 | x64
  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...


Now restart the system and run the below code 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; 

4 comments:

  1. May I seek for your help ?
    when I paste ur 1st sample code and debugged it. It comes out with this problem "Unhandled exception at at 0x000007FEFCEFAC3D in Project1.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000000029E070."
    What does it means ?

    ReplyDelete
    Replies
    1. I have never encounter such problem. Please check that you have followed all the steps completely.

      Delete
    2. use the code in comment of this link:
      http://4someonehelp.blogspot.sg/2013/04/install-opencv-245-using-visual-studio.html

      Code:
      #include "opencv2\core\core.hpp"
      #include "opencv2\highgui\highgui.hpp"
      #include "cv.h"
      #include "highgui.h"
      #include "tchar.h"


      int _tmain(int argc, _TCHAR* argv[])
      {
      IplImage *img = cvLoadImage("C:/img.jpg");//Give the full path to the image file
      cvNamedWindow("OpenCV",1);
      cvShowImage("OpenCV",img);

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

      return 0;
      }

      Delete
    3. @Ansuman Mahapatra thank u for the great tutorial.
      @Wilfred Lim, i got the same error. I think it's because of the image path. I could fix it by copying image to the project folder(where your c++ files are) and refer it just by it's name and format.

      Delete