私は C++ の知識があまりなく、他の誰かが開発したファイルを使用して、自分のイメージに autoLocalThresholding を適用しています。
これが私がメソッドを呼び出す方法です..
UIImage *newImage = [imageProcessing resizeImage:image];
ImageWrapper *greyScale=Image::createImage(newImage, newImage.size.width, newImage.size.height);
ImageWrapper *edges=greyScale.image->autoLocalThreshold();
そして、ここにこれらの関数の定義があります..
ImageWrapper* Image::autoLocalThreshold() {
const int local_size=8;
// now produce the thresholded image
uint8_t *result=(uint8_t*) malloc(m_width*m_height);
// get the initial total
int total=0;
for(int y=0; y<local_size; y++) {
for(int x=0; x<local_size; x++) {
total+=(*this)[y][x];
}
}
// process the image
int lastIndex=m_width*m_height-(m_width*local_size/2+local_size/2);
for(int index=m_width*local_size/2+local_size/2; index<lastIndex; index++) {
int threshold=total/64;
if(m_imageData[index]>threshold*0.9)
result[index]=0;
else
result[index]=255;
// calculate the new total
for(int index2=index-m_width*local_size/2-local_size/2; index2<index+m_width*local_size/2-local_size/2; index2+=m_width) {
total-=m_imageData[index2];
total+=m_imageData[index2+local_size];
}
}
return Image::createImage(result, m_width, m_height, true);
}
これにより、この行でEXEC_BAD_ACCESSエラーが発生します..
total+=(*this)[y][x];
なぜこれが起こっているのか、そしてその救済策は何なのか説明できますか? オープン ソース ファイルはこちらから入手できます。https://code.google.com/p/simple-iphone-image-processing/source/browse/trunk/Classes/Image.mm?r=15
また、これは毎回ではなく時々発生します。 前もって感謝します