0% found this document useful (0 votes)
22 views3 pages

Open CVNN

N

Uploaded by

Cristian Garcia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

Open CVNN

N

Uploaded by

Cristian Garcia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Instalación de OpenCV

http://www.codebind.com/cpp-tutorial/install-opencv-ubuntu-cpp/

OpenCV is an image processing library created by Intel and later supported by Willow Garage
and now maintained by Itseez. OpenCV means Intel® Open Source Computer Vision Library.
It is a collection of C functions and a few C++ classes that implement some popular Image
Processing and Computer Vision algorithms. OpenCV is Available on Mac, Windows, Linux
(Terminal environment).

Step 1 – Updating Ubuntu


$ sudo apt-get update

$ sudo apt-get upgrade

Step 2 – Install dependencies


$ sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-
config libavcodec-dev libavformat-dev libswscale-dev

$ sudo apt-get install python3.9-dev python3-numpy libtbb2 libtbb-dev

$ sudo apt-get install libjpeg-dev libpng-dev libtiff5-dev libdc1394-


22-dev libeigen3-dev libtheora-dev libvorbis-dev libxvidcore-dev
libx264-dev sphinx-common libtbb-dev yasm libfaac-dev libopencore-
amrnb-dev libopencore-amrwb-dev libopenexr-dev libgstreamer-plugins-
base1.0-dev libavutil-dev libavfilter-dev libavresample-dev

Step 3 – Get OpenCV


$ sudo -s

# cd /opt

# git clone https://github.com/Itseez/opencv.git

# git clone https://github.com/Itseez/opencv_contrib.git

Step 4 – build and install OpenCV


/opt# cd opencv
/opt/opencv# mkdir release

/opt/opencv# cd release

/opt/opencv/release# cmake -D BUILD_TIFF=ON -D WITH_CUDA=OFF -D


ENABLE_AVX=OFF -D WITH_OPENGL=OFF -D WITH_OPENCL=OFF -D WITH_IPP=OFF
-D WITH_TBB=ON -D BUILD_TBB=ON -D WITH_EIGEN=OFF -D WITH_V4L=OFF -D
WITH_VTK=OFF -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D
CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D
OPENCV_EXTRA_MODULES_PATH=/opt/opencv_contrib/modules /opt/opencv/

/opt/opencv/release # make -j4

/opt/opencv/release# make install

/opt/opencv/release# ldconfig

/opt/opencv/release# exit

/opt/opencv/release$ cd ~

sudo apt-get install libopencv-dev

Create a C++ program

Follow the commands

$ mkdir cpp_test

$ cd cpp_test

$ touch main.cpp

The above command will create a folder called cpp_test and create a main.cpp file inside it
Now place any .jpeg image inside the cpp_test folder.
So Now your cpp_test folder will contain two files as follows
.
├── sample.jpeg
└── main.cpp

Now open the main.cpp and add the following code

//Uncomment the following line if you are compiling this code in Visu
al Studio
//#include "stdafx.h"

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;

int main(int argc, char** argv)


{
// Read the image file
//Mat image = imread("sample.jpeg");
Mat image = imread("sample.jpeg", IMREAD_GRAYSCALE );//Imagen en esc
ala de grises

// Check for failure


if (image.empty())
{
cout << "Could not open or find the image" << endl;
cin.get(); //wait for any key press
return -1;
}

String windowName = "Prueba"; //Name of the window

//namedWindow(windowName); // Create a window


namedWindow(windowName, WINDOW_NORMAL); //Ventana redimensionable

imshow(windowName, image); // Show our image inside the created wind


ow.

waitKey(0); // Wait for any keystroke in the window

destroyWindow(windowName); //destroy the created window

return 0;
}

Now compile your code with the following command


g++ main.cpp -o output `pkg-config --cflags --libs opencv4`

Now run the C++ program with the following command

$ ./output

press ESC to exit

You might also like