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@...