我正在尝试使用 leptonica 的 pixOtsuAdaptiveThreshold 函数,但运气不佳。我不确定我是否做得对,但我正在尝试获取 UIImage(objective-C),应用 pixOtsuAdaptiveThreshold,然后转换回 UIImage。当我使用传入的参数调用 pixOtsuAdaptiveThreshold 时,它会崩溃。
谁能告诉我我做错了什么?我已经为此苦苦挣扎了 2 天,我想我正在失去理智。谢谢!
代码
-(void)leptnoica:(UIImage *)image {
CGImageRef myCGImage = image.CGImage;
CFDataRef data = CGDataProviderCopyData(CGImageGetDataProvider(myCGImage));
const UInt8 *imageData = CFDataGetBytePtr(data);
PIX *myPix = (PIX *) malloc(sizeof(PIX));
myPix->w = (int)CGImageGetWidth (myCGImage);
myPix->h = (int)CGImageGetHeight (myCGImage);
myPix->d = (int)CGImageGetBitsPerComponent(myCGImage);
myPix->wpl = (CGImageGetBytesPerRow (myCGImage)/4);
// myPix->informat = IFF_TIFF;
myPix->informat= IFF_PNG;
myPix->data = (l_uint32 *) imageData;
myPix->colormap = NULL;
l_int32 one=300;
PIX *pixg;
PIX *pixB;
pixg = (PIX *) malloc(sizeof(PIX));
pixg=pixConvertTo8(myPix, 0);
l_float32 scorefract=0.1f;
pixOtsuAdaptiveThreshold(pixg, one, one, 0, 0, scorefract,NULL,&pixB);