Last Updated: February 25, 2016
·
917
· Ventsy

SetUp OpenCV with VS2012 on Win7 64bit

This tip will explain the process of setting up OpenCV library on Windows 7. This library is mostly used for Computer Vision algorithms.

1) Download opencv
http://opencv.org/downloads.html

2) Download vs2012

http://www.microsoft.com/en-gb/download/details.aspx?id=30682

3) Extract opencv (for the purpose of this protip place if in D:)

4) Confirm that bit version of windows is 64.

5) Set up the PATH - click on Start button, right click on My Computer -> Properties -> Advanced System Settings -> Environment Variables -> System Variables (find PATH) -> Edit -> just add the following:

D:\opencv249\opencv\build\x64\vc11\bin

6) RESTART PC !!!!!

7) Open VS2012

8) Create new win32 console application empty project

9) Configure the release and debug to x64

10) Right click on the project -> Properties

11) C/C++ -> General:

D:\opencv249\opencv\build\include
D:\opencv249\opencv\build\include\opencv

12) Linker -> General:

D:\opencv249\opencv\build\x64\vc11\lib

13) Linker -> Input:

opencv_calib3d249.lib
opencv_contrib249.lib
opencv_features2d249.lib
opencv_flann249.lib
opencv_gpu249.lib
opencv_highgui249.lib
opencv_imgproc249.lib
opencv_legacy249.lib
opencv_ml249.lib
opencv_nonfree249.lib
opencv_objdetect249.lib
opencv_photo249.lib
opencv_stitching249.lib
opencv_superres249.lib
opencv_ts249.lib
opencv_video249.lib
opencv_videostab249.lib
opencv_core249.lib

NB: The ending 249 is the version of OpenCV

14) Sample code:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;
using namespace cv;

VideoCapture capture (0);
cv::Mat out; cv::Mat out2;

int main(int, char**)
{
namedWindow( "Edges", CV_WINDOW_NORMAL ); 
//CvCapture* capture = cvCaptureFromCAM(0);

for(;;) {
    //frame = cvQueryFrame( capture );
    Mat frame;
    capture >> frame;
    GaussianBlur( frame, out, Size(5, 5), 0, 0 );
    cvtColor( out ,out2, CV_BGR2GRAY ); // produces out2, a one-channel image (CV_8UC1)
   Canny( out2, out2, 100, 200, 3 ); // the result goes to out2 again,but since it is still one channel it is fine

   vector<vector<Point>> contours;

   findContours(out2, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
   drawContours(frame, contours, -1, Scalar(239,255,0), 2);

    //if( !frame.data ) break;
    imshow( "Edges", out2 );
    imshow( "Contours", frame );

    if(cv::waitKey(30) >= 0) break;
}
return 0;
}

15) Build or hit F5.

If all steps followed precisely, the sample code should work.