歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

樹莓派 安裝 OpenCV 使用CMake 編譯工程 最新版2015

樹莓派 安裝 OpenCV 使用CMake 編譯工程 最新版2015

一、安裝make,cmake

sudo apt-get install make
sudo apt-get install cmake

二、下載deb包

去這裡下載libopencv_2.4.10.deb.zip(我不太好下載,折騰了好久最後是用手機流量才下載下來,電腦一直下載到一大半就停止不動了)

那個deb的作者還發了這個帖子,有問題可以去問

三、安裝deb包

解壓.deb.zip,復制到RPi上,到那個目錄裡,然後執行

sudo dpkg -i ./libopencv_2.4.10.deb

四、復制頭文件

下載OpenCV2.4.10 Windows版,在win下安裝,得到/build,/source目錄。復制/build/include/*到/usr/local/include

(假設/build/include/已經復制到RPi上的./目錄了)

sudo cp -r ./* /usr/local/include

說明一下deb和頭文件的關系:deb裡頭是一些.so(動態鏈接庫),在鏈接時用到;頭文件在編譯時用到。缺一不可。

五、安裝ffmpeg

可以先試試看不做這個步驟,反正我在安裝之前一直莫名其妙地報錯,說

/tmp/ccDC21Dx.o: In function `cv::Mat::~Mat()':
a.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x3c): undefined reference to `cv::fastFree(void*)'
/tmp/ccDC21Dx.o: In function `cv::Mat::release()':
a.cpp:(.text._ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x58): undefined reference to `cv::Mat::deallocate()'

安裝之後正常(不知道是不是這個原因)

sudo apt-get install ffmpeg

六、新建測試工程源碼

假設我們在目錄./下做這個工程

1.新建a.cpp,內容如下:(主要是看看Mat能否正常初始化和析構,可以的話基本上就沒問題了)

#include "opencv2/opencv.hpp"
using namespace cv;

int main(){
    Mat img;
    return 0;
}

2.新建CMakeLists.txt,內容如下:(這個文件名不可更改,用於cmake)

PROJECT(main)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
AUX_SOURCE_DIRECTORY(. DIR_SRCS)
ADD_EXECUTABLE(main ${DIR_SRCS})
TARGET_LINK_LIBRARIES(main opencv_core)
TARGET_LINK_LIBRARIES(main opencv_imgproc)
TARGET_LINK_LIBRARIES(main opencv_video)
TARGET_LINK_LIBRARIES(main opencv_highgui)
TARGET_LINK_LIBRARIES(main opencv_photo)
TARGET_LINK_LIBRARIES(main opencv_flann)
TARGET_LINK_LIBRARIES(main opencv_superres)
TARGET_LINK_LIBRARIES(main opencv_stitching)
TARGET_LINK_LIBRARIES(main opencv_ml)
TARGET_LINK_LIBRARIES(main opencv_video)
TARGET_LINK_LIBRARIES(main opencv_features2d)
TARGET_LINK_LIBRARIES(main opencv_calib3d)
TARGET_LINK_LIBRARIES(main opencv_objdetect)

七、編譯測試工程

1.編譯

mkdir ./build
cd ./build
cmake ..
make

如果沒有錯誤,就會產生如下輸出

pi@turtle ~/swap/proj $ mkdir build
pi@turtle ~/swap/proj $ cd ./build
pi@turtle ~/swap/proj/build $ cmake ..
-- The C compiler identification is GNU 4.6.3
-- The CXX compiler identification is GNU 4.6.3
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/swap/proj/build
pi@turtle ~/swap/proj/build $ make
Scanning dependencies of target main
[100%] Building CXX object CMakeFiles/main.dir/a.cpp.o
Linking CXX executable main
[100%] Built target main

2.運行

./main

應該如下:

pi@turtle ~/swap/proj/build $ ./main
pi@turtle ~/swap/proj/build $

對,確實沒有輸出,但是沒有報錯就是好事了,接下來就可以使用了!

--------------------------------------分割線 --------------------------------------

Ubuntu Linux下安裝OpenCV2.4.1所需包 http://www.linuxidc.com/Linux/2012-08/68184.htm

Ubuntu 12.04 安裝 OpenCV2.4.2 http://www.linuxidc.com/Linux/2012-09/70158.htm

CentOS下OpenCV無法讀取視頻文件 http://www.linuxidc.com/Linux/2011-07/39295.htm

Ubuntu 12.04下安裝OpenCV 2.4.5總結 http://www.linuxidc.com/Linux/2013-06/86704.htm

Ubuntu 10.04中安裝OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm

基於QT和OpenCV的人臉識別系統 http://www.linuxidc.com/Linux/2011-11/47806.htm

[翻譯]Ubuntu 14.04, 13.10 下安裝 OpenCV 2.4.9  http://www.linuxidc.com/Linux/2014-12/110045.htm

--------------------------------------分割線 --------------------------------------

OpenCV的詳細介紹:請點這裡
OpenCV的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved