element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Sci Fi Your Pi
  • Challenges & Projects
  • Design Challenges
  • Sci Fi Your Pi
  • More
  • Cancel
Sci Fi Your Pi
Blog TrainingSphere - 11 - OpenCV
  • Blog
  • Forum
  • Documents
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: amgalbu
  • Date Created: 19 Sep 2015 11:57 AM Date Created
  • Views 1081 views
  • Likes 5 likes
  • Comments 3 comments
  • sci_fi_your_pi
  • training_sphere
Related
Recommended

TrainingSphere - 11 - OpenCV

amgalbu
amgalbu
19 Sep 2015

After some busy times, I finally have a weekend for working on this project


One of the ancillary parts of this project, is to make some blob analysis on the images captured by RaspiCam to detect laser beams. So I need install the OpenCV libraries and try to get images from RaspiCam inside a C program.

The idea is that an external application will command the autopilot subsystem (by means of MAVLink messages) and will detect reflected laser beams to start some special effect


So here are the steps to install OpenCV

 

1. Install RaspiCam. Installation procedure is very well described on Raspberry official site http://www.raspberrypi.org/archives/3890 Once installed, test it with this command:

raspistill -t 10000

2. Download the MMAL library aspivid/Raspistill source code from https://github.com/raspberrypi/userland .

3. Unzip the file and copy the directory userlan-master in /opt/vc. I also renamed the directory as "userland"

4.  Go to /opt/vc/userland and type

     sed -i ‘s/if (DEFINED CMAKE_TOOLCHAIN_FILE)/if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)/g’ makefiles/cmake/arm-linux.cmake

5. create a build directory...

     sudo mkdir build

     cd build

6. ... and compile

     sudo cmake -DCMAKE_BUILD_TYPE=Release ..
     sudo
make
    
sudo make install

7. go to /opt/vc/bin and test one file typing : ./raspistill -t 3000



OK... now I'm ready to create a new project

 

1. create a new folder (/home/pi/vc) in your home directory

     mkdir cv
     cd cv

2. copy all raspicam apps source code

     cp /opt/vc/userland/host_applications/linux/apps/raspicam/*  .

     mv RaspiStill.c camcv.c

     sudo chmod 777 camcv.c

3. remove then content of CMakeLists.txt and replace with :
     cmake_minimum_required(VERSION 2.8)
     project( camcv )
     SET(COMPILE_DEFINITIONS -Werror)
     include_directories(/opt/vc/userland/host_applications/linux/libs/bcm_host/include)
     include_directories(/opt/vc/userland/interface/vcos)
     include_directories(/opt/vc/userland)
     include_directories(/opt/vc/userland/interface/vcos/pthreads)
     include_directories(/opt/vc/userland/interface/vmcs_host/linux)
     include_directories(/opt/vc/userland/interface/khronos/include)

     include_directories(/opt/vc/userland/interface/khronos/common)

     add_executable(camcv RaspiCamControl.c RaspiCLI.c RaspiPreview.c camcv.c RaspiText.c RaspiTexUtil.c gl_scenes/teapot.c gl_scenes/models.c gl_scenes/square.c gl_scenes/mirror.c gl_scenes/yuv.c gl_scenes/sobel.c tga.c)
     target_link_libraries(camcv /opt/vc/lib/libmmal_core.so /opt/vc/lib/libmmal_util.so /opt/vc/lib/libmmal_vc_client.so /opt/vc/lib/libvcos.so /opt/vc/lib/libbcm_host.so /opt/vc/lib/libGLESv2.so /opt/vc/lib/libEGL.so)

4. delete CMakeFiles directory if it exits
5. compile & test
     cmake .
     make
     ./camcv -t 1000


Great!!!
We are now ready to install OpenCV


1. install both dev lib and python lib. Even if I'm going to use pure C for development, Python is still useful for small scripts, so I recommend to install it.

     sudo apt-get update

     sudo apt-get install libopencv-dev
     sudo apt-get install python-opencv

2. to test if OpenCv library is well installed, write this test software. It just displays a picture using imread and imshow functions. You will need to provide a sample .jpg file. To compile using OpenCv lib, create a CMakeLists.txt file with the following lines

     cmake_minimum_required(VERSION 2.8)
     project( displayimage )
     find_package( OpenCV REQUIRED )
     add_executable( displayimage display_image.cpp )
     target_link_libraries( displayimage ${OpenCV_LIBS} )

3. compile and execute

     cmake .
     make
     ./displayimage

4. Modify your CMakeFiles.txt to include OpenCV library

     project( camcv )

     SET(COMPILE_DEFINITIONS -Werror)

     #OPENCV
     find_package( OpenCV REQUIRED )

     include_directories(/opt/vc/userland/host_applications/linux/libs/bcm_host/include)

     include_directories(/opt/vc/userland/interface/vcos)
     include_directories(/opt/vc/userland)
     include_directories(/opt/vc/userland/interface/vcos/pthreads)
     include_directories(/opt/vc/userland/interface/vmcs_host/linux)
     include_directories(/opt/vc/userland/interface/khronos/include)

     include_directories(/opt/vc/userland/interface/khronos/common)

     add_executable(camcv RaspiCamControl.c RaspiCLI.c RaspiPreview.c camcv.c RaspiText.c RaspiTexUtil.c gl_scenes/teapot.c gl_scenes/models.c gl_scenes/square.c gl_scenes/mirror.c gl_scenes/yuv.c gl_scenes/sobel.c tga.c)
     target_link_libraries(camcv /opt/vc/lib/libmmal_core.so /opt/vc/lib/libmmal_util.so /opt/vc/lib/libmmal_vc_client.so /opt/vc/lib/libvcos.so /opt/vc/lib/libbcm_host.so /opt/vc/lib/libGLESv2.so /opt/vc/lib/libEGL.so ${OpenCV_LIBS})

5. Recompile. It should be ok, because we didn't change anything in the source code

     make
     ./camcv

 

In next post I will make a basic application that can capture an image from RaspiCam and make some video processing using the power of the OpenCV library

  • Sign in to reply

Top Comments

  • balearicdynamics
    balearicdynamics over 10 years ago +1
    Godd presentation, it will be useful in the next future. I can't wait to see it to fly! Enrico
  • fvan
    fvan over 10 years ago +1
    Looking forward to see how you get on with OpenCV as this is very interesting for various applications. And with the Pi 2's processing power, things should go rather smoothly!
  • saturnv
    saturnv over 10 years ago

    Good luck. i was really interested in seeing this project in the finals. Autonomy is a cool function and the training sphere would be a great tool, game, and toy all in one. Such a device could have many applications. Press on and good luck.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fvan
    fvan over 10 years ago

    Looking forward to see how you get on with OpenCV as this is very interesting for various applications. And with the Pi 2's processing power, things should go rather smoothly!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • balearicdynamics
    balearicdynamics over 10 years ago

    Godd presentation, it will be useful in the next future.

    I can't wait to see it to fly! image

     

    Enrico

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube