Report- Install Raspberry Pi With OpenCV and Demo Facedetect

18
ĐẠI HC QUC GIA THÀNH PHHCHÍ MINH TRƯỜNG ĐẠI HC CÔNG NGHTHÔNG TIN ĐỒ ÁN MÔN HC 2 HƯỚNG DN CÀI ĐẶT RASPBERRY PI VÀ OPENCV 2.4.8 VI DEMO NHN DNG KHUÔN MT THÔNG QUA RASPBERRY CAMERA MODULE Giáo viên hướng dn: Ks. Cao Văn Hưng Ths. Đỗ Thế Luân Sinh viên : Nguyễn Đức Trung- 1052035 Trn Thanh Liêm - 10520364

Transcript of Report- Install Raspberry Pi With OpenCV and Demo Facedetect

  • I HC QUC GIA THNH PH H CH MINH

    TRNG I HC CNG NGH THNG TIN

    N MN HC 2

    HNG DN CI T RASPBERRY PI V OPENCV 2.4.8

    VI DEMO NHN DNG KHUN MT

    THNG QUA RASPBERRY CAMERA MODULE

    Gio vin hng dn:

    Ks. Cao Vn Hng

    Ths. Th Lun

    Sinh vin :

    Nguyn c Trung- 1052035

    Trn Thanh Lim - 10520364

  • Ci t Raspberry v Demo OpenCV

    2 | P a g e

    Mc Lc:

    I. Ci t Raspbian vo th nh ( SD card): .............................................................................................. 3

    1) Chun b phn mm: ......................................................................................................................... 3

    2) Ci t ln SD card: ........................................................................................................................... 4

    II. Ci t ln Raspberry Pi: ....................................................................................................................... 5

    III. Config c bn cho Raspberry Pi: ....................................................................................................... 5

    1) Config Network : ............................................................................................................................... 5

    2) iu khin Raspberry Pi t xa qua 1 my khc: ................................................................................ 6

    IV. Ci t OpenCV ln Raspberry Pi: ..................................................................................................... 7

    1) Ci t cc gi cn thit h tr OpenCV: .......................................................................................... 7

    2) Download v ci t OpenCV 2.4.8: ............................................................................................... 11

    3) Chy code mu OpenCV:................................................................................................................. 17

  • Ci t Raspberry v Demo OpenCV

    3 | P a g e

    I. Ci t Raspbian vo th nh ( SD card):

    1) Chun b phn mm:

    - Raspbian OS: Download ti http://www.raspberrypi.org/downloads/

    - SD formatter : Download ti https://www.sdcard.org/downloads/formatter_4/

  • Ci t Raspberry v Demo OpenCV

    4 | P a g e

    - Win32diskimager: Download ti http://sourceforge.net/projects/win32diskimager/

    2) Ci t ln SD card:

    - Dng SD formatter nh dng li th nh :

    Gn th SD vo my tnh.

    Khi ng SD Formatter, chn ng th phn Drive.

    Click Option, mc Format Size Adjustment chn ON.

    Sau cng, click Format.

    - S dng Win32diskimager np image Raspbian OS vo th:

    Trong Image File chn image Raspbian va ti v.

    Chn a ca th SD trong Device.

  • Ci t Raspberry v Demo OpenCV

    5 | P a g e

    Bm Write bt u ghi.

    II. Ci t ln Raspberry Pi:

    - Sau khi np h iu hnh Raspbian vo th nh, cm th, cm cp HDMI, bn phm,

    chut v dy mng vo Raspberry Pi.

    - Cm ngun vo, ta s thy mn hnh khi ng ca Raspberry Pi vo thng Raspi-

    config.

    - Chn dng th 3- Enable boot to Desktop/Scratch. Sau thot ra chn Finish

    khi ng li Raspberry Pi v hon tt qu trnh ci t.

    - Khi Raspi khi ng xong, ta g username l pi, password l raspberry, sau g

    startx vo mn hnh giao din RasPi.

    III. Config c bn cho Raspberry Pi:

    1) Config Network :

    - Ta vo Terminal trn desktop. G lnh: sudo nano /etc/network/interfaces

    chnh thng s ci t cho mng dy, y trng hp ta t ip tnh laptop c

    th kt ni vo bng giao thc vnc.

  • Ci t Raspberry v Demo OpenCV

    6 | P a g e

    y ta t IP ca Raspi l 192.168.0.210, IP mng l 192.168.0.1.

    Note: Nu mun a ch IP t cp pht th ta ch cn sa li dng th 3 thnh

    iface eth0 inet dhcp v xa cc dng th 4 tr i.

    - lu li bm t hp phm Ctrl + O ==> Enter ==> Ctrl + X.

    - Sau ta g lnh sudo reboot khi ng li card mng.

    2) iu khin Raspberry Pi t xa qua 1 my khc:

    - Ti terminal g:

    sudo raspi-config : vo mn hnh config raspi

    Chn mc Advance Options SSH Enable ri OK.

    - Ci t SSH client trn my tnh Windows. Download phn mm PuTTY ti

    http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html .

  • Ci t Raspberry v Demo OpenCV

    7 | P a g e

    - Trn giao din PuTTY ta nhp a ch 192.168.0.210 ca Raspi vo Hostname ri

    bm Open.

    - Ci t VNCServer ln Raspi. Ti terminal ta g:

    sudo apt-get install tightvncserver

    tightvncserver

    vncserver:1 geometry 1024x768 depth 24

    - Ci t VNCViewer ti my client mun truy cp vo Raspi. Download ti

    http://www.realvnc.com/download/viewer/ . Chy vncviewer v in

    192.168.0.210:5901 vo VNC Server. Sau bm Connect l ta hon ton s

    dng c Raspi thng qua iu khin t xa.

    IV. Ci t OpenCV ln Raspberry Pi:

    1) Ci t cc gi cn thit h tr OpenCV:

    - Config ssh v camera:

    sudo raspi-config

  • Ci t Raspberry v Demo OpenCV

    8 | P a g e

    ssh-->enable : bt ssh.

    camera-->enable : bt camera.

  • Ci t Raspberry v Demo OpenCV

    9 | P a g e

    // cp nht driver mi nht.

    sudo apt-get update

    sudo apt-get upgrade

  • Ci t Raspberry v Demo OpenCV

    10 | P a g e

    // kim tra camera.

    lsusb

    sudo apt-get install guvcview

    guvcview : bt th camera.

    // ci t synaptic.

    sudo apt-get install synaptic

    // ci t python scipy stack.

    sudo apt-get install python-numpy python-scipy python-matplotlib python-

    pandas python-sympy python-nose

  • Ci t Raspberry v Demo OpenCV

    11 | P a g e

    2) Download v ci t OpenCV 2.4.8:

    // download opencv bn 2.4.8

    wget http://sourceforge.net/projects/opencvlibrary/files/opencv-

    unix/2.4.8/opencv-2.4.8.zip/download

    // ci t mi trng pht trin cho opencv.

    sudo apt-get install build-essential cmake pkg-config

  • Ci t Raspberry v Demo OpenCV

    12 | P a g e

    sudo apt-get install default-jdk ant

    sudo apt-get install libgtkglext1-dev

    sudo apt-get install bison

    sudo apt-get install qt4-dev-tools libqt4-dev libqt4-core libqt4-gui

    sudo apt-get install v4l-utils

  • Ci t Raspberry v Demo OpenCV

    13 | P a g e

    sudo apt-get install qtcreator ( C th ci hoc khng).

    // ci t opencv.

    unzip opencv-2.4.8.zip

    cd opencv-2.4.8

    mkdir build

    cd build

    cmake D CMAKE_BUILD_TYPE=RELAESE D

    INSTALL_C_EXAMPLES=ON D

    INSTALL_PYTHON_EXAMPLES=ON D BUILD_EXAMPLES=ON

    D WITH_QT=ON D CMAKE_INSTALL_PREFIX=/usr/local D

    WITH_OPENGL=ON D WITH_V4L=ON D

    BUILD_NEW_PYTHON_SUPPORT=ON D WITH_TBB=ON..

  • Ci t Raspberry v Demo OpenCV

    14 | P a g e

    Make

    sudo make install

  • Ci t Raspberry v Demo OpenCV

    15 | P a g e

    // sa cc file config link th vin.

    sudo nano /etc/ld.so.conf.d/opencv.conf

    thm vo dng:

    /usr/local/lib

  • Ci t Raspberry v Demo OpenCV

    16 | P a g e

    sudo ldconfig

    sudo nano /etc/bash.bashrc

    thm vo cui:

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

    export PKG_CONFIG_PATH

  • Ci t Raspberry v Demo OpenCV

    17 | P a g e

    Lu cc file li.

    3) Chy code mu OpenCV:

    // chy code mu ca opencv.

    cd /opencv-2.4.8/samples/c

    chmod +x build_all.sh

    ./build_all.sh

    // chy facedetect.

    ./facedetect

    // chy code mu python.

    cd /opencv-2.4.8/samples/python2

    ./facedetect.py

  • Ci t Raspberry v Demo OpenCV

    18 | P a g e