问题描述:

I am currently trying to crop a large matrix of images using Magick++. I am looping through all of the images and cutting each one into a 3x3 grid of tiles to get their average RGB values. Currently the below code works fine for the first image, but on the 10th iteration (the second image in the matrix), the program throws an error ("libc++abi.dylib: terminate called throwing an exception\n Abort trap: 6") on the crop step. I have looked at this over and over and can not seem to find any issue with the geometry math. Any help would be much appreciated, thanks!

slices is the matrix of images each of which is a 12x12 pixel image. averages is an array of RGB values which is a self-defined struct containing 3 ints (red, green, and blue).

void ImageSlicer::calculateRGBValues() {

int subwidth = 612 / numSlices;

int subheight = 612 / numSlices;

int average_subwidth = subwidth / cutSize;

int average_subheight = subheight / cutSize;

for (int x = 0; x < numSlices; x++) {

for (int y = 0; y < numSlices; y++) {

Image currentSlice = slices[x][y];

for (int i = 0; i < cutSize; i++) {

for (int j = 0; j < cutSize; j++) {

Image cropped = currentSlice;

cropped.crop(Geometry(average_subwidth,

average_subheight,

i * average_subwidth,

j * average_subheight,

false,

false));

cropped.scale(Geometry(1,1));

ColorRGB pixel = cropped.pixelColor(1,1);

RGB avg;

avg.red = pixel.red() * 255;

avg.green = pixel.green() * 255;

avg.blue = pixel.blue() * 255;

averages.push_back(avg);

}

}

}

}

}

相关阅读:
Top