Hello.
I've spent many hours on this code and I cannot figure out why when I either declare "kot" - which will be in the code below or when I call blob_detect() which uses included .cpp with a "new" call (so to speak) I get an error allocating memory. If someone can take a look and please suggest anything. Thank you in advance
PS. Using Visual Studio 2008 in a XP machine.
#include "stdafx.h"
#include "cv.h"
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <highgui.h>
//#include <time.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <ctime>
#include "blob.h"
#include "BlobExtraction.h"
#include "BlobLibraryConfiguration.h"
#include "BlobResult.h"
using namespace std;
#ifndef PATH_MAX
#define PATH_MAX 512
#endif /* PATH_MAX */
void blob_detect(IplImage* img, CvSeq* objects, double thresh, int maxBlobArea, int minBlobArea);
typedef struct ObjectPos
{
float x;
float y;
float width;
float height;
int found; /* for reference */
int neghbors;
} ObjectPos;
CvSeq* objects;
CvMemStorage* storage;
//int main( int argc, char* argv[] )
int main()
{
int i, j;
int saveDetected = 1;
double scale_factor = 1.2;
float maxSizeDiff = 1.5F;
float maxPosDiff = 0.3F;
FILE* info;
char* infoname;
char* fullname[PATH_MAX];
char detfilename[PATH_MAX];
char* filename;
char detname[] = "det-";
/* Global Assignments. They should be put interactively eventually*/
/*double threshold = 100;
double minBlobArea = 10, maxBlobArea = 300;*/
filename = "kot1.txt";
saveDetected = 0;
infoname = "kot1.txt";
info = fopen(infoname, "r");
if( info != NULL )
{
int x, y, width, height;
IplImage* img;
int hits, missed, falseAlarms;
int totalHits, totalMissed, totalFalseAlarms;
int found;
float distance;
int refcount;
ObjectPos* ref;
int detcount;
ObjectPos* det;
int error;
int* pos;
int* neg;
pos = (int*) cvAlloc( 40 * sizeof( *pos ) );
neg = (int*) cvAlloc( 40 * sizeof( *neg ) );
for( i = 0; i < 40; i++ ) { pos[i] = neg[i] = 0; }
printf( "+================================+======+======+======+\n" );
printf( "| File Name | Hits |Missed| False|\n" );
printf( "+================================+======+======+======+\n" );
totalHits = totalMissed = totalFalseAlarms = 0;
storage = cvCreateMemStorage();
filename = new char;
while( !feof( info ) )
{
//char * imgName = new char[];
//filename = new char;
if( fscanf( info, "%s %d", filename, &refcount ) != 2 || refcount <= 0 ){ break;}
int * kot = new int [333]; //this is the test pointer I'm using to test where the memory allocation starts to fail. If this variable is declared before the if(fscanf(... ...)) it allocates fine. but here it fails.
//img = cvLoadImage( fullname );
img = cvLoadImage( filename, CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR );
if( !img ) continue;
ref = (ObjectPos*) cvAlloc( refcount * sizeof( *ref ) );
for( i = 0; i < refcount; i++ )
{
error = (fscanf( info, "%d %d %d %d", &x, &y, &width, &height ) != 4);
if( error ) break;
ref[i].x = 0.5F * width + x;
ref[i].y = 0.5F * height + y;
ref[i].width = sqrtf( 0.5F * (width * width + height * height) );
ref[i].found = 0;
ref[i].neghbors = 0;
}
if( !error )
{
cvClearMemStorage( storage );
objects = cvCreateSeq(0, sizeof(CvSeq), sizeof(CvRect), storage);
/***************************** Insert here detector *********************************/
blob_detect(img, objects, 100, 10, 100); // this is a function which calls .cpp files that are in the same folder. They are called as I've traced it using the debug functionality in VS '08. There is a function there also that uses 'new' where it fails as well.
/************************** END DETECTOR *****************************************/
} /* if( !error )*/
}/*while( !feof( info ) )*/
}/* if( info != NULL )*/
fclose(info);
return 0;
}
Any help would be greatly appreciated.