When I run the following program with scalefactory higher than 1.5, the program throws an EXC_BAD_ACCESS. The program scales an image.
#include <iostream>
#include <OpenCV/cv.h>
#include <OpenCV/highgui.h>
#include <cmath>
using namespace std;
using namespace cv;
int scale (int xyvalue, float scalefactor) {
return ceil(xyvalue/scalefactor);
}
int main () {
Mat input;
float scalefactorx = 1.5;
float scalefactory = 1.5;
Mat output;
input = imread("/tmp/plum_grey_scale_MC_.low.jpg", 0);
output = cvCreateMat(input.size().height*scalefactory, input.size().width*scalefactorx, input.type());
for (int y = 0; y<output.size().height; y++)
{
for (int x = 0; x<output.size().width; x++)
{
output.data[y*output.size().width+x] = input.data[scale(y,scalefactory)*input.size().width + scale(x,scalefactorx)];
}
}
namedWindow("pic1", CV_WINDOW_AUTOSIZE);
imshow("pic1", output);
cvWaitKey(0);
cvDestroyWindow("BlomsterBillede");
return 0;
}
If e.g. I set scalefactorx = 5, scalefactory = 2, it fails around x=1356 and y=409.
Hope you can help me.