2

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!

1
  • 2
    Start using the C++ API of OpenCV! Commented Jan 7, 2011 at 15:52

3 Answers 3

2

images is just an array of IplImage pointers so the following should work:

IplImage** images = (IplImage**) malloc(sizeof(IplImage*)*maxImNumber)

Sign up to request clarification or add additional context in comments.

Comments

1

or better yet vector images ... and then images.pushback(newImage) on each loop

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.