Raspberry Pi with OpenCV 3

Counters  coins.

เป็นการนำ  raspberry Pi มาทำงานกับ OpenCV  เพื่อสแกนหาว่าเหรียญหรือวัตถุกลม  โดยใช้กล้อง Web camera

Original


 

Device :  

  1. Raspberry Pi 3Device.jpg
  2. Web camera
  3. SD card Class 10
  4.  Micro USB Cable
  5. LAN Cable

 

 

 


 

Software Setup : 1-piece-lot-16gb-memory-card-class-10-16GB-micro-sd-card-from-manufacturer-Free-adapter.jpg

  1. set SD Card
  2. Download  IP scanner and Putty  for find IP of raspberry pi  and connect terminal raspberry
    •    http://www.advanced-ip-scanner.com/
    •    http://www.putty.org/

 

Device setup: 

  1.   Insert SD card to raspberry pi
  2.   Connect Laptop with Raspberry  by LAN cable
  3.   Open Raspberry Pi by connect micro USB  with Laptop
  4.   Connect Web camera with raspberry pi

 

Remote Desktop :  

  1.     After open Raspberry pi and connect with  Laptop  open “Advance IP scanner ”  find IP  Address raspberry pi   and  copy IP Address
  2.     open “Putty”   paste IP Address Raspberry pi   Click   “open”  terminal of raspberry    will show      insert  User : pi     password : raspberry    
  3.    the following command
    • sudo apt-get update
    • sudo apt-get install xrdp  #  (for remote desktop) wait until complete
    • Capture.JPG
    • exit  # (for close putty)
    • open “Remote desktop connection” in windows  insert IP address raspberry pi   user :  pi   password : raspberry  and then click “ok”

 

Verify Webcam Works  : 

  1.  Open terminal in Raspberry Pi screen
  2. The following commands
    • lsusb          # your webcam should be listed
    • cd /dev      # cd to dev directory
    • ls -l            # verify “video0” is listed, this is your webcam
    • cd ~            # back to home directory
    • sudo apt-get install fswebcam                                                                                              # install program to take still images with your webcam
    • fswebcam -r 640×480 –no-banner image.jpg                                                              # take a still image with your webcam open image in directory pic
    • sudo apt-get install luvcview               # install webcam stream viewer
    • luvcview -s 320×240                                # test webcam

 

Using the Raspbian Provided OpenCV Pre-compiled Binaries : 

  • The following commands
    • dpkg -l | less                  # this will list install package
    • sudo apt-get update
    • sudo apt-get upgrade
    • sudo apt-get install libopencv-dev python-opencv

 

verify the OpenCV install : 

  • The following commands
    • python  
    • >>> import cv2
    • >>> cv2.__version__                                                                                                                   # will say “2.4.9” if pre-compiled binary installation was successful

 

OpenCV Compile : 

********* this takes about 3.5 hours total on a RPi 2 good luck  *********

The following commands

  • cd ~
  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get install python-numpy python-scipy python-matplotlib
  • sudo apt-get install build-essential cmake pkg-config
  • sudo apt-get install default-jdk ant
  • sudo apt-get install libgtkglext1-dev
  • sudo apt-get install v4l-utils
  • sudo apt-get install libjpeg8 \
  • libjpeg8-dev \
  • libjpeg8-dbg \
  • libjpeg-progs \
  • libavcodec-dev \
  • libavformat-dev \
  • libgstreamer0.10-0-dbg \
  • libgstreamer0.10-0 \
  • libgstreamer0.10-dev \
  • libxine2-dev \
  • libunicap2 \
  • libunicap2-dev \
  • swig \
  • libv4l-0 \
  • libv4l-dev \
  • python-numpy \
  • libpython2.7 \
  • python-dev \
  • python2.7-dev \
  • libgtk2.0-dev \
  • libjasper-dev \
  • libpng12-dev \
  • libswscale-dev
  • wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/3.0.0/opencv-3.0.0.zip
  • unzip opencv-3.0.0.zip
  • cd opencv-3.0.0
  • mkdir build
  • cd build
  • cmake -D CMAKE_BUILD_TYPE=RELEASE \
  • -D INSTALL_C_EXAMPLES=ON \
  • -D INSTALL_PYTHON_EXAMPLES=ON \
  • -D BUILD_EXAMPLES=ON \
  • -D CMAKE_INSTALL_PREFIX=/usr/local \
  • -D WITH_V4L=ON ..

 

  • sudo make             # this takes about 3 hours on the RPi 2
  • sudo make install
  • sudo nano /etc/ld.so.conf.d/opencv.conf

# opencv.conf will be blank, add the following line, then save and exit nano

# back to the command line

  • sudo ldconfig
  • sudo nano /etc/bash.bashrc

# add the following lines at the bottom of bash.bashrc

->  PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
# enter these at the bottom of bash.bashrc, NOT at the command line
->  export PKG_CONFIG_PATH
# enter these at the bottom of bash.bashrc, NOT at the command line
(leave a blank line at the end of bash.bashrc)

# save bash.bashrc changes, then back at the command line, reboot


 

verify our OpenCV install :

# after rebooting

  •      python
  •      >>> cv2.__version__

# should say your OpenCV version, i.e. ‘3.0.0’, press Ctrl+D to exit the Python prompt session


 

Lest’s start : 


 

Example 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s