regionprops Matlab function之opencv的cvBlobsLib

来源:互联网 发布:桌面会议软件 编辑:程序博客网 时间:2024/06/07 13:32

cvBlobsLib

Table of contents

Contents

  1. cvBlobsLib
  2. Blob extraction library
    1. News
    2. Features
    3. Download
    4. Build intructions
    5. Documentation
    6. Algorithm
    7. Project samples
    8. Code examples

Blob extraction library

A library to perform binary images connected component labelling (similar to regionprops Matlab function). It also provides functions to manipulate, filter and extract results from the extracted blobs, see features section for more information.

News

2011-12-19: Added some info about building cvBlobsLib with OpenCV v2.2 onwards. Also added link to a colored blob detection tutorial.

2011-07-18: Linux port of cvBlobsLib v8.3 was added by user AhmetOnat.

2009-04-17: New version (v8.3) available! A minor build error was solved.Also a test project was added.

2009-04-14: New version (v8.2) available! A minor runtime error has been resolved on MSVC2008 (unitialised pMask).

2009-02-04: New version (v8.1) available! Few unneeded files have been removed and a makefile for Linux have been generated (Thanks to kecsap)

2009-01-29: New version (v8) available! A complete rewrite of the library has been done. Also the algorithm has been changed (See Algorithm section)

2009-01-04: Add a small patch to the v6 linux version to compile with the latest opencv versions.

2008-08-24: Python binding for v6 released.

2007-03-22: Version v6 available for linux. Thanks to Jon Azpiazu.

2007-16-02: New version (v6) available! The performance has been increased drastically for images with large number of blobs (thanks to D.Grossman for the advice).

2006-11-13: Added prebuilt documentation in the Download section.

2006-11-10: New version (v5) available as an attachment to this file (see Download section). This version contains some bug fixes and some new functionalities.

Features

The library provides two basic functionalities:

  1. Extract 8-connected components in binary or grayscale images. These connected components are referred as blobs.
  2. Filter the obtained blobs to get the interest objects in the image. This is performed using the Filter method from CBlobResult.

The library is thread-safe if different objects per thread are used.

Download

Latest release: cvblobslib_OpenCV_v8_3.zip also for Linux: cvblobs8.3_linux.tgz

Old library versions:  cvblobslib_OpenCV_v6.zip for windows and cvblobslib_v6p1.tar.gz for linux.  A Python binding for Linux is available athttp://pyblobs.googlecode.com.

The documentation can be downloaded here.

Build intructions

cvBlobsLib has been developed using Microsoft Visual C++ (6.0) and also can be used in .NET. A Linux version could be downloadedhere.

cvBlobsLib is distributed in a static library (.lib). To use it, it is needed to build the.lib file and later use that lib file in the desired project. To build the.lib file, simply open the MSVC++ project and build it (debug or release version).

To build the project where the library is to be used follow this steps (MSVC++ 6.0):

  • In "Project/Settings/C++/Preprocessor/Additional Include directories" add the directory where the blob library is stored

  • In "Project/Settings/Link/Input/Additional library path" add the directory where the blob library is stored and in "Object/Library modules" add thecvblobslib.lib file

  • Include the file "BlobResult.h" where you want to use blob variables.

  • In "Project/Settings/C++/Precompiled Headers" select "Not use precompiled headers" (Thanks Brendan)

NOTE: Verify that in the project where the cvblobslib.lib is used, the MFC Runtime Libraries are not mixed:

  1. Check in "Project->Settings->C/C++->Code Generation->Use run-time library" of your project and set it to

  2. Debug Multithreaded DLL (debug version) or to Multithreaded DLL ( release version ).
    1. Check in "Project->Settings->General" how it uses the MFC. It should be "Use MFC in a shared DLL".

NOTE: The library can be compiled and used in .NET using this steps, but the menu options may differ a little

NOTE 2: In the .NET version, the character sets must be equal in the .lib and in the project. [OpenCV yahoo group: Msg 35500]

NOTE 3: cvBlobsLib might give errors when building with OpenCV v2.2 onwards. Try commenting out this line in file "BlobLibraryConfiguration.h":

  • #define _SHOW_ERRORS

NOTE 4: If you are using the new cv::Mat for your images instead of the oldIplImage, you can easily convert between them, such as by following theOpenCV C++ Cheatsheet.

Documentation

The function documentation is included in source files and a full HTML documentation can be build usingDoxygen.

The main classes are: CBlobResult and CBlob.CBlobResult stores a set of blobs and CBlob stores a single blob.

To build a CBlobResult, just use its image constructor on a input 1-channel image. This image can be binary or gray-leveled, in both cases the extracted blobs are all that have diferent color than the one specified in theCBlobResult constructor. This will fill the CBlobResult with all the blobs of the image. The blobs from theCBlobResult object can be filtered using the Filter method.

To filter the blobs, the library uses the blob operator concept: a class, derived fromCOperadorBlob which implements the function operator () on a CBlob object (see for example theCBlobGetArea class to extract the blob's area). The criteria to include or discard blobs is any object from classes derived fromCOperadorBlob (area, perimeter, gray level, etc., or new classes created by users).

There are two special blob operators: CBlobGetMean and CBlobGetStdDev. Both expect an input image and they return the mean (or the standard deviation) of the input image only inside the selected blob. These operators allow to extract blobs in one image and calculate many features in other images.

Algorithm

The algorithm has been changed to this one: "A linear-time component labeling algorithm using contour tracing technique",  F.Chang et al.

This algorithm improves drastically the performance of the library.

Project samples

The library has been succesfully used in these projects:

  1. cork stopper inspection
  2. http://derindelimavi.blogspot.com/2009/02/cvblobslibin-yeni-versiyonu-ckt.html

  3. Colored Blobs and Skin Detection Tutorial

  4. Add your own!

Code examples

//////////////////////////////////////////////////////////////// get blobs and filter them using its area/////////////////////////////////////////////////////////////CBlobResult blobs;int i;CBlob *currentBlob;IplImage *original, *originalThr;// load an image and threshold itoriginal = cvLoadImage("pic1.png", 0);cvThreshold( original, originalThr, 100, 0, 255, CV_THRESH_BINARY );// find non-white blobs in thresholded imageblobs = CBlobResult( originalThr, NULL, 255 );// exclude the ones smaller than param2 valueblobs.Filter( blobs, B_EXCLUDE, CBlobGetArea(), B_LESS, param2 );// get mean gray color of biggest blobCBlob biggestBlob;CBlobGetMean getMeanColor( original );double meanGray;blobs.GetNth( CBlobGetArea(), 0, biggestBlob );meanGray = getMeanColor( biggestBlob );// display filtered blobscvMerge( originalThr, originalThr, originalThr, NULL, displayedImage );for (i = 0; i < blobs.GetNumBlobs(); i++ ){        currentBlob = blobs.GetBlob(i);        currentBlob->FillBlob( displayedImage, CV_RGB(255,0,0));}

原创粉丝点击