opencv Installation in Linux and hello world
http://opencv.org/quickstart.html
Installation in Linux
These steps have been tested for Ubuntu 10.04 but should work with other distros as well.
Required Packages
- GCC 4.4.x or later
- CMake 2.8.7 or higher
- Git
- GTK+2.x or higher, including headers (libgtk2.0-dev)
- pkg-config
- Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
- ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
- [optional] libtbb2 libtbb-dev
- [optional] libdc1394 2.x
- [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev
The packages can be installed using a terminal and the following commands or by using Synaptic Manager:
[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
Getting OpenCV Source Code
You can use the latest stable OpenCV version or you can grab the latest snapshot from our Git repository.
Getting the Latest Stable OpenCV Version
- Go to our downloads page.
- Download the source archive and unpack it.
Getting the Cutting-edge OpenCV from the Git Repository
Launch Git client and clone OpenCV repository. If you need modules from OpenCV contrib repository then clone it too.
For example
cd ~/<my_working_directory>
git clone https://github.com/Itseez/opencv.git
git clone https://github.com/Itseez/opencv_contrib.git
Building OpenCV from Source Using CMake
Create a temporary directory, which we denote as <cmake_build_dir>, where you want to put the generated Makefiles, project files as well the object files and output binaries and enter there.
For example
cd ~/opencv
mkdir build
cd buildConfiguring. Run cmake [<some optional parameters>] <path to the OpenCV source directory>
For example
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
or cmake-gui
- set full path to OpenCV source code, e.g. /home/user/opencv
- set full path to <cmake_build_dir>, e.g. /home/user/opencv/build
- set optional parameters
- run: “Configure”
- run: “Generate”
Description of some parameters
- build type: CMAKE_BUILD_TYPE=Release\Debug
- to build with modules from opencv_contrib set OPENCV_EXTRA_MODULES_PATH to <path to opencv_contrib/modules/>
- set BUILD_DOCS for building documents
- set BUILD_EXAMPLES to build all examples
[optional] Building python. Set the following python parameters:
- PYTHON2(3)_EXECUTABLE = <path to python>
- PYTHON_INCLUDE_DIR = /usr/include/python<version>
- PYTHON_INCLUDE_DIR2 = /usr/include/x86_64-linux-gnu/python<version>
- PYTHON_LIBRARY = /usr/lib/x86_64-linux-gnu/libpython<version>.so
- PYTHON2(3)_NUMPY_INCLUDE_DIRS = /usr/lib/python<version>/dist-packages/numpy/core/include/
[optional] Building java.
- Unset parameter: BUILD_SHARED_LIBS
- It is useful also to unset BUILD_EXAMPLES, BUILD_TESTS, BUILD_PERF_TESTS - as they all will be statically linked with OpenCV and can take a lot of memory.
Build. From build directory execute make, recomend to do it in several threads
For example
make -j7 # runs 7 jobs in parallel
[optional] Building documents. Enter <cmake_build_dir/doc/> and run make with target “html_docs”
For example
cd ~/opencv/build/doc/
make -j7 html_docsTo install libraries, from build directory execute
sudo make install
[optional] Running tests
- Get the required test data from OpenCV extra repository.
For example
git clone https://github.com/Itseez/opencv_extra.git
- set OPENCV_TEST_DATA_PATH environment variable to <path to opencv_extra/testdata>.
- execute tests from build directory.
For example
<cmake_build_dir>/bin/opencv_test_core
Note
If the size of the created library is a critical issue (like in case of an Android build) you can use the install/strip command to get the smallest size as possible. The stripped version appears to be twice as small. However, we do not recommend using this unless those extra megabytes do really matter.
Using OpenCV with gcc and CMake
Note
We assume that you have successfully installed OpenCV in your workstation.
- The easiest way of using OpenCV in your code is to use CMake. A few advantages (taken from the Wiki):
- No need to change anything when porting between Linux and Windows
- Can easily be combined with other tools by CMake( i.e. Qt, ITK and VTK )
- If you are not familiar with CMake, checkout the tutorial on its website.
Steps
Create a program using OpenCV
Let’s use a simple program such as DisplayImage.cpp shown below.
#include <stdio.h>
#include <opencv2/opencv.hpp> using namespace cv; int main(int argc, char** argv )
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
} Mat image;
image = imread( argv[1], 1 ); if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image); waitKey(0); return 0;
}
Create a CMake file
Now you have to create your CMakeLists.txt file. It should look like this:
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
Generate the executable
This part is easy, just proceed as with any other project using CMake:
cd <DisplayImage_directory>
cmake .
make
Result
By now you should have an executable (called DisplayImage in this case). You just have to run it giving an image location as an argument, i.e.:
./DisplayImage lena.jpg
You should get a nice window as the one shown below:
opencv Installation in Linux and hello world的更多相关文章
- OpenCV installation on Linux
Getting the Cutting-edge OpenCV from the Git Repository Launch Git client and clone OpenCV repositor ...
- 【转】Installing OpenCV on Debian Linux
In this post I will describe the process of installing OpenCV(both versions 2.4.2 and 2.4.3) on Debi ...
- Apache Tomcat 9 Installation on Linux (RHEL and clones)
Apache Tomcat 9 is not available from the standard RHEL distributions, so this article provides info ...
- Domino Server installation on Linux (Centos or Redhat) – something somewhere
something somewhere welcome in there…:) Just another techki site howto / Linux / Lotus Domino 0 Domi ...
- opencv 4.0 + linux下静态编译,展示详细ccmake的参数配置
#先安装 cmake 3.14 # cmake安装到了 /usr/local/bin #配置PATH export PATH="$PATH:/usr/local/bin" #下载最 ...
- 【opencv基础】OpenCV installation stuck at [ 98%] Built target opencv_perf_stitching with no error
前言 按照官网步骤安装opencv的过程中进行到98%时一直没有继续进行. 原因 后台一直在编译运行,只需等待即可,参考here: well, turns out it gets stuck for ...
- 【opencv基础】linux系统opencv以及opencv_contrib的安装与使用
前言 本文主要介绍如何在linux系统安装使用opencv. 具体步骤可参考opencv官网here. 步骤 编译源码之前需要安装相关依赖库: 1.下载源码: 2.解压源码: 3.配置cmake: 注 ...
- opencv 4.0 + linux + cuda静态编译
#下载最新的opencv git clone "https://github.com/opencv/opencv.git" git clone "https://gith ...
- Sublime 2 Installation for Linux
Linux You can download the package and uncompress it manually. Alternatively, you can use the comman ...
随机推荐
- #添加屏蔽IP LINUX
netfilter/iptables 的最大优点是它可以配置有状态的防火墙,这是 ipfwadm 和 ipchains 等以前的工具都无法提供的一种重要功能.有状态的防火墙能够指定并记住为发送或接收信 ...
- localstorage 使用
localstorage作为HTML5的一个特殊属性,在发布时就备受关注:最近总结了其一些小的用法,希望可以抛砖引玉. 因HTML5本地存储只能存字符串,所以所有数据存储的话,都要转化成字符串:而js ...
- SQL Server中count(*), count(col), count(1)的对比
让我们先看一下BOL里面对count(*)以及count(col)的说明: COUNT(*) 返回组中的项数.包括 NULL 值和重复项. COUNT(ALL expression) 对组中的每一行都 ...
- 《Excel图表之道》读书笔记
一.突破常规的作图方法 突破Excel的默认颜色 非数据元素用淡色 突破Excel的图表布局 图表要素:主标题.副标题.图例.绘图.脚注 竖向构图 标明数据来源.图表注释.坐标轴截断符号 专业的水蓝色 ...
- C++版 Chip8游戏模拟器
很早就想写个FC模拟器,但真是一件艰难的事情.. 所以先写个Chip8模拟器,日后再继续研究FC模拟器. Chip8只有35条指令,属于RISC指令集,4k内存,2k显存,16个寄存器(其中15个通用 ...
- C# 中经常用到的HTTP请求类,已封装get,post,delete,put
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...
- BOM的来源是不可能出现的字符,GB2312双字节高位都是1,Unicode理论的根本缺陷导致UTF8的诞生
Unicode字符编码规范 http://www.aoxiang.org 2006-4-2 10:48:02Unicode是一种字符编码规范 . 先从ASCII说起.ASCII是用来表示英文字符的 ...
- Tabhost嵌套以及Tab中多个Activity跳转的实现
做了一个demo,先看看效果图: 源码 如下: () DoubleTabHost package yy.android.tab; import android.app.TabActivity; imp ...
- 水平/竖直居中在旧版Safari上的bug
今天调了两个出现在旧版Safari上的layout bug. 它们最初是在同事的iPad上被发现的, 我在自己桌面上安装的Safari 5.1.7上也能够复现. Bug1: .vertical-cen ...
- Android ActivityManagerService 基本构架详解
学习AmS有段时日了,总结下,也好梳理一下自己的思路.小兵一个,有些地方理解不对,大家可以互相讨论,交流才有进步吗~~~ AmS可以说是Android上层系统最核心的模块之一,其主要完成管理应用进程的 ...