OpenCV (open source computer vision) is>
OpenCV is the most popular and advanced code library for Computer Vision> INSTALLATIONMany people are having problem with installing OpenCV even from Ubuntu Software Centre. Here a simple .sh script file get all dependancy files from internet and compile the source finally install opencv on your system. So that users can easily write their CV files from C,C++, and Python.
Step1:
Download the latest opencv.sh from https://github.com/jayrambhia/Install-OpenCV/blob/master/Ubuntu/or Copy the following script to gedit and save as opencv.sh
version="$(wget -q -O - http://sourceforge.net/projects/opencvlibrary/files/opencv-unix | egrep -m1 -o '\"[0-9](\.[0-9])+' | cut -c2-)"
echo "Installing OpenCV" $version
}
To compile C program, Let’s assume the file is opencvtest.c
$ gcc -ggdb pkg-config --cflags opencv -o basename opencvtest.c .c opencvtest.c pkg-config --libs opencv$ ./opencvtest In C++
=== Loading an image file in C++ ==
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
int main()
{
Mat img = imread("/home/USER/Pictures/python.jpg",CV_LOAD_IMAGE_COLOR);
imshow("opencvtest",img);
waitKey(0);
return 0;
}
to compile in C++ $ g++ -ggdb pkg-config --cflags opencv -o basename opencvtest.cpp .cpp opencvtest.cpp pkg-config --libs opencv$ ./opencvtest
Note: Always include OpenCV header files in C and C++ as
#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/flann/miniflann.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
A bash script to compile opencv programs.Making a Bash Script to Compile OpenCV:
It’s kind of boring typing all this stuff. So, A bash file to compile OpenCV programs. Name it .compile_opencv.sh and keep it in your home directory.
echo "compiling $1"
if [[ $1 == *.c ]]