Resize an array of images with OpenCV
Posted
by
amr
on Stack Overflow
See other posts from Stack Overflow
or by amr
Published on 2011-01-10T23:55:47Z
Indexed on
2011/01/11
0:53 UTC
Read the original article
Hit count: 317
I'm passing an array of images (IplImage**) to an object in C++ using OpenCV. I'm then trying to iterate over that array and resize them all to a fixed size (150x150)
I'm doing it this way:
for(int i = 0; i< this->numTrainingFaces; i++)
{
IplImage* frame_copy = cvCreateImage( cvSize(150,150), this->faceImageArray[0]->depth, this->faceImageArray[0]->nChannels );
cout << "Created image" << endl;
cvResize(this->faceImageArray[i], frame_copy);
cout << "Resized image" << endl;
IplImage* grey_image = cvCreateImage( cvSize( frame_copy->width, frame_copy->height ), IPL_DEPTH_8U, 1 );
cout << "Created grey image" << endl;
cvCvtColor( frame_copy, grey_image, CV_RGB2GRAY );
cout << "Converted image" << endl;
this->faceImageArray[i] = grey_image;
cvReleaseImage(&frame_copy);
cvReleaseImage(&grey_image);
}
But I'm getting this output, and I'm not sure why:
Created image
Resized image
Created grey image
Converted image
Created image
OpenCV Error: Assertion failed (src.type() == dst.type()) in cvResize, file /build/buildd/opencv-2.1.0/src/cv/cvimgwarp.cpp, line 3102
terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.1.0/src/cv/cvimgwarp.cpp:3102: error: (-215) src.type() == dst.type() in function cvResize
Aborted
I'm basically just trying to replace the image in the array with the resized one in as few steps as possible.
Edit:
Revised my code as follows:
for(int i = 0; i< this->numTrainingFaces; i++)
{
IplImage* frame_copy = cvCreateImage( cvSize(150,150), this->faceImageArray[i]->depth, this->faceImageArray[i]->nChannels );
cvResize(this->faceImageArray[i], frame_copy);
IplImage* grey_image = cvCreateImage( cvSize( frame_copy->width, frame_copy->height ), IPL_DEPTH_8U, 1 );
cvCvtColor( frame_copy, grey_image, CV_RGB2GRAY );
faceImageArray[i] = cvCreateImage( cvSize(grey_image->width, grey_image->height), grey_image->depth, grey_image->nChannels);
cvCopy(grey_image,faceImageArray[i]);
cvReleaseImage(&frame_copy);
cvReleaseImage(&grey_image);
}
Then later on I'm performing some PCA, and get this output:
OpenCV Error: Null pointer (Null pointer to the written object) in cvWrite, file /build/buildd/opencv-2.1.0/src/cxcore/cxpersistence.cpp, line 4740
But I don't think my code has got to the point where I'm explicitly calling cvWrite, so it must be part of the library. I can give a full implementation if necessary - is there anything in my code that's going to create a null pointer?
© Stack Overflow or respective owner