regionprops Matlab function之opencv的cvBlobsLib

cvBlobsLib

Table of contents

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 at http://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 downloaded here.

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 the cvblobslib.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 old IplImage, you can easily convert between them, such as by following the OpenCV C++ Cheatsheet.

Documentation

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

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 the CBlobResult constructor. This will fill the CBlobResult with all the blobs of the image. The blobs from the CBlobResult object can be filtered using the Filter method.

To filter the blobs, the library uses the blob operator concept: a class, derived from COperadorBlob which implements the function operator () on a CBlob object (see for example the CBlobGetArea class to extract the blob's area). The criteria to include or discard blobs is any object from classes derived from COperadorBlob (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 it
original = cvLoadImage("pic1.png", 0);
cvThreshold( original, originalThr, 100, 0, 255, CV_THRESH_BINARY );

// find non-white blobs in thresholded image
blobs = CBlobResult( originalThr, NULL, 255 );
// exclude the ones smaller than param2 value
blobs.Filter( blobs, B_EXCLUDE, CBlobGetArea(), B_LESS, param2 );

// get mean gray color of biggest blob
CBlob biggestBlob;
CBlobGetMean getMeanColor( original );
double meanGray;

blobs.GetNth( CBlobGetArea(), 0, biggestBlob );
meanGray = getMeanColor( biggestBlob );

// display filtered blobs
cvMerge( originalThr, originalThr, originalThr, NULL, displayedImage );

for (i = 0; i < blobs.GetNumBlobs(); i++ )
{
        currentBlob = blobs.GetBlob(i);
        currentBlob->FillBlob( displayedImage, CV_RGB(255,0,0));
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值