Raspberry Pi3 編譯openCV 2

Raspberry Pi3 編譯openCV 2

$sudo apt-get install build-essential cmake cmake-curses-gui pkg-config libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev zlib1g-dbg zlib1g zlib1g-dev pngtools libtiff5-dev libtiff4 libtiffxx0c2 libtiff-tools libeigen3-dev

 

$mkdir ~/Desktop/opencv2

$ cd ~/Desktop/opencv2

$wget https://github.com/Itseez/opencv/archive/2.4.13.zip

$unzip 2.4.13.zip

screen-shot-2016-12-02-at-5-17-50-pm

$cd opencv-2.4.13
$mkdir release
$cd release
$ ccmake ../
screen-shot-2016-12-02-at-5-31-25-pm

修改完後,按下「c」設定新的選項,然後再按下「g」即可產生編譯用的設定檔案。

$ make -j4

screen-shot-2016-12-02-at-5-37-01-pm

 

$ sudo make install

 

$make  -j4

然後等個約1小時

screen-shot-2016-12-02-at-7-39-03-pm

 

 

然後安裝:
$ sudo make install

screen-shot-2016-12-02-at-7-39-32-pm
執行指令更新程式庫:
$ sudo ldconfig

試著檢查OpenCV的版本:
$ pkg-config --modversion opencv

screen-shot-2016-12-02-at-7-40-04-pm

 

 

 

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char **argv)
{
    Mat image = imread("apple.jph", CV_LOAD_IMAGE_COLOR);
    namedWindow("apple", WINDOW_AUTOSIZE);
    imshow("apple", image);
    waitKey(0);
    return 0;
}

$ g++ -lopencv_core -lopencv_highgui -lopencv_imgcodecs tes.cpp
$ g++ `pkg-config --libs opencv` test.cpp
$ ./a.out

import cv2

img=cv2.imread('apple.jpg')
cv2.imshow('apple', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

$ python test.py

Raspberry Pi
CH01 簡介篇CH30 OpenCVCH02 準備作業系統RaspbianCH03 第一次開機與設定CH06 python 程式CH06 架設網站伺服器CH14 常見問題CH15 XBMCCH20 應用程式CH21 讀者問題集CH30 docker