OpenCV (open source computer vision) is released under a BSD license and hence it’s free for both academic and commercial use. It has C++, C, Python and Java interfaces and supports Ubuntu Linux. OpenCV was designed for computational efficiency and with a strong focus on real-time applications.
OpenCV is the most popular and advanced code library for Computer Vision related applications today, spanning from many very basic tasks (capture and pre-processing of image data) to high-level algorithms (feature extraction, motion tracking, machine learning). It is free software and provides a rich API in C, C++, Java and Python. Other wrappers are available. The library itself is platform-independent and often used for real-time image processing and computer vision.
Installation
Many 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
Step 1
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
2 $version 3 mkdir OpenCV 4 cd OpenCV 5 6 sudo apt-get -qq remove ffmpeg x264 libx264-dev 7 8 sudo apt-get -qq install libopencv-dev build-essential checkinstall cmake pkg-config yasm libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils ffmpeg 9 $version 10 .zip/download 11 $version 12 $version.zip 13 $version 14 mkdir build 15 cd build 16 WITH_OPENGL=ON .. 17 make -j2 18 sudo checkinstall 19 20 sudo ldconfig 21 22
Note: If you are running 13.10 and you don't have a nvidia card then ensure you install ocl-icd-libopencl1 (sudo apt-get install ocl-icd-libopencl1) before running this script. Ubuntu 13.10 will install nvidia-319-updates as a dependency for libopencv-dev by default if ocl-icd-libopencl1 is not installed (see bug report).
Step 2
Open terminal.
$ chmod +x opencv.sh 2 $ ./opencv.sh 3
This will complete opencv installation
Running OpenCV
Python
Loading an image in Python
import * 2 3 ) 4 ) 5 img) 6 0) 7
$ python filename.py
2
Note that the test program waits for a key press to end.
in C
Loading an image file in C
2 3 4 main() 5 { 6 CV_LOAD_IMAGE_COLOR); 7 CV_WINDOW_AUTOSIZE); 8 img); 9 0); 10 img); 11 0; 12 } 13
To compile C program, Let’s assume the file is opencvtest.c
` 2 $ ./opencvtest 3
In C++
Loading an image file in C++
2 cv; 3 4 main() 5 { 6 7 CV_LOAD_IMAGE_COLOR); 8 img); 9 0); 10 11 0; 12 } 13
to compile in C++
` 2 $ ./opencvtest 3
Note: Always include OpenCV header files in C and C++ as
2 3 4 5 6 7 8 9 10 11 12 13 14
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.
#!/bin/bash
2
3 $1 == *.c ]]
4 then
5 `;
6 $1 == *.cpp ]]
7 then
8 `;
9 else
10
11 fi
12
13
Add an alias in .bashrc or .bash_aliases
2 $ opencv opencvtest.c 3 $ ./opencvtest 4
Note that the .bashrc is a hidden file. Do not include the '$' characters at the beginning of each line. The alias will work after you log out and back. You can type the alias opencv... command at the prompt to set the alias for the current session.
版权声明:本文博客原创文章,博客,未经同意,不得转载。