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
Forget Me Not Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Forget Me Not Design Challenge
  • More
  • Cancel
Forget Me Not Design Challenge
Blog Cam-e-lot - Round 3 - Man vs OpenCV
  • Blog
  • Forum
  • Documents
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: amgalbu
  • Date Created: 19 Aug 2014 2:13 PM Date Created
  • Views 695 views
  • Likes 0 likes
  • Comments 5 comments
  • forget_me_not
  • iot_cam-e-lot
Related
Recommended

Cam-e-lot - Round 3 - Man vs OpenCV

amgalbu
amgalbu
19 Aug 2014

Hello everybody

For my project I need to make some analysis on the images captured by RaspiCam, so the next step is to install the OpenCV libraries and try to get images from RaspiCam inside a C program.

So here are the steps for this round (this tutorial has been adapted from the tutorial published by Pierre on Think RPI | Creative Raspberry Pi Area)

 

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

 

I'm sorry this has been a very boring post with a little more than some shell scripting... 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

 

Stay tuned!

  • Sign in to reply

Top Comments

  • mcb1
    mcb1 over 11 years ago in reply to vish +1
    Frederick Just tag your cats and read the RFID tag (134KHz) when they make the video call. Surely you should be able to recognise them by now ...So I'm not sure why you need facial recognition.. Mark
Parents
  • fvan
    fvan over 11 years ago

    I've tried searching for this before, but could OpenCV be able to do facial recognition on cats ? image

     

    Frederick

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

    I'm not sure OpenCV has built-in face recognition features. For sure, this library https://github.com/bytefish/libfacerec works on Raspberry Pi and OpenCV. Probably with a proper training set it could be adapted to cat recognition..

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vish
    vish over 11 years ago in reply to amgalbu

    Hi,

    From openCV 2.4, this library is integrated into openCV so you will be able to use it without any extra installations. I worked with LBPH faceRecognizer and worked well for my project. But that time, it was human faces. In theory, it should work with cat faces also. But detecting cats faces may be a bit tricky. If face detector is not working, you could try eyes detector( which should most certainly work ) and then draw a rough estimation of face based on the position and size of detected eyes.

    You must first detect the faces in the frame and then pass it to the FaceRecognizer class. This may be a time consuming in Pi. My suggestion would be resize the captured frame to smaller size( I used 160x120 for mine ), detect the face, now you will be having the co-ordinates w.r.t the resized image, pass that area to the face recognizer and check the performance. If it's not working, do a little math and calculate the co-ordinates in the original frame and pass that area to your face recognizer. It's a lot more efficient when all you have is a single core system.

    Do share with us what results you are getting. image

    Cheers,

    vish

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vish
    vish over 11 years ago in reply to amgalbu

    Forgot to mention, here is the link

    Face Recognition with OpenCV — OpenCV 2.4.9.0 documentation

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 11 years ago in reply to vish

    Frederick

    Just tag your cats and read the RFID tag (134KHz)  when they make the video call.

     

    Surely you should be able to recognise them by now ...So I'm not sure why you need facial recognition..image

     

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • mcb1
    mcb1 over 11 years ago in reply to vish

    Frederick

    Just tag your cats and read the RFID tag (134KHz)  when they make the video call.

     

    Surely you should be able to recognise them by now ...So I'm not sure why you need facial recognition..image

     

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
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