我打算预加载我存储在应用程序中的所有图像。图像的预加载包括:
- 从包中读取图像。
- 使用 cvExtractSurf 从 opencv 框架中提取对象描述符。
- 将 IPLImage 与相应的对象描述符和关键点一起存储。
我在创建包含 CvSeq* 键和 CvSeq* decs 的字典时遇到问题。请建议如何将这些值存储在 NSMutableDictionary 中。
-(void) preloadImages:(NSMutableDictionary *)dictionary{
NSArray *d = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:nil];
CvSURFParams params = cvSURFParams(500, 1);
CvMemStorage* storage = cvCreateMemStorage(0);
for( int i=0;i<[d count];i++){
NSString *searchForMe = @"myapp.app/1";
NSString *s = [[NSString alloc] initWithString:[d objectAtIndex:i]];
NSRange range = [s rangeOfString:searchForMe];
if( range.location != NSNotFound ){
NSMutableDictionary *surfDict = [[NSMutableDictionary alloc] init];
NSString *substring = [s substringFromIndex:range.location];
substring = [substring stringByReplacingOccurrencesOfString:@"myapp.app/" withString:@""];
UIImage *testImage = [UIImage imageNamed:substring];
IplImage *iplTestImage = [OpenCVUtilities CreateGRAYIplImageFromUIImage:testImage];
CvSeq *keys = 0 ;
CvSeq *descs = 0;
cvExtractSURF( iplTestImage, 0, &keys, &descs, storage, params );
[surfDict setObject:(id)testImage forKey:@"uiImage"];
NSLog(@"Image name : %@", substring);
[dictionary setObject:surfDict forKey:[NSString stringWithFormat:@"%d",i]];
[dictionary setObject:(NSObject *)keys forKey:@"keys"]; // error here
[dictionary setObject:(NSObject *)descs forKey:@"descs"]; // error here
[surfDict release];
}
}
}