OpenCV


Introduction

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

Toggle line numbers

   1 version="$(wget -q -O - http://sourceforge.net/projects/opencvlibrary/files/opencv-unix | egrep -m1 -o '\"[0-9](\.[0-9])+' | cut -c2-)"
2 echo "Installing OpenCV" $version
3 mkdir OpenCV
4 cd OpenCV
5 echo "Removing any pre-installed ffmpeg and x264"
6 sudo apt-get -qq remove ffmpeg x264 libx264-dev
7 echo "Installing Dependenices"
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 echo "Downloading OpenCV" $version
10 wget -O OpenCV-$version.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/$version/opencv-"$version".zip/download
11 echo "Installing OpenCV" $version
12 unzip OpenCV-$version.zip
13 cd opencv-$version
14 mkdir build
15 cd build
16 cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..
17 make -j2
18 sudo checkinstall
19 sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
20 sudo ldconfig
21 echo "OpenCV" $version "ready to be used"
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.

Toggle line numbers

   1 $ chmod +x opencv.sh
2 $ ./opencv.sh
3

This will complete opencv installation

Running OpenCV

Python

Loading an image in Python

Toggle line numbers

   1 from cv2.cv import *
2
3 img = LoadImage("/home/USER/Pictures/python.jpg")
4 NamedWindow("opencv")
5 ShowImage("opencv",img)
6 WaitKey(0)
7
Toggle line numbers

   1 $ python filename.py
2

Note that the test program waits for a key press to end.

in C

Loading an image file in C

Toggle line numbers

   1 #include
2 #include<opencv2/highgui/highgui.hpp>
3
4 int main()
5 {
6 IplImage* img = cvLoadImage("/home/USER/Pictures/python.jpg",CV_LOAD_IMAGE_COLOR);
7 cvNamedWindow("opencvtest",CV_WINDOW_AUTOSIZE);
8 cvShowImage("opencvtest",img);
9 cvWaitKey(0);
10 cvReleaseImage(&img);
11 return 0;
12 }
13

To compile C program, Let’s assume the file is opencvtest.c

Toggle line numbers

   1 $ gcc -ggdb `pkg-config --cflags opencv` -o `basename opencvtest.c .c` opencvtest.c `pkg-config --libs opencv`
2 $ ./opencvtest
3

In C++

Loading an image file in C++

Toggle line numbers

   1 #include<opencv2/highgui/highgui.hpp>
2 using namespace cv;
3
4 int main()
5 {
6
7 Mat img = imread("/home/USER/Pictures/python.jpg",CV_LOAD_IMAGE_COLOR);
8 imshow("opencvtest",img);
9 waitKey(0);
10
11 return 0;
12 }
13

to compile in C++

Toggle line numbers

   1 $ g++ -ggdb `pkg-config --cflags opencv` -o `basename opencvtest.cpp .cpp` opencvtest.cpp `pkg-config --libs opencv`
2 $ ./opencvtest
3

Note: Always include OpenCV header files in C and C++ as

Toggle line numbers

   1 #include "opencv2/core/core_c.h"
2 #include "opencv2/core/core.hpp"
3 #include "opencv2/flann/miniflann.hpp"
4 #include "opencv2/imgproc/imgproc_c.h"
5 #include "opencv2/imgproc/imgproc.hpp"
6 #include "opencv2/video/video.hpp"
7 #include "opencv2/features2d/features2d.hpp"
8 #include "opencv2/objdetect/objdetect.hpp"
9 #include "opencv2/calib3d/calib3d.hpp"
10 #include "opencv2/ml/ml.hpp"
11 #include "opencv2/highgui/highgui_c.h"
12 #include "opencv2/highgui/highgui.hpp"
13 #include "opencv2/contrib/contrib.hpp"
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.

Toggle line numbers

   1 #!/bin/bash
2 echo "compiling $1"
3 if [[ $1 == *.c ]]
4 then
5 gcc -ggdb `pkg-config --cflags opencv` -o `basename $1 .c` $1 `pkg-config --libs opencv`;
6 elif [[ $1 == *.cpp ]]
7 then
8 g++ -ggdb `pkg-config --cflags opencv` -o `basename $1 .cpp` $1 `pkg-config --libs opencv`;
9 else
10 echo "Please compile only .c or .cpp files"
11 fi
12 echo "Output file => ${1%.*}"
13

Add an alias in .bashrc or .bash_aliases

Toggle line numbers

   1 $ alias opencv="~/.compile_opencv.sh"
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.

版权声明:本文博客原创文章,博客,未经同意,不得转载。

Opencv on Ubuntu (from Ubuntu)的更多相关文章

  1. 基于opencv网络摄像头在ubuntu下的视频获取

     基于opencv网络摄像头在ubuntu下的视频获取 1  工具 原料 平台 :UBUNTU12.04 安装库  Opencv-2.3 2  安装编译运行步骤 安装编译opencv-2.3  参 ...

  2. Ubuntu杂记——Ubuntu下用虚拟机共享上网

    由于最近把自己电脑环境换成了Ubuntu,但学校的网络是电信的闪讯,大学里用过的人都知道这货有多坑,而且没有Linux客户端,上网都是问题,怪不得国内用Linux的人那么少,特别是高校的学生(让我瞎逼 ...

  3. [Ubuntu]在Ubuntu下搭建自己的源服务器

    1.摘要     网上有很很多关于搭建源镜像的文章,但是对于一般人来讲,用不着镜像所有的deb包,只对我们能用到的感兴趣.另外,对于一些在Ubuntu的源中没有的软件,我们也可以放在我们自己的源里,这 ...

  4. vm12 安装ubuntu15.10详细图文教程 虚拟机安装ubuntu安装 ubuntu更新软件 ubuntu一直卡在下载语言怎么办?

    1,准备工作-ubuntu下载 ubuntu官网下载 如何官网下载ubuntu http://www.ubuntu.com/download/ 2,打开虚拟机 虚拟机安装ubuntu15.10 虚拟机 ...

  5. 【Ubuntu】Ubuntu设置和查看环境变量

    [Ubuntu]Ubuntu设置和查看环境变量    转载 https://blog.csdn.net/White_Idiot/article/details/78253004 1. 查看环境变量 查 ...

  6. ubuntu 18.04在更新软件库时出现E: Release file for http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease is not valid yet...

    1.完整的错误信息如下: E: Release file for http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease i ...

  7. [Ubuntu Setup] Ubuntu 13.04 安装 ia32-libs

    http://stackoverflow.com/questions/23182765/how-to-install-ia32-libs-in-ubuntu-14-04-lts sudo -i cd ...

  8. apt-get update --> Bad header line (fresh install) Ign http://archive.ubuntu.com natty-security/multiverse Sources/DiffIndex W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/natty/Rele

    apt-get update --> Bad header line (fresh install) fresh natty install i386 desktop. I get this e ...

  9. Ubuntu Err:1 http://us.archive.ubuntu.com/ubuntu bionic InRelease Could not resolve 'us.archive.ubuntu.com' 错误

    Ubuntu 更新 apt-get update 的时候 出现 Err: http://us.archive.ubuntu.com/ubuntu bionic InRelease Could not ...

  10. [转帖]【Ubuntu】Ubuntu 各版本代号简介

    [Ubuntu]Ubuntu 各版本代号简介 https://www.jianshu.com/p/7b351fde8799 一.版本及代号说明 Ubuntu中,每个版本都有一个更为特色的名字,这个名字 ...

随机推荐

  1. configure.ac:20: error: Autoconf version 2.65 or higher is required

    安装thrift例如,下面的问题出现: configure.ac:20: error: Autoconf version 2.65 or higher is required wget http:// ...

  2. Idea开发环境

    Idea开发环境中搭建Maven 1.配置Maven的环境变量 a.首先我们去maven官网下载Maven程序,解压到安装目录,如图所示: b.配置M2_HOME的环境变量,然后将该变量添加到Path ...

  3. 浅谈web网站架构演变过程(转)

    前言 我们以javaweb为例,来搭建一个简单的电商系统,看看这个系统可以如何一步步演变.   该系统具备的功能:   用户模块:用户注册和管理 商品模块:商品展示和管理 交易模块:创建交易和管理 阶 ...

  4. 【Android进阶】判断网络连接状态并自动界面跳转

    用于判断软件打开时的网络连接状态,若无网络连接,提醒用户跳转到设置界面 /** * 设置在onStart()方法里面,可以在界面每次获得焦点的时候都进行检测 */ @Override protecte ...

  5. ubuntu nginx安装及相关linux性能參数优化

    一.安装 下载源代码,解压:tar -xzvf nginx-1.4.7.tar.gz ./configure make && make install 改动默认nginx的监听port ...

  6. 每天进步一点点--&gt;函数fseek() 使用方法

    在阅读代码时,遇到了非常早之前用过的fseek(),非常久没实用了,有点陌生,写出来以便下次查阅. 函数功能是把文件指针指向文件的开头,须要包括头文件stdio.h fseek   函数名: fsee ...

  7. Kienct与Arduino学习笔记(2) 深度图像与现实世界的深度图的坐标

    转载请注明出处:http://blog.csdn.net/lxk7280 首先,要接触一下KinectOrbit这个摄像机库,这篇文章中有这个库的下载网址和简单的介绍:http://blog.csdn ...

  8. WebGL 在 OpenGL ES 指令 iOS 在 C 分歧版指令分析

    WebGL 中 OpenGL ES 指令与 iOS 中 C 版指令的差异简析 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途 ...

  9. 在SQL Server Management Studio中可以运行作业但是用T-SQL运行则失败

    原文:在SQL Server Management Studio中可以运行作业但是用T-SQL运行则失败 问题: 在SQL Server Management Studio中可以运行作业但是用T-SQ ...

  10. SpringMVC源代码深度分析DispatcherServlet核心的控制器(初始化)

    SpringMVC是非常优秀的MVC框架,每一个框架都是为了我们提高开发效率,我们试图通过对SpringMVC的源码去了解这个框架,了解整个设计思想,框架要有扩展性,这里用的比較多是接口和抽象,是框架 ...