1. 程式人生 > >ubuntu 平臺上 安裝 opencv實踐

ubuntu 平臺上 安裝 opencv實踐

install opencv on ubuntu 12.10

apt-get  install on shiyanlou 的速度?
apt-source ?
After this operation, 100 MB of additional disk space will be used.

step 1

setp 1.1 get opencv source

準備原始碼 opencv
Opencv的原始碼,2.4.9,90M左右
百度網盤連結:

或者類似方法

wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4
.2/OpenCV-2.4.2.tar.bz2 tar xvf OpenCV-2.4.2.tar.bz2

step 1.2 install build-essential

build-essential 軟體包,涵蓋gcc/g++/gdb/make

    sudo apt-get install build-essential  

step 1.3 install pakcage about multi-media

支援讀寫圖片以及視訊等,about 100MB

    sudo apt-get install  libgtk2.0-dev libavcodec-dev libavformat-dev
libtiff4-dev libswscale-dev libjasper-dev

step 1.4 install cmake

編譯,大小10M左右

sudo apt-get install cmake

step 1.5 install pkg-config

pkg-config,它是一個提供從原始碼中編譯軟體時查詢已安裝的庫時使用的統一介面的計算機軟體。

sudo apt-get install pkg-config  

二、編譯安裝過程

2.1 環境監測:

使用cmake來檢測編譯環境以及生成makefile以及其他project資訊,在使用cmake過程可以設定一些引數。

在本目錄下(opencv原始碼目錄)使用cmake,注意後面的點表示在當前目錄下尋找CMakeLists.txt。

    cmake .  

結果簡略如下:

   ...
-- Configuring done
-- Generating done
-- Build files have been written to: /media/sda_m/opencv-2.4.9

2.2 使用make編譯

耗時間20分鐘,下一步試試有沒有已經編譯好的bin檔案

make  

正確編譯結果是:

[100%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade.dir/traincascade.cpp.o
[100%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade.dir/cascadeclassifier.cpp.o
[100%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade.dir/boost.cpp.o
[100%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade.dir/features.cpp.o
[100%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade.dir/haarfeatures.cpp.o
[100%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade.dir/lbpfeatures.cpp.o
[100%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade.dir/HOGfeatures.cpp.o
[100%] Building CXX object apps/traincascade/CMakeFiles/opencv_traincascade.dir/imagestorage.cpp.o
Linking CXX executable ../../bin/opencv_traincascade

2.3 使用make install 安裝

sudo make install  

正確的結果提示是:

...
-- Set runtime path of "/usr/local/bin/opencv_haartraining" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_createsamples
-- Set runtime path of "/usr/local/bin/opencv_createsamples" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_performance
-- Set runtime path of "/usr/local/bin/opencv_performance" to "/usr/local/lib"
-- Installing: /usr/local/bin/opencv_traincascade
-- Set runtime path of "/usr/local/bin/opencv_traincascade" to "/usr/local/lib"

2.4 新增動態庫資訊

在檔案/etc/ld.so.conf中新增 /usr/local/lib(這個跟安裝目錄有關, {CMAKE_INSTALL_PREFIX}/lib),
也可以在/etc/ld.so.conf.d 目錄下增加一個conf檔案(可以命名為 opencv.conf),同樣新增 /usr/local/lib

檢視已經生成的動態庫
[email protected]:/usr/local/lib# ls
libopencv_calib3d.so           libopencv_gpu.so            libopencv_nonfree.so          libopencv_superres.so
libopencv_calib3d.so.2.4       libopencv_gpu.so.2.4        libopencv_nonfree.so.2.4      libopencv_superres.so.2.4
libopencv_calib3d.so.2.4.9     libopencv_gpu.so.2.4.9      libopencv_nonfree.so.2.4.9    libopencv_superres.so.2.4.9
libopencv_contrib.so           libopencv_highgui.so        libopencv_objdetect.so        libopencv_ts.a
libopencv_contrib.so.2.4       libopencv_highgui.so.2.4    libopencv_objdetect.so.2.4    libopencv_video.so
libopencv_contrib.so.2.4.9     libopencv_highgui.so.2.4.9  libopencv_objdetect.so.2.4.9  libopencv_video.so.2.4
libopencv_core.so              libopencv_imgproc.so        libopencv_ocl.so              libopencv_video.so.2.4.9
libopencv_core.so.2.4          libopencv_imgproc.so.2.4    libopencv_ocl.so.2.4          libopencv_videostab.so
libopencv_core.so.2.4.9        libopencv_imgproc.so.2.4.9  libopencv_ocl.so.2.4.9        libopencv_videostab.so.2.4
libopencv_features2d.so        libopencv_legacy.so         libopencv_photo.so            libopencv_videostab.so.2.4.9
libopencv_features2d.so.2.4    libopencv_legacy.so.2.4     libopencv_photo.so.2.4        pkgconfig
libopencv_features2d.so.2.4.9  libopencv_legacy.so.2.4.9   libopencv_photo.so.2.4.9      python2.7
libopencv_flann.so             libopencv_ml.so             libopencv_stitching.so
libopencv_flann.so.2.4         libopencv_ml.so.2.4         libopencv_stitching.so.2.4
libopencv_flann.so.2.4.9       libopencv_ml.so.2.4.9       libopencv_stitching.so.2.4.9

使用下面的動態庫管理命令ldconfig,讓opencv的相關連結庫被系統共享

    sudo ldconfig -v  

如果成功的話,我的檢測方法如下,正確的結果將會發現前面動態庫的名字

sudo ldconfig -v >temp.so.txt && cat temp.so.txt|grep opencv

2.5 指定標頭檔案位置

完成了動態庫的共享,還不能使用opencv來程式設計,還需要為程式指定openvc的標頭檔案位置。這裡使用pkg-config命令來完成。首先在 /etc/profile 中新增

export  PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig  

pkg-config 維護著一個關於opencv的配置檔案,這個檔案(opencv.pc)在目錄 /usr/local/lib/pkgconfig,這個檔案記錄著opencv的一些動態庫資訊,還有標頭檔案資訊

輸入pkg-config –cflags opencv 和pkg-config –libs opencv ,可以發現以下資訊。

正確的結果是如下:

[email protected]:/usr/local/lib# pkg-config --cflags opencv
-I/usr/local/include/opencv -I/usr/local/include 


[email protected]:/usr/local/lib# pkg-config --libs opencv


/usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_ocl.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so -lrt -lpthread -lm -ldl 

3 測試

編譯sample

在解壓的opencv目錄下找到 samples/c/build_all.sh,執行該檔案

[email protected]:/media/sda_m/opencv-2.4.9/samples/c$ ./build_all.sh 
compiling contours.c
compiling convert_cascade.c
compiling delaunay.c
compiling fback_c.c
compiling morphology.c
compiling motempl.c
compiling polar_transforms.c
compiling pyramid_segmentation.c
compiling adaptiveskindetector.cpp
compiling bgfg_codebook.cpp
compiling blobtrack_sample.cpp
compiling facedetect.cpp
compiling find_obj.cpp
compiling find_obj_calonder.cpp
compiling find_obj_ferns.cpp
compiling latentsvmdetect.cpp
compiling mser_sample.cpp
compiling mushroom.cpp
compiling one_way_sample.cpp
compiling smiledetect.cpp
compiling tree_engine.cpp

list all the executive

find . -perm /u=x,g=x,o=x

結果是

.
./find_obj_calonder  #?
./adaptiveskindetector #?
./delaunay #ok

./facedetect #ok
./mser_sample #?
./blobtrack_sample #?
./one_way_sample #?
./latentsvmdetect  #ok
./tree_engine #?
./bgfg_codebook #?
./motempl #?
./fback_c #?
./polar_transforms #?
./contours #ok
./find_obj #Ok 
./smiledetect #ok
./mushroom #?
./convert_cascade  #?
./morphology #ok
./pyramid_segmentation #ok
./find_obj_ferns   #?

期中末尾表示為 #?是當前不知道作用的,其他的ok都有結果的

example find object


smile detect

face detect

動態的 delaunay 三角+ voronoi分割

This program demostrates iterative construction of
delaunay triangulation and voronoi tesselation.
It draws a random set of points in an image and then delaunay triangulates them.

有趣 morphology

fail example

find_obj_ferns

./find_obj_ferns box.png box_in_scene.png 

This program shows the use of the "fern" plannar PlanarObjectDetector point
descriptor classifier
Usage:
./find_obj_ferns <object_filename> <scene_filename>, default: box.png and box_in_scene.png

Trying to load box.png_model.xml.gz ...
The file not found and can not be read. Let's train the model.
Step 1. Finding the robust keypoints ...

adaptiveskindetector

需要一個照片序列

./adaptiveskindetector

This program demonstrates the contributed flesh detector CvAdaptiveSkinDetector which can be found in contrib.cpp
Usage: 
./adaptiveskindetector fileMask firstFrame lastFrame

Example: 
./adaptiveskindetector C:\VideoSequences\sample1\right_view\temp_%05d.jpg  0  1000
   iterates through temp_00000.jpg  to  temp_01000.jpg

find_obj_calonder:Calonder point descriptor classifierSURF

./find_obj_calonder
This program shows the use of the Calonder point descriptor classifierSURF is used to detect interest points, Calonder is used to describe/match these points
Format:
   classifier_file(to write) test_image file_with_train_images_filenames(txt)   or
   classifier_file(to read) test_image

others

  • blobtrack_sample 輸入未知

  • one_way_sample 2 photo need

  • tree_engine

  • /bgfg_codebook

Learn background and find foreground using simple average and average difference learning method:
Originally from the book: Learning OpenCV by O'Reilly press

檢視example下面的圖片

 ll *.jpg
eog 檢視下面的圖片

小結

搭建環境
玩玩example
找到興趣方向

  • 動態的 delaunay 三角+ voronoi分割

參考

windows install

參考 淺墨

get sample

form git or pan

error 1:    error C1083: 無法開啟包括檔案:“opencv2/opencv.hpp”: 

vc++目錄
- include
- include
- opencv2
- opencv
- lib
- linker input
- opencv_core248d.lib
- opencv_imgproc248d.lib
- opencv_highgui248d.lib

error 2: 丟失opencv_core*.dll

至此,環境變數在裡面,但是竟然一直找不到。只有使用蠻力法,全部拷貝

相關推薦

ubuntu 平臺 安裝 opencv實踐

install opencv on ubuntu 12.10 apt-get install on shiyanlou 的速度? apt-source ? After this operation, 100 MB of additional dis

ubuntu系統安裝多個版本的opencv 程式使用具體版本的方法

然而有的時候可能一臺ubuntu系統中安裝了多個版本的opencv,這是就可能出現上述問題。 解決方法:在CMake.txt配置時注意呼叫FIND_PACKAGE( OpenCV 2.4 REQUIRED )

Ubuntu安裝OpenCV

一、安裝 1、從原始碼進行安裝OpenCV的官網 Releases版本中下載最新版本。(官網地址:https://opencv.org/)           2、選擇原始碼下載,將其解壓到 opencv3資料夾中。

learn opencv-Ubuntu(cuda)安裝深度學習框架

在帶有CUDA支援的Ubuntu上安裝深度學習框架 在本文中,我們將學習如何在具有NVIDIA圖形卡的機器上安裝TensorFlow,Theano,Keras和PyTorch等深度學習框架。 如果你有一個全新的顯示卡的計算機,你不知道什麼樣的庫來

關於在RK3288安裝Opencv的方法

pda zip 依賴項 all fig 準備 for 固件 namespace Opencv是一個開源的計算機視覺庫,可以給開發人員提供更便捷的方式設計復雜的視覺應用,Opencv主要是用c和c++編寫,可以運行在Windows/Linux/Mac等上。這幾天嘗試著在RK3

Linux平臺安裝MySQL服務

table 校驗 運行 put statement procs 可靠 commands 系列 MySQL服務是一個真正的多線程、多用戶的SQL數據庫服務,憑借其高性能、高可靠和易於使用的特性,成為服務器領域中最受歡迎的開源數據庫系統。為了確保MySQL數據庫功能的完整性。可

在Linux(CentOS、Debian、Ubuntu等)安裝Netdata

required bsp ram ins 默認 src 維護 ip地址 ash Netdata是一個免費的、開放源碼的實時監控工具,它是一個主動維護的、易於安裝的、可以使用web瀏覽器訪問的漂亮的儀表板UI。使用Netdata,您可以輕松地實時監視您的Vultr實例的每

Ubuntu 16.04 安裝OpenCV 3.4.3

iba get 2.0 avcodec 依賴庫 4.3 build cmake efi 1.準備依賴庫 [編譯] sudo apt-get install build-essential [必需] sudo apt-get install cmake git libgtk

ubuntu伺服器安裝tomcat 9

前提條件: 確保ubuntu伺服器上 已經安裝 java 8 或更高版本,安裝java8可以參考我的另一篇博文 通過 ppa 在ubuntu server 上安裝java 8 java -version java version "1.8.0_191"Java(TM) SE Runt

Ubuntu 16.04 安裝opencv 3.2

1.安裝依賴庫 sudo apt-get install build-essential sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libsw

Ubuntu14.04安裝記錄(專用2) ubuntu下解除安裝opencv

6.安裝Ceres庫由於按照書上出現了“E未發現軟體包liblpack-dev的錯誤”,故另參考流程如下https://blog.csdn.net/felaim/article/details/60138647安裝g2o庫7.編譯安裝VTK庫(筆者使用的系統是Ubuntu14.04,為保險起見安裝的

Ubuntu 16.04 安裝opencv的各種方法(含opencv contrib擴充套件包安裝方法)

C++介面安裝 採用原始碼編譯的安裝方式,基本也就是這種方法了,首先在官網下載你想安裝的版本的opencv壓縮包,下載連線如下: https://github.com/opencv/opencv/releases 首先,安裝一些依賴,根據自己的情況選擇,如果不知道自己安裝

ubuntu機器安裝環境重點注意事項

  環境:Ubuntu 16.04.4 1.新增download使用者 sudo adduser download 2.修改主機名(不修改,修改後需要重啟機器) Sudo vi hostname 3.修改sudo免密碼 sudo vi /etc/sudoers 配置中新增downlo

ubuntu機器安裝環境重點註意事項

新的 ssh免密碼 java 註意 模塊 www .net libmysql 6.0 環境:Ubuntu 16.04.4 1.添加download用戶 sudo adduser download 2.修改主機名(不修改,修改後需要重啟機器) Sudo vi hostna

Ubuntu 系統安裝Mysql 遇到的問題小結

``問題一:ERROR 1698 (28000): Access denied for user ‘root’@'localhost 該問題是沒有設定登入密碼; 1. sudo mysql -u root ; #進入安全模式設定密碼 2. 進入資料庫中新增使用

ubuntu server安裝Hadoop步驟

1. Java安裝: Because everything work with java. $ sudo apt-get install openjdk-7-jdk 安裝之後,可以檢視java的版本資訊: [email protected]:~$ java -version java version

在Ubuntu18.04安裝opencv 3.4.1

對於安裝opencv有的人一次就成功,而有人安裝了N多次才成功。我就是那個安裝了N多次的人,每次遇到了很多安裝錯誤,只能通過到網上搜教程資料,解決方法;通過一次次的試錯,最終完成了安裝。再此提醒第一次安裝或則安裝失敗沒有頭緒的小夥伴,請注重官方安裝教程: https://docs.opencv.org/ma

Linux系統安裝opencv-3.3.0

原文連結:https://blog.csdn.net/u011195662/article/details/78403366 注意一定要先安裝gtk再安裝opencv,否則程式會報錯! 原始碼編譯時出現的問題: 原文連結:https://blog.csdn.net/farmwang/ar

如何在mac安裝opencv與python

OpenCV全稱是:Open Source Computer Vision Library。是一個基於BSD許可發行的跨平臺機器視覺庫,由一系列C函式和少量的C++類構成,同時提供Python、Ruby、MATLAB等語言的介面,實現了影象處理和計算機視覺方面的很多通用演算法。 如題,我們將

在樹莓派安裝OpenCV-Python

在樹莓派上安裝OpenCV-Python 以下安裝的是python3下的opencv 如果是安裝python2的CV 直接執行 sudo apt-get install opencv-python 這個文章有相當強的時效性,我用的映象是官方18-06-27的映象,如果有如