The problem is that you are trying to assign the IplImage*
returned from cvLoadImage()
to the IplImage
dereferenced from images[i]
. You cannot convert between the two types.
A quick fix for this could be to dereference the pointer returned from cvLoadImage()
, like so:
images[i] = *cvLoadImage( imgName, CV_LOAD_IMAGE_UNCHANGED );
This might work, but it seems a little unorthodox to me.
A better solution would be to not dynamically allocate the IplImage
yourself, but instead keep an array of IplImage*
on the stack:
#define NUM_IMAGES 6;
IplImage *images[NUM_IMAGES];
for (int i = 0; i < NUM_IMAGES ; i++ ){
char *num = (char *)malloc( sizeof(int) );
char *extension = ".jpg";
sprintf( num, "%d", i );
int nameLen = strlen( num ) + strlen( extension ) + 1;
char *imgName = (char *)malloc( nameLen );
strlcpy( imgName, num, nameLen );
strlcat( imgName, extension, nameLen );
images[i] = cvLoadImage( imgName, CV_LOAD_IMAGE_UNCHANGED );
}
/* Release the image memory */
for (size_t i = 0; i < NUM_IMAGES; ++i)
{
cvReleaseImage(&images[i]);
}
If for some reason you must dynamically allocate, then do it with pointers instead. Replace the first line of my example with:
IplImage** images = (IplImage**)malloc(sizeof(IplImage*) * 6);
and then place a free(images);
at the very end.
As a side note, if at all possible, consider switching to the C++ API. You will save yourself so much pain.