I Have following source code to detect BLOB and i am using MS 2008 , OpenVC 2.1
#include "stdafx.h"
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
/*You may change the values of the sthreshold and hlower and hupper to get different results....*/
const int sthreshold=210;
const double hlower=178;
const double hupper=3;
int main(int argc, char* argv[]) {
int i,j,k;//for iterations
int height,width,step,channels;/*HSV means the frame after color conversion*/
int heightmono,widthmono,stepmono,channelsmono;/*mono means the frame which has the monochrome image*/
const char string1[]="monoimg.avi";/*This is the name of the video which would be the outcome of the blob detection program..*/
uchar *data,*datamono;
i=j=k=0;
IplImage *frame = 0;
int key = 0;/*Initializing the capture from the video...*/
CvCapture* capture = cvCreateFileCapture( "partofvideo3.avi" );
double fps = cvGetCaptureProperty (/*getting the capture properties......the frame rate..*/
capture,CV_CAP_PROP_FPS);
CvSize size = cvSize(
(int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH),
(int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT)
);
CvVideoWriter *writer=cvCreateVideoWriter(string1, CV_FOURCC('D', 'I', 'V', 'X') ,fps,size) ;
if(writer !=NULL)
printf("Loaded\n");
else
printf("Not Loaded\n");
/* always check */
if (!capture) {
fprintf (stderr, "Cannot open video file!\n");
return(1);
}
height = frame->height;
width = frame->width;
step = frame->widthStep;
channels = frame->nChannels;
data = (uchar *)frame->imageData;
cvNamedWindow("monoimage", CV_WINDOW_AUTOSIZE);
cvNamedWindow("original frame", CV_WINDOW_AUTOSIZE);
for (;;) {/*keep looping till we are out of frames...*/
if (!cvGrabFrame(capture)) {
break;
}
frame = cvRetrieveFrame(capture);
IplImage *colimgbot = cvCreateImage( cvGetSize(frame), 8, 3 );
IplImage *monoimgbot = cvCreateImage( cvGetSize(frame), 8, 1 );
cvCvtColor(frame,frame,CV_RGB2HSV);
for(i=0;i< (height);i++)
{
for(j=0;j<(width);j++)
{
if((data[(height-i)*step+j*channels]<=hlower) && (data[(height-i)*step+j*channels]>=hupper))
{
if((data[(height-i)*step+j*(channels)+1])>sthreshold)
/*"height-i" because if we use only "i" we were getting vertically inverted result...hence reinverting the same
would do the required....*/
datamono[i*stepmono+j*channelsmono]=255;
else
datamono[i*stepmono+j*channelsmono]=0;}
else datamono[i*stepmono+j*channelsmono]=0;
}
}
cvErode(monoimgbot,monoimgbot,0,14);
cvDilate( monoimgbot,monoimgbot,0,15);
cvWriteFrame(writer, monoimgbot);
cvShowImage("original frame", frame);
cvShowImage("monoimage", monoimgbot);
if( (cvWaitKey(10) & 255) == 27 ) break;
}
cvReleaseVideoWriter(&writer) ;
cvDestroyWindow("monoimage");
cvReleaseCapture(&capture);
return 0;
}
when i run the program i am getting following run time error when following line encounters
CvVideoWriter* writer=cvCreateVideoWriter(string1, CV_FOURCC( ‘D’,'I’,'V’,'X’),fps,size) ;
Output #0 , avi , to ‘monoimg.avi’ : Stream #0.0: Video mgeg4, yuv420p, q=2-31, 90k tbn [mpeg4 @ 0x37e5c0] framerate not set OpenCV Error: Bad Argument (Could not open codec ‘mpeg 4′:Unspecified Error) in unknown function , file C:\User\VP\ocv\opencv\src\highgui\cvcap_ffmpeg.cpp, line 1306