element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 - 12 - Blob detection
  • 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: 24 Sep 2015 8:09 AM Date Created
  • Views 573 views
  • Likes 1 like
  • Comments 0 comments
  • opencv
  • sci_fi_your_pi
  • cvblob
  • training_sphere
Related
Recommended

TrainingSphere - 12 - Blob detection

amgalbu
amgalbu
24 Sep 2015

In this post we will face some image processing technique, like blob analysys.

I will use the cvBlob library to detect blobs in the image capture by the raspicam

 

Step1: cvBlob installation

1.       Download cvBlob library from this link

               https://github.com/Steelskin/cvblob              

          and save it to

          /home/pi/cvblob

2.       Because I downloaded the zip file, I need to unzip it

               tar xvf cvblob-0.10.4-src.zip

3.       We need to make some bug fixing. So move to the source code directory

cd cvblob

cv cvBlob

and make the following  changes to

               a.       cvblob.h: at line 84 replace

const char cvChainCodeMoves[8][2] = { {0, -1},

with

const signed char cvChainCodeMoves[8][2] = { {0, -1},

               b.      cvlabel.cpp: at line 34 replace

const char movesSE[4][3][4] = <line continues...>

with

const signed char movesSE[4][3][4] = <line continues...>

               c.       cvlabel.cpp: at line 40 replace

const char movesI[4][3][4] = <line continues...>

with

const signed char movesI[4][3][4] = <line continues...>

4.       build cvBlob library

                    cd ..    

          cmake .    

          make

5.       and finally let's install the cvBlob library

               make install


Step2: develop an application that can detect blobs in images

  1. I firstly created some utility functions to capture images from RaspiCam. You can find such functions in raspistill.h and raspistill.c (everything is under development, so some code clean up may be required..). Thanks to raspistill functions, the main application is very easy to implement:

raspistill_initialize(&state);     
raspistill_shot(&state, camera_callback);     
raspistill_terminate(&state);              

The raspistill_shot take a photo and invoke the camera_callback function. The only      parameter used by this function is an IplImage object that contains the captured image

2.       Next step is to implement functions for detecting blobs in the image. Such functions are implemented in the blobs.c and blobs.h functions. There are two functions currently implemented

detectBlobs(IplImage* image, struct ImageParams* imageParams)          

                  and        

detectBlobsWithImage(IplImage* image, struct ImageParams* imageParams)              

The second one shows the results of the image processing in a set of windows. So I'm going to use the latter for this demo because it's more impressive than some text output on a console. This function basically gets the images captured by the RaspiCam and creates an image (named segmentated) where the pixel whose color is inside the given RGB color range are white and the other pixels are black

IplImage* segmentated;
cvInRangeS(image, CV_RGB(155, 0, 0), CV_RGB(255, 130, 130), segmentated);






With the segmentated image, we can detect blobsIplImage* labelImg;CvBlobs blobs;

labelImg = cvCreateImage(cvGetSize(image), IPL_DEPTH_LABEL, 1);
 
result = cvLabel(segmentated, labelImg, blobs);

3.       Let's bring everything together and make  loop that periodically invoke the raspistill_shot function so that we can experiment with the camera and it's behavior in different light conditions

4.       Let's build application with the usual sequence of commands

                    cd build    

          cmake ..    

          make

  • Sign in to reply
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