main.cpp
Go to the documentation of this file.
00001 // main.cpp : Defines the entry point for the console application.
00002 //
00003 
00004 #include "cv.h"
00005 #include "highgui.h"
00006 #include <stdio.h>
00007 
00008 #ifdef _MSC_VER
00009 #include "stdafx.h"
00010 #include <conio.h>
00011 #endif
00012 
00013 // Main blob library include
00014 #include "BlobResult.h"
00015 
00016 char wndname[] = "Blob Extraction";
00017 char tbarname1[] = "Threshold";
00018 char tbarname2[] = "Blob Size";
00019 
00020 // The output and temporary images
00021 IplImage* originalThr = 0;
00022 IplImage* original = 0;
00023 IplImage* displayedImage = 0;
00024 
00025 int param1,param2;
00026 
00027 
00028 
00029 // threshold trackbar callback
00030 void on_trackbar( int dummy )
00031 {
00032         if(!originalThr)
00033         {
00034                 originalThr = cvCreateImage(cvGetSize(original), IPL_DEPTH_8U,1);
00035         }
00036 
00037         if(!displayedImage)
00038         {
00039                 displayedImage = cvCreateImage(cvGetSize(original), IPL_DEPTH_8U,3);
00040         }
00041         
00042         // threshold input image
00043         cvThreshold( original, originalThr, param1, 255, CV_THRESH_BINARY );
00044 
00045         // get blobs and filter them using its area
00046         CBlobResult blobs;
00047         int i;
00048         CBlob *currentBlob;
00049 
00050         // find blobs in image
00051         blobs = CBlobResult( originalThr, NULL, 255 );
00052         blobs.Filter( blobs, B_EXCLUDE, CBlobGetArea(), B_LESS, param2 );
00053 
00054         // display filtered blobs
00055         cvMerge( originalThr, originalThr, originalThr, NULL, displayedImage );
00056 
00057         for (i = 0; i < blobs.GetNumBlobs(); i++ )
00058         {
00059                 currentBlob = blobs.GetBlob(i);
00060                 currentBlob->FillBlob( displayedImage, CV_RGB(255,0,0));
00061         }
00062          
00063     cvShowImage( wndname, displayedImage );
00064         
00065 }
00066 
00067 
00068 
00069 int main( int argc, char** argv )
00070 {
00071 
00072         param1 = 100;
00073         param2 = 2000;
00074         
00075         // open input image
00076 #ifdef _MSC_VER
00077         original = cvLoadImage("c:\\Archivos de programa\\OpenCV\\samples\\c\\pic1.png",0);
00078 #else
00079         original = cvLoadImage("example.png",0);
00080 #endif
00081         cvNamedWindow(wndname, 0);
00082     cvCreateTrackbar( tbarname1, wndname, &param1, 255, on_trackbar );
00083         cvCreateTrackbar( tbarname2, wndname, &param2, 30000, on_trackbar );
00084         
00085         // Call to update the view
00086         for(;;)
00087     {
00088         int c;
00089         
00090         // Call to update the view
00091         on_trackbar(0);
00092 
00093         c = cvWaitKey(0);
00094 
00095            if( c == 27 )
00096             break;
00097         }
00098     
00099     cvReleaseImage( &original );
00100         cvReleaseImage( &originalThr );
00101         cvReleaseImage( &displayedImage );
00102     
00103     cvDestroyWindow( wndname );
00104     
00105     return 0;
00106 }


hrl_cvblobslib
Author(s): kelsey
autogenerated on Wed Nov 27 2013 11:32:58