Subscribe:

Ads 468x60px

Sunday, August 5, 2012

Setting cvbloblib in Visual studio 2010

Hey guys

           I am giving tutorials for setting cvbloblib in Microsoft Visual studio 2010

*Download cvblobllib from willogarage website

http://opencv.willowgarage.com/wiki/cvBlobsLib/

Setting OpenCV in Visual studio2010

Download cvbloblib for linux(Note:Windows version not working for me)

Extract all files to project folder





Add headers and source file into the project




test.cpp file

 // ObjectTracking.cpp : Define the entry point for console app.   
 #include "opencv/cv.h"   
 #include "opencv/highgui.h"   
 #include "BlobResult.h"   
 // Get thresholded image in HSV format   
 IplImage* GetThresholdedImageHSV( IplImage* img )   
 {   
   // Create an HSV format image from image passed   
   IplImage* imgHSV = cvCreateImage( cvGetSize( img ),    
                    8,    
                    3 );     
   cvCvtColor( img, imgHSV, CV_BGR2HSV );   
   // Create binary thresholded image acc. to max/min HSV ranges   
   IplImage* imgThresh = cvCreateImage( cvGetSize( img ),    
                      8,    
                      1 );         
   cvInRangeS( imgHSV,   
         cvScalar( 104, 178, 70 ),   
         cvScalar( 130, 240, 124 ),   
         imgThresh );   
   // Tidy up and return thresholded image   
   cvReleaseImage( &imgHSV );   
   return imgThresh;   
 }   
 int main()   
 {   
   CBlobResult blobs;    
   CBlob *currentBlob;    
   CvPoint pt1, pt2;   
   CvRect cvRect;   
   int key = 0;   
   IplImage* frame = 0;   
   CvCapture* capture = 0;  
   // Initialize capturing live feed from video file or camera   
   capture = cvCaptureFromCAM(0);  
   // Get the frames per second   
  // int fps = ( int )cvGetCaptureProperty( capture,   
                 //      CV_CAP_PROP_FPS );    
   // Can't get device? Complain and quit   
   if( !capture )   
   {   
     printf( "Could not initialize capturing...\n" );   
     return -1;   
   }   
   // Windows used to display input video with bounding rectangles   
   // and the thresholded video   
   cvNamedWindow( "video" );   
   cvNamedWindow( "thresh" );      
   // An infinite loop   
   while( key != 'x' )   
   {   
     // If we couldn't grab a frame... quit   
     if( !( frame = cvQueryFrame( capture ) ) )   
       break;      
     // Get object's thresholded image (blue = white, rest = black)   
     IplImage* imgThresh = GetThresholdedImageHSV( frame );      
     // Detect the white blobs from the black background   
     blobs = CBlobResult( imgThresh, NULL, 0 );    
     // Exclude white blobs smaller than the given value (10)    
     // The bigger the last parameter, the bigger the blobs need    
     // to be for inclusion    
     blobs.Filter( blobs,   
            B_EXCLUDE,   
            CBlobGetArea(),   
            B_LESS,   
            10 );        
     // Attach a bounding rectangle for each blob discovered   
     int num_blobs = blobs.GetNumBlobs();   
     for ( int i = 0; i < num_blobs; i++ )      {        currentBlob = blobs.GetBlob( i );       cvRect = currentBlob->GetBoundingBox();   
       pt1.x = cvRect.x;   
       pt1.y = cvRect.y;   
       pt2.x = cvRect.x + cvRect.width;   
       pt2.y = cvRect.y + cvRect.height;   
       // Attach bounding rect to blob in orginal video input   
       cvRectangle( frame,   
              pt1,    
              pt2,   
              cvScalar(0, 0, 0, 0),   
              1,   
              8,   
              0 );   
     }   
     // Add the black and white and original images   
     cvShowImage( "thresh", imgThresh );   
     cvShowImage( "video", frame );   
     // Optional - used to slow up the display of frames   
     key = cvWaitKey(1);   
     // Prevent memory leaks by releasing thresholded image   
     cvReleaseImage( &imgThresh );      
   }  
   // We're through with using camera.    
   cvReleaseCapture( &capture );   
   return 0;   
 }   


Compile and build test.cpp along with the source files and the output will look like this

Output



Video




4 comments:

mahi said...

Good a work

jonathan said...

Hi , i have a problem when start debug

Cannot open include file: 'cxtypes.h': No such file or directory.
Can you help me?

1>------ Build started: Project: Neural_network_handwritten, Configuration: Debug Win32 ------
1>Build started 04-05-2013 14:40:19.
1>InitializeBuildStatus:
1> Touching "Debug\Neural_network_handwritten.unsuccessfulbuild".
1>ClCompile:
1> main.cpp
1>c:\cvblobslib\blobcontour.h(7): fatal error C1083: Cannot open include file: 'cxtypes.h': No such file or directory
1> ComponentLabeling.cpp
1>c:\opencv245\include\opencv2\flann\logger.h(66): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(234) : see declaration of 'fopen'
1>c:\cvblobs8.3_linux\componentlabeling.cpp(318): warning C4244: 'argument' : conversion from 'short' to 't_chainCode', possible loss of data
1>c:\cvblobs8.3_linux\componentlabeling.cpp(346): warning C4244: 'argument' : conversion from 'short' to 't_chainCode', possible loss of data
1> BlobResult.cpp
1>c:\opencv245\include\opencv2\flann\logger.h(66): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(234) : see declaration of 'fopen'
1>c:\cvblobs8.3_linux\blobresult.cpp(934): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(234) : see declaration of 'fopen'
1> BlobProperties.cpp
1> BlobOperators.cpp
1>c:\opencv245\include\opencv2\flann\logger.h(66): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(234) : see declaration of 'fopen'
1> BlobContour.cpp
1>c:\opencv245\include\opencv2\flann\logger.h(66): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(234) : see declaration of 'fopen'
1> blob.cpp
1>c:\cvblobs8.3_linux\blob.cpp(586): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\cvblobs8.3_linux\blob.cpp(587): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\cvblobs8.3_linux\blob.cpp(592): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\cvblobs8.3_linux\blob.cpp(603): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\cvblobs8.3_linux\blob.cpp(624): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1> Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:09.03
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Lentin Joseph said...

Hi, Can you build it in release mode instead of Debug?

Anonymous said...

jonathan, there is no 'cxtypes.h' in OpenCV anymore, it has been renamed. Rename 'cxtypes.h' to 'cxcore.h' in your code.

Post a Comment