Project

General

Profile

Statistics
| Branch: | Revision:

root / vision / cvblobs8.3 / testBlobs / main.cpp @ b11b2b30

History | View | Annotate | Download (2.15 KB)

1
// main.cpp : Defines the entry point for the console application.
2
//
3

    
4
//#include "stdafx.h" //AO
5
#include "opencv/cv.h"
6
#include "opencv/highgui.h"
7
#include <stdio.h>
8
//#include <conio.h> //AO
9

    
10
// Main blob library include
11
#include "BlobResult.h"
12

    
13
char wndname[] = "Blob Extraction";
14
char tbarname1[] = "Threshold";
15
char tbarname2[] = "Blob Size";
16

    
17
// The output and temporary images
18
IplImage* originalThr = 0;
19
IplImage* original = 0;
20
IplImage* displayedImage = 0;
21

    
22
int param1,param2;
23

    
24

    
25

    
26
// threshold trackbar callback
27
void on_trackbar( int dummy )
28
{
29
        if(!originalThr)
30
        {
31
                originalThr = cvCreateImage(cvGetSize(original), IPL_DEPTH_8U,1);
32
        }
33

    
34
        if(!displayedImage)
35
        {
36
                displayedImage = cvCreateImage(cvGetSize(original), IPL_DEPTH_8U,3);
37
        }
38
        
39
        // threshold input image
40
        cvThreshold( original, originalThr, param1, 255, CV_THRESH_BINARY );
41

    
42
        // get blobs and filter them using its area
43
        CBlobResult blobs;
44
        int i;
45
        CBlob *currentBlob;
46

    
47
        // find blobs in image
48
        blobs = CBlobResult( originalThr, NULL, 255 );
49
        blobs.Filter( blobs, B_EXCLUDE, CBlobGetArea(), B_LESS, param2 );
50

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

    
54
        for (i = 0; i < blobs.GetNumBlobs(); i++ )
55
        {
56
                currentBlob = blobs.GetBlob(i);
57
                currentBlob->FillBlob( displayedImage, CV_RGB(255,0,0));
58
        }
59
         
60
    cvShowImage( wndname, displayedImage );
61
        
62
}
63

    
64

    
65

    
66
int main( int argc, char** argv )
67
{
68

    
69
        param1 = 100;
70
        param2 = 2000;
71
        
72
        // open input image
73
        original = cvLoadImage("pic6.png",0);
74

    
75
        cvNamedWindow("input");
76
        cvShowImage("input", original );
77
        
78
        cvNamedWindow(wndname, 0);
79
    cvCreateTrackbar( tbarname1, wndname, &param1, 255, on_trackbar );
80
        cvCreateTrackbar( tbarname2, wndname, &param2, 30000, on_trackbar );
81
        
82
        // Call to update the view
83
        for(;;)
84
    {
85
        int c;
86
        
87
        // Call to update the view
88
        on_trackbar(0);
89

    
90
        c = cvWaitKey(0);
91

    
92
           if( c == 27 )
93
            break;
94
        }
95
    
96
    cvReleaseImage( &original );
97
        cvReleaseImage( &originalThr );
98
        cvReleaseImage( &displayedImage );
99
    
100
    cvDestroyWindow( wndname );
101
    
102
    return 0;
103
}