Creating new image in a loop using OpenCV
I am programing some image conversion code with OpenCV and I don't know how can I create image memory buffer to load image on every iteration. I have number of iteration (maxImNumber) and I have an input image. In every loop program must create image that is resized and modified input image. Here is some basic code (concept).
for (int imageIndex = 0; imageIndex < maxImNumber; imageIndex++){
cvCopy(inputImage, images[imageIndex], 0);
cvReleaseImage(&inputImage);
images[imageIndex+1] = cvCreateImage(cvSize((image[imageIndex]->width)/2, image[imageIndex]->height), IPL_DEPTH_8U, 1);
for (i=1; i < image[imageIndex]->height; i++) {
index = 0; //
for(j=0; j < image[imageIndex]->width ; j=j+2){
// doing some basic matematical operation on image content and store it to new image
images[imageIndex+1][i][index] = (image[imageIndex][i][j] + image[imageIndex][i][j+2])/2;
index++
}
}
开发者_如何学运维inputImage = cvCreateImage(cvSize((image[imageIndex+1]->width), image[imageIndex]->height), IPL_DEPTH_8U, 1);
cvCopy(images[imageIndex+1], inputImage, 0);
}
Can somebody, please, explain how can I create this image buffer (images[]) and allocate memory for it. Also how can I access any image in this buffer?
Thank you very much in advance!
images
is just an array of IplImage
pointers so the following should work:
IplImage** images = (IplImage**) malloc(sizeof(IplImage*)*maxImNumber)
or better yet vector images ... and then images.pushback(newImage) on each loop
Use an std::vector<IplImage*> images(maxImNumber)
.
Iterate over it once to allocate all images using, e.g. cvCreateImage()
or cvCloneimage()
.
When you are done with it iterator over it again and cvReleaseImage()
all the images.
精彩评论