0
显然,这段代码在最后一行cvCvtColor()中给出了错误,出了什么问题?这个功能有什么可以改进的吗?将pbm文件转换为IplImage
+(IplImage*) LoadPbmAsIplImage: (NSString*) fileName{
NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"pbm"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
NSString *content = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSArray *lines = [content componentsSeparatedByString:@"\n"];
NSString *secondLine = [lines objectAtIndex:1]; //because first line (index 0) contains meta data
int width = [secondLine length];
int height = [lines count]-1;
Mat *mat = new Mat(width, height, CV_8UC4);
MatIterator_<uint> it = mat->begin<uint>();
for (int i=0; i<[lines count]; i++){
for (int j=0; j<[[lines objectAtIndex:i] length]; j++){
int pixelValue = 0;
if ([[lines objectAtIndex:i] characterAtIndex:j] == '1'){
pixelValue = 255;
}
*it = pixelValue;
}
}
IplImage iplImage = *mat;
IplImage* rv = cvCreateImage(cvSize(iplImage.width, iplImage.height), IPL_DEPTH_8U, 3);
cvCvtColor(mat, rv, CV_RGBA2BGR);
return rv;
}
感谢您的输入,我的首要任务是从pbm转换到IplImage,一旦完成,我将继续清理并优化。现在的问题是,当我在ImageView中查看它时,我会看到垃圾模糊的抽象图像。 – Haoest 2011-03-22 23:30:03