我试图使用轻子子的pixOtsuAdaptiveThreshold函数,但运气不佳。我不确定我是否做的对,但我试图采取一个UIImage (目标-C),应用pixOtsuAdaptiveThreshold,然后转换回UIImage。当我用传入的参数调用pixOtsuAdaptiveThreshold时,它会崩溃。
有人能告诉我我做错了什么吗?两天来我一直在为这件事而奋斗,我想我已经失去理智了。谢谢!
码
-(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);发布于 2013-06-17 18:28:19
首先,您应该始终使用轻子构造函数(例如,pixCreate())和轻子访问器(例如,pixGetDimensions())。永远不要直接访问任何字段。所有访问器都会测试参数,即使输入错误,也不会使程序崩溃。有关使用示例,请参阅prog目录中的一些程序。
第二,CGImage可能有一个与轻子子不同顺序的字节,并且它可能有不同的像素和行填充。您需要理解这两种数据格式并进行适当的转换。
https://stackoverflow.com/questions/17096618
复制相似问题