0
当我运行scalefactory高于1.5的下列程序时,程序将引发EXC_BAD_ACCESS。 该程序缩放图像。OpenCV矩阵访问产生EXC_BAD_ACCESS
#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;
}
如果例如,我设置scalefactorx = 5,scalefactory = 2,它绕x = 1356和y = 409失败。
希望你能帮助我。
+1:特权可读性,总是:) – 2009-11-04 10:35:53
喂汤, 它“作品”时,我用你的方法,但输出画面的像素的每2行缺少。 – spangs 2009-11-05 17:12:32