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