Skip to search.
OpenCV · Open Source Computer Vision Library Comm

Group Information

  • Members: 30001
  • Category: Open Source
  • Founded: Jun 20, 2000
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Messages

  Messages Help
Advanced
how to do blob extraction -- very urgent!!!!!!!!!!!!!!   Message List  
Reply Message #59936 of 87940 |
hai

friends , i am new to open cv i need your help

i need to do blob extraction, to find out a region of interest from a
sequence of frame ( from video file). i have captured the video file
and extracted to frames and using frame difference Back ground is
subtracted

(here i am using a test video having still background and moving
vehicle , my aim is to extract the vehicle and count and classify them
(based on size or length))

now i want to extract the blob reagion (the vehicles - and draw a
rectangle over them and count and measure the size of rectangle)

============================================================

here is my code for capturing video extracting frame and back ground
subtraction using frame difference (most of the part code i have got
from net - thanks for the unknown authors)


// program for back ground detectio (subtraction)
//using cvAbsDiff difference between two frame
// this program take avi file as input and then extract the forground and
//background
// forground object canny edge detction also doing


// umeshnarayanan modified on 2009 jan 27



#include "cv.h"
#include "cvaux.h"
//#include "cvcam.h" for cam
#include "highgui.h"
#include <ctype.h>
#include <stdio.h>

IplImage *frame1 = NULL, *frame2 = NULL, *frame3 = NULL;
IplImage *diff1 = NULL, *diff2 = NULL, *result = NULL;
IplImage* cannyImg;
IplImage *grayImg = 0; // gray image

int main(int argc, char** argv)
{
int height,width,step,channels;
uchar *data1, *data2, *data3, *diffData1, *diffData2, *resultData;

int i, j;

int threshold = 30;

int diff;

/* Start capturing */

CvCapture* capture = 0;

/*capturing from cam
if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 &&
isdigit(argv[1][0])))
capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
else if( argc == 2 )
capture = cvCaptureFromAVI( argv[1] );
*/

capture = cvCaptureFromAVI( "car.avi" );


int mode = CV_RETR_EXTERNAL;

mode = CV_RETR_CCOMP; //detect both outside and inside contour


if( !capture )

{

fprintf(stderr,"Could not initialize...\n");
return -1;

}

/* Capture 1 video frame for initialization */

frame2 = cvQueryFrame(capture); // retrive from the video
frame3 = cvQueryFrame(capture);

/* Create windows */

cvNamedWindow("Actual Video", 1); // creating window

cvNamedWindow("With Differencing", 1);
cvMoveWindow("With Differencing", 500,0);
cvNamedWindow("BackGround", 1);
cvMoveWindow("BackGround", 0,350);

cvNamedWindow("canny Edge",1);
cvMoveWindow("canny Edge", 750, 350);

CvBGStatModel* bg_model;

bg_model =cvCreateGaussianBGModel( frame2 );

/* Get properties of frame */

width = frame2->width;
height = frame2->height;
step = frame2->widthStep;
channels = frame2->nChannels;

int key=-1;
while(key != 'q')
{

/* Get consecutive frames */

frame1 = cvCloneImage(frame2);

// cvReleaseData(frame2);
// cvReleaseImage(&frame2);

frame2 = cvCloneImage(frame3);

// cvReleaseData(frame3);
// cvReleaseImage(&frame);

frame3 = cvQueryFrame(capture);

/* Initialize difference and result frames */
diff1 = cvCloneImage(frame3);
diff2 = cvCloneImage(frame3);
result = cvCloneImage(frame3);



/* Image is treated as as unsigned char data hence we use an
unsigned char pointer to point to the same to access pixels */

data1 = (uchar *)frame1->imageData;
data2 = (uchar *)frame2->imageData;
data3 = (uchar *)frame2->imageData;

diffData1 = (uchar *)diff1->imageData;
diffData2 = (uchar *)diff2->imageData;
resultData = (uchar *)result->imageData;

/* Get difference of frames */

cvAbsDiff(frame2,frame1,diff1);
cvAbsDiff(frame3,frame2,diff2);

cvUpdateBGStatModel( frame2, bg_model );

// canny edge detection


// Check for threshold

for(i=0;i<=height-1;i++)
{
for(j=0;j<=width-1;j++)
{
//Difference depends on sum of pixels on each channel

if(((diffData1[i*step+j*channels+0] +
diffData1[i*step+j*channels+1] + diffData1[i*step+j*channels+2]) >
threshold) && ((diffData2[i*step+j*channels+0] +
diffData2[i*step+j*channels+1] + diffData2[i*step+j*channels+2]) >
threshold))
{
resultData[i*step+j*channels+0] = 255;
resultData[i*step+j*channels+1] = 255;
resultData[i*step+j*channels+2] = 255;
}
else
{
resultData[i*step+j*channels+0] = 0;
resultData[i*step+j*channels+1] = 0;
resultData[i*step+j*channels+2] = 0;
}
}
}//end of frame differencing with binarization

grayImg = cvCreateImage( cvSize(result->width, result->height),
IPL_DEPTH_8U, 1 );

//convert original color image (3 channel rgb color image) to
gray-level image
cvCvtColor( result, grayImg, CV_BGR2GRAY );
cannyImg = cvCreateImage(cvGetSize(result), IPL_DEPTH_8U, 1);

cvCanny(grayImg, cannyImg, 50, 150, 3);





cvShowImage("Actual Video",frame2);
cvShowImage("With Differencing",result);
cvShowImage("BackGround", bg_model->background);
cvShowImage("canny Edge", cannyImg);


// cvReleaseData(frame1);
cvReleaseImage(&frame1);
// cvReleaseData(diff1);
cvReleaseImage(&diff1);
// cvReleaseData(diff2);
cvReleaseImage(&diff2);
// cvReleaseData(result);
cvReleaseImage(&result);

key = cvWaitKey(10);
}//end of while


cvDestroyWindow("Actual Video");
cvDestroyWindow("With Differencing");
cvDestroyWindow("BackGround");
cvDestroyWindow("canny");
cvReleaseCapture(&capture);

return 0;
}



please help me its very urgent ,thanking you in advance

you can contact me

umeshnarayanan1@...
umeshnarayanan@...





Thu Jan 29, 2009 7:31 am

umeshnarayanan
Offline Offline
Send Email Send Email

Message #59936 of 87940 |
Expand Messages Author Sort by Date

hai friends , i am new to open cv i need your help i need to do blob extraction, to find out a region of interest from a sequence of frame ( from video file)....
umeshnarayanan Offline Send Email Jan 29, 2009
7:31 am

try cvblobslib: http://opencv.willowgarage.com/wiki/cvBlobsLib Regards ... forground and...
rickypetit Offline Send Email Jan 29, 2009
2:34 pm

i have alrady visited http://opencv.willowgarage.com/wiki/cvBlobsLib for blob library extraction but still i am not able to understand the things clearely...
umeshnarayanan Offline Send Email Jan 30, 2009
10:13 am

for blob extraction with out using the blob extraction library their is an interesting code (for white region detection) found in http://geekblog.nl/entry/24 ...
umeshnarayanan Offline Send Email Feb 4, 2009
4:04 am

Blob extraction ============= Blob extraction is an image segmentation technique that categorizes the pixels in an image as belonging to one of many discrete...
umeshnarayanan Offline Send Email Feb 6, 2009
10:43 am

sample program to perform blob extractio ========================================= it will take an image then convert to gray then blobs are detecting ...
umeshnarayanan Offline Send Email Feb 6, 2009
10:46 am

this program is used for blob detection for moving objects in a video file first- video is captured then ,extracted to frames ,then background is extracted...
umeshnarayanan Offline Send Email Feb 6, 2009
10:49 am

hi this program is great.. by the way, i need to modify the program to highlight the rectangle moving blob in yellow when it crosses a white vertical marker...
yllui001 Offline Send Email Aug 14, 2009
5:02 pm
Advanced

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help