Professional Documents
Culture Documents
Search
About
OpenCV
Signal Processing
HPC
Previous Next
pdfcrowd.com
cvblobs is a blob library for OpenCV available at http://code.google.com/p/cvblob/ To use this library in codeblocks just unzip the downloaded library and copy the cvblob.h header file to the headers directory in opencv in my case it is C:\opencv2.0\include\opencv. Then add the rest of the files to your project by right clicking on the project and selecting add files. Here is a example for tracking an yellow colored object using this blob library
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 //OpenCV Headers #include<cv.h> #include<highgui.h> //Input-Output #include<stdio.h> //Blob Library Headers #include<cvblob.h> //Definitions #define h 240 #define w 320 //NameSpaces using namespace cvb; using namespace std; int main() { //Structure to get feed from CAM CvCapture* capture=cvCreateCameraCapture(0);
pdfcrowd.com
18 19 20 21 22 23 24
25
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
//Structure to hold blobs CvBlobs blobs; //Windows cvNamedWindow("Live",CV_WINDOW_AUTOSIZE); //Image Variables IplImage *frame=cvCreateImage(cvSize(w,h),8,3); //Original Image IplImage *hsvframe=cvCreateImage(cvSize(w,h),8,3);//Image in HSV color space IplImage *labelImg=cvCreateImage(cvSize(w,h),IPL_DEPTH_LABEL,1);//Image Variable for blobs IplImage *threshy=cvCreateImage(cvSize(w,h),8,1); //Threshold image of yellow color //Getting the screen information int screenx = GetSystemMetrics(SM_CXSCREEN); int screeny = GetSystemMetrics(SM_CYSCREEN); while(1) { //Getting the current frame IplImage *fram=cvQueryFrame(capture); //If failed to get break the loop if(!fram) break; //Resizing the capture cvResize(fram,frame,CV_INTER_LINEAR ); //Flipping the frame cvFlip(frame,frame,1); //Changing the color space cvCvtColor(frame,hsvframe,CV_BGR2HSV); //Thresholding the frame for yellow cvInRangeS(hsvframe,cvScalar(23,41,133),cvScalar(40,150,255),threshy); //Filtering the frame cvSmooth(threshy,threshy,CV_MEDIAN,7,7); //Finding the blobs unsigned int result=cvLabel(threshy,labelImg,blobs); //Rendering the blobs
pdfcrowd.com
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
cvRenderBlobs(labelImg,blobs,frame,frame); //Filtering the blobs cvFilterByArea(blobs,60,500); for (CvBlobs::const_iterator it=blobs.begin(); it!=blobs.end(); ++it) { double moment10 = it->second->m10; double moment01 = it->second->m01; double area = it->second->area; //Variable for holding position int x1; int y1; //Calculating the current position x1 = moment10/area; y1 = moment01/area; //Mapping to the screen coordinates int x=(int)(x1*screenx/w); int y=(int)(y1*screeny/h); //Printing the position information cout<<"X: "<<x<<" Y: "<<y<<endl; } //Showing the images cvShowImage("Live",frame); //Escape Sequence char c=cvWaitKey(33); if(c==27) break; } //Cleanup cvReleaseCapture(&capture); cvDestroyAllWindows(); }
Here we are taking live feed from the cam and thresholding it for yellow color. Then we are smoothing it with a median filter and finding the blobs. Then we are rendering them so that we can see
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
them. cvFilterByArea removes any blobs which are too big or too small to be called a blob. Then we are finding their moments,dividing them by their area we get the X and Y positions. The result is as follows
pdfcrowd.com
AD VE R T ISE M E N T
EXCLUSI VE: "stolen" security camera footage from jennifer aniston's house (secrets revealed by smartwater)
Facebook 10
Twitter 1
Like
This entry was posted in OpenCV and tagged blob detection, Detecing objects using blobs, tracking colored objects by 8a52labs. Bookmark the permalink.
pdfcrowd.com
i tried your program,but i cant run it.. the error message tell me the problem is on my memory..what you suggest to me to fix it? help me please
Reply
Hi Hendy, Can you kindly post your error here so that I can give a better answer . Have you used cvBlob library? It can be downloaded from http://code.google.com/p/cvblob/ Just unzip the folder and copy the header file to
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
include folder in OpenCV Then add the remaining files to the project
Reply
Thanks buddy its worked well for me work and keep posting
Reply
I appreciate your
Pingback: Triggering keyboard events using image processing 8A52labs Pingback: Triggering Mouse Events 8A52labs
pdfcrowd.com
contents and very useful to me, can u tell me how to do dct idct for an rgb image, i tried using cvSplit, but when i use each channel in dct() the error msg isthe function/feature is not implemented (Odd-size DCTs are not implemented in function cvDCT) what is the solution for this,but wihen i used gray image it is working ,i dont know wat is the problem?
Reply
Hi, I am glad you are finding my blog useful. cvDCT supports only even numbered arrays like 2,4,6 etc So I suggest you to pad the matrix if your array is odd numbered
Reply
pdfcrowd.com
Hi, this is Koko and I would just like to clarify some things with cvBlob. first, this is the file you download right cvblob-0.10.3src.zip second, when you say Then add the rest of the files to your project by right clicking on the project and selecting add files. would the rest of the files be the source files also in the file that you download, being the C++ source files: cvaux cvblob cvcolo cvcontour cvlabel cvtrack thank you again for your support
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
Reply
Hi, Yeh,that is the correct file. Yeh,Add the source files also as they will be compiled along with your own code in main.c
Reply
Thanks for the quick reply! I am happy to say that everything worked fine, this really helped me out. Was almost about to give up on cvBlob before I saw this XD
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
I am happy that you found my blog useful. Yeh, that was the real intention. No one should suffer the frustration i suffered .
Hello again, Would you know a place where I can check for example uses of the functions in cvblob? I have been checking the function declarations in the document
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
provided by the cvblob website, but the information is somewhat limited. One example would be cvRenderBlob, I have read that it can draw or print the data of the blobs. Well in most examples the blobs are being drawn, but I would like the data of the blobs to be printed. Thanks again for your help
Reply
pdfcrowd.com
Counting blobs is equal to counting the labels given in the render. My function for counting blobs is as follows //Function to find the number of blobs of the given color int findnumber(IplImage *frame,IplImage *threshy,IplImage *labelImg) { //Variable to hold no of blobs int label=0; //Structure to hold the blobs CvBlobs blobs; //Finding the blobs unsigned int result=cvLabel(threshy,labelImg,blobs); //Rendering the blobs cvRenderBlobs(labelImg,blobs,frame,frame); //Filtering the blobs cvFilterByArea(blobs,60,500); for (CvBlobs::const_iterator it=blobs.begin(); it!=blobs.end(); ++it)
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
Hi The VS2010 ask me for a cxtypes.h header (belongs to the first version of OpenCV) and cant compile it. Any Idea?
Reply
pdfcrowd.com
hello, Im using your code and I have some error compiling it, Ill be very glad if youll help me. the error I constantly get are : ./src/HelloWorld.o: undefined reference to symbol cvFlip and the same for all cv functions what seems to be the problem in your opinion? thank you!! Yokhai en.yokhai@gmail.com
Reply
pdfcrowd.com
and headers
Reply
solved it the program starts to run , the camera turns on, and suddenly shuts down with (Live:6042): Gtk-WARNING **: Unable to locate theme engine in module_path: pixmap, error. what does it mean?
Reply
pdfcrowd.com
Maybe u have not installed the GTK sudo aptitude install gtk2-engines-pixbuf might work
Hi.I tried your code in Codeblocks 8.02 on Ubuntu 10.04 LTSand i am getting an error saying that GetSystemMetrics,SM_CXSCREEN,SM_CXSCREEN are not defined in this scope Can you help me with that please..???
Reply
Hi,
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
I used that function to get the resolution of the monitor. Unfortunately it is win32 function. I have no idea about its parallel in Linux but the nearest answer i found is this http://stackoverflow.com/questions/1153052/how-toprogrammatically-get-the-resolution-of-a-windowand-that-of-the-system-in Else u can replace with values of your screen resolution
Reply
Hi, thanks for the tutorial ! I tried your program and installed openCV & cvBlob library step by step but still have an error LNK2019:cvFilterByArea cvRenderBlobs cvLabel .
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
Have you added the sources files of cvBlob in your project (not only in the folder)? If you only add the files to your folder compiler will not compile it, so you need to add the files to your project. You need to copy the header to include folder in opencv
Reply
pdfcrowd.com
Hello Like your Post, I am following everything . but I am getting error test.obj : error LNK2019: unresolved external symbol __imp__GetSystemMetrics@4 referenced in function _main 1>C:\Users\dhut\documents\visual studio 2010\Projects\cexample\Debug\cexample.exe : fatal error LNK1120: 1 unresolved externals can you help me out please ?
Reply
pdfcrowd.com
is a linking error with GetSystemMetrics. Make sure you have included windows.h. If nothing works replace screenx and screeny with the values of ur monitor(pixel values for width and height)
Reply
Thanks For Reply. Can you tell me what I need to detect two blobs of same or different colors, locate their Centroids and find the distance between these two blobs? Plz guide me.
8a52labs
pdfcrowd.com
You can find that in my another blog post such as triggering keyboard events All u need to do is have two threshold image for two different colors say green and yellow and pass them to a blob detect functions
Hi, I just Include #pragma comment(lib, user32.lib) . and it starts working.. Thanks for sharing..
Reply
pdfcrowd.com
Hi, I am trying to compile it using VS2010 and OpenCV 2.3 and I get the next error: Error C2065: nbsp: not declared identifier //its on the line 23 I hope you can help me. Thanks for sharing.
Reply
Hi, You might have copied the code wrong. nbsp is the formatting error if u see line 23 there is nbsp replace that with line from blog
Reply
pdfcrowd.com
Hi!! yes!! It was a newbie mistake. It works perfectly. Thanks for sharing!!!
Hi Emmanuel Tapia! will you plz help me that how to run this code in VS2010 and OpenCV 2.3, I get list of errors like the following: error LNK2019: unresolved external symbol _cvSaveImageBlob referenced in function _main documents\visual studio 2010\Projects\testopencv2\testopencv2\sourcefile.obj testopencv2
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
. i have uploaded complete vs project, plz help me to fix it : https://sites.google.com/site/funitqta/files/testopencv2.rar? attredirects=0&d=1 its built in Visual studio 2010 and opencv 2.2. plz check it.
Reply
HI!, How can I get the angle of the blobs? (The angle of the green line that cross the moments in the image) Thanks for your answers!
Reply
pdfcrowd.com
double detectangle(IplImage *thresh,IplImage *mhi,double timestamp,IplImage *orient,IplImage *frame) { //Updating the motion history cvUpdateMotionHistory(thresh,mhi,timestamp,1); //Calculating motion gradient cvCalcMotionGradient( mhi,thresh, orient,.5,.05, 3 ); //Rectangle CvRect rectangle; //Setting ROI rectangle=cvRect( 0, 0,w,h); // select component ROI cvSetImageROI(frame,rectangle ); cvSetImageROI( mhi,rectangle ); cvSetImageROI( orient,rectangle); cvSetImageROI(thresh,rectangle); //Calculating the angle double angle=cvCalcGlobalOrientation(orient,thresh, mhi, timestamp,1); angle=360.0-angle;
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
Im getting this error : unresolved external symbol _cvFilterByArea referenced in function _main..I followed all the mentioned stepshelp
Reply
Remove cvFilterByArea() and try executing the program If u still get the error it means cvblobs is not attached correctly
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
Reply
Im also getting the following errors 1>testing.obj : error LNK2019: unresolved external symbol _cvFilterByArea referenced in function _main 1>testing.obj : error LNK2019: unresolved external symbol _cvRenderBlobs referenced in function _main 1>testing.obj : error LNK2019: unresolved external symbol _cvLabel referenced in function _main But i have referenced the blob library in both project folder and also in the project in vc++ What could be t reason
Reply
Emmanuel Tapia
pdfcrowd.com
Your samples are awesome!! How can I identify two or more blobs position? I want to label (or recognize) some blobs and use them as markers, then get the position of those blobs. For example, if y have only two blobs on screen, I want to label them as 1 and 2 and know their position as X1,Y1 and X2,Y2. Thanks for your knowledge!
Reply
pdfcrowd.com
I solved it, but what I want to know is if its possible to hold the blob label no matter if it changes its position, and how to do it
Reply
please post the code to identify more than one blob and to print their x and y coordinates as x1,y1 and x2 and y2 and if you cracked how to hold the blob no. and keep on printing their individual x and y in a video please post it too.
pdfcrowd.com
How would you modify the code to detect blobs in an image instead of an input camera? Thank you in advance.
Reply
Hi there, thanks for these blog it is so useful for me. This program worked perfectly on my project and I want to ask how can I track other colors for example red? Can you give red color threshold levels?Because I did not understand cvInRangeS(hsvframe,cvScalar(23,41,133),cvScalar(40,150,255),threshy);
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
I am glad that you found it useful That line is for detecting yellow u can use a red object,use slider bars in place of values to get the value for detecting a red object I have discussed this in Thresholding, Please refer that post
Reply
pdfcrowd.com
thanks for all the help firstly. we are working on a virtual mouse project that works with blob. we get lots of helps from your blog. we want to let user pick the color that he want to control mouse. i mean we want to make a code that gives thechance to pick color of blob to user. (with clicking on a color on the screen) can you give us some clues?? you are like our mentor. thanks again for all.
Reply
pdfcrowd.com
Reply
Check this post It will show how to use threshold for a specific color by adjust the slider bar http://8a52labs.wordpress.com/2011/05/17/thresholdingimages/
Reply
when i change the slider there is no change in threshold. i tried changing the initial numbers of h1,s1,v1 and it worked. so why slider bar not working instantly??
pdfcrowd.com
Have u tried the thresholding post? Study the code u will get an idea sliders are linked to variables which u have to mention in cvThreshold
you tutorial is very useful for me and i use it in my graduation project ,but i want help from you that i need more information about the blob not only there number ,i make some change and can detect red and green and blue at once but i need to different between them to use them so if you can tell me how to do this ?
Reply
pdfcrowd.com
when i am using this code with start with debugging it has problems with msyuv.dll. it is unloaded and compiler says fail toload c:\\WINDOWS\system32\msyuv.dll can not open or load PDB file. when i am using start without debuging its working fine but i have to fix it i guess to work with better achievement. any idea??
Reply
Hi! Nice tutorial. I would let you know, that I just added to my project the cvbob.h file on the header section and it worked fine, too. (I am working with cvblob 0.10.4 and windows 7). Could you, please, give me some advices on how change
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
the color of the object? I would like to track a blue object Thanks.
Reply
To detect a blue object you just have to give proper values for tresholding blue objects. Refer to the post about tresholding You can use slider control to get the values by trail and error
Reply
Hi, Your is very useful. I tried working with cvBlob but I am not
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
able to link it properly. I am working with VS2010 and OpenCV 2.1. I downloaded that cvBlob src and header files and have added them as directed in your blog. Still I am getting this error: error C2065: CvBlobs : undeclared identifier Please help me. Its very urgent. Thanks
Reply
Hi, I am an opensource person and I dont use MS products All of my blog posts are tested using CodeBlocks
Reply
pdfcrowd.com
your work is superb dear friend, but facing some problem in visual studio 2010. errors like this: error LNK2019: unresolved external symbol _cvSaveImageBlob referenced in function _main documents\visual studio 2010\Projects\testopencv2\testopencv2\sourcefile.obj testopencv2 its my project ,plz download my project here and help me to fix it please: https://sites.google.com/site/funitqta/files/testopencv2.rar? attredirects=0&d=1 plz any one can fix it, its built in Visual studio 2010 and opencv 2.2.
Reply
pdfcrowd.com
Hi, I am an opensource person and I dont use MS products All of my blog posts are tested using CodeBlocks and DeV C++
Reply
Leave a Reply
Enter your comment here...
open in browser PRO version
Are you a developer? Try out the HTML to PDF API
pdfcrowd.com
Blog at WordPress.com. |
Follow
Follow 8A52labs
Get every new post delivered to your Inbox.
Join 25 other followers
pdfcrowd.com