20
BUILDING OPENCV 3.0.0 YOURSELF André Moreira June, 2014

Guide: How to Build OpenCV 3.0.0

Embed Size (px)

DESCRIPTION

A tutorial teaching how to build and use OpenCV v.3.0.0 using Visual Studio 2013.

Citation preview

Page 1: Guide: How to Build OpenCV 3.0.0

BUILDING OPENCV 3.0.0 YOURSELF

André MoreiraJune, 2014

Page 2: Guide: How to Build OpenCV 3.0.0

WHO I AM ...

# My name is André de Souza Moreira;

# Msc. Candidate at PUC-RIO;

# Researcher at Instituto Tecgraf in Computer Graphics;

# Before: Researcher at NCA in Medical Image Processing.

andredsm.com

Page 3: Guide: How to Build OpenCV 3.0.0

WHAT IS OPENCV?# It’s an open source library written in C++ for computer vision.# It was originally designed by Intel.# There are several bidings to others languagens like Python and Java.# Runs on Windows, Android, Linux, OS X and others.# Offers CUDA and OpenCL Interface.# Its last release version is 2.4.9 but you can acquire 3.0.0 version (under development) on

github (June, 2014).

Page 4: Guide: How to Build OpenCV 3.0.0

GOALS# Making a simple building of OpenCV 3.0.0 with Visual Studio 2013;# Running an OpenCV example;# Linking the library against a new project in Visual Studio 2013.

Page 5: Guide: How to Build OpenCV 3.0.0

BEFORE YOU BUILD

Page 6: Guide: How to Build OpenCV 3.0.0

Step :Get the Source Code# Available at https://github.com/Itseez/opencv

# Option 1: Download directly from the website

1

Page 7: Guide: How to Build OpenCV 3.0.0

Step :Get the Source COde# Option 2: Clone the git repository:

# The advantage of this method consists of tracking changes from the original repository. So, you can rebuild the library whenever there is a new feature...

1

$ git clone [email protected]:Itseez/opencv.git

Page 8: Guide: How to Build OpenCV 3.0.0

Step :Install dependencies# There are a lot dependencies you can use in opencv building, such as: Qt, Python, Opengl, pdflatex to generate the documentation, CUDA, OpenCL and others...

# For example, you can install the python 2.7.x and numpy in order to build python wrapper.

2

Page 9: Guide: How to Build OpenCV 3.0.0

# Install the Cmake Tool• Available on http://www.cmake.org/

# Open cmake-gui, configure where the library’s source code is (1) and where the project’s files will be generated (2). Finally, click in Configure button (3).

Step :Preparing the Project

3

(1)

(2)

(3)

Page 10: Guide: How to Build OpenCV 3.0.0

# Select the project that will be generated. • In our case is Visual Studio 2013. (No, I did not choose the wrong option, the

generator for Visual Studio 2013 is really called Visual Studio 12!) ;P

Step :Preparing the Project

3

Page 11: Guide: How to Build OpenCV 3.0.0

# Cmake will show you some build options:• BUILD: set what gonna be built.• WITH: The library takes advantage of others technologies like CUDA.• INSTALL: Which files will be put in the installation folder.• CMAKE/CMAKE_INSTAL_PREFIX: Set the default installation folder.

# After choosing, click Configure button

again. If everything is OK, all the red

background will disappear.

# Finally, click in the Generate button.

Step :Preparing the Project

3

Page 12: Guide: How to Build OpenCV 3.0.0

My Options:

Page 13: Guide: How to Build OpenCV 3.0.0

BUILDING THE PROJECT

Page 14: Guide: How to Build OpenCV 3.0.0

# Go to the build folder and open the Visual Studio Solution (Opencv.sln)# Select the build mode (1) and then build the project ALL_BUILD (2). (This step will build all

the projects shown in the Solution Explorer Guide)# If no errors occurs, build the INSTALL project (3). (Installs the artifacts)

Step :Building the Project

4

(1)

(2)

(3)

Page 15: Guide: How to Build OpenCV 3.0.0

# Copy all the .dll in {INSTALL_DIRECTORY} \x64\vc12\bin to:• C:\Windows\System32 if the library was built in x64• C:\Windows\SysWOW64 if the library was built in x86

# At this point, you can run any sample and it should works without error.

# Copy all files in {INSTALL_DIRECTORY} \x64\vc12\lib to {VISUALSTUDIO_DIRECTORY}\VC\lib (x86) or {VISUALSTUDIO_DIRECTORY}\VC\lib\amd64 (x64)

# Copy the two folders in {INSTALL_DIRECTORY} \include to {VISUALSTUDIO_DIRECTORY}\VC\include

Step :Installing the library

5

Page 16: Guide: How to Build OpenCV 3.0.0

RUN THE SAMPLES# You can run the examples from {INSTALL_DIRECTORY} \x64\vc12\samples\* and check if

everything is OK.• Running cpp\cpp-example-delaunay2.exe:

Page 17: Guide: How to Build OpenCV 3.0.0

Link Against the Library# Create a new project (CTRL+SHIFT+N).# Go to DEBUG > {projectName} Properties (Alt + F7)# List the modules’ name you need in Linker > Input > Additional Dependencies:

• Example:

Page 18: Guide: How to Build OpenCV 3.0.0

Link Against the Library# Create a cpp file (CTRL+SHIFT+A) and run it (CTRL+F5):

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

using namespace cv;

/** @function main */int main(int argc, char** argv){ Mat src, src_gray, dst; int kernel_size = 3; int scale = 1; int delta = 0; int ddepth = CV_16S; char* window_name = "Laplace Demo";

/// Load your image src = imread("myImage.jpg");

if (!src.data) { return -1; }

/// Remove noise by blurring with a Gaussian filter GaussianBlur(src, src, Size(3, 3), 0, 0, BORDER_DEFAULT);

/// Convert the image to grayscale cvtColor(src, src_gray, COLOR_RGB2GRAY);

/// Create window namedWindow(window_name, WINDOW_AUTOSIZE);

/// Apply Laplace function Mat abs_dst;

Laplacian(src_gray, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT); convertScaleAbs(dst, abs_dst);

/// Show what you got imshow(window_name, abs_dst);

waitKey(0);

return 0;}

Page 19: Guide: How to Build OpenCV 3.0.0

The Result

Ref: http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/laplace_operator/laplace_operator.html

Page 20: Guide: How to Build OpenCV 3.0.0

Need Help?# The Official Documentation:

• http://www.teste.com

# The Stackoverflow Community:• http://stackoverflow.com/questions/tagged/opencv

# OpenCV’s Install Guide:• http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_install/windows_install.html

# This Great Book: ;)

OpenCV Computer Vision Application Programming Cookbook (2nd Edition), Robert Laganiere.

ISBN-13: 9781782161486Publisher: Packt PublishingPublication date: 8/1/2014Pages: 390