3

カメラロール、アルバムなど、iOS デバイスのフォト ライブラリにあるすべての写真を調べようとしています。

そこから、コア イメージを使用して写真に顔が含まれているかどうかを確認し、含まれている場合は、detectedFaceArray という配列に追加します。

ALAssetsLibraryを使用してすべてのグループを列挙し、フォト ギャラリーの写真を列挙する必要があることは理解していますが、各写真にコア イメージを実装する方法がわかりません。私が使用しているコードは、この質問で尋ねられているコードです:

https://stackoverflow.com/questions/18658783/enumerategroupswithtypes-alassetsgroupall-retrieves-only-the-number-of-photos-i

また

-(void)getAllPictures
{
self.galleryImages=[[NSMutableArray alloc] init];
mutableArray =[[NSMutableArray alloc]init];
NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];  
library = [[ALAssetsLibrary alloc] init];

void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop)
{

if(result != nil)
{
    if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto])
    {
        [assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]];

        NSURL *url= (NSURL*) [[result defaultRepresentation]url];

        [library assetForURL:url
                 resultBlock:^(ALAsset *asset) {
                     [mutableArray addObject:asset];
                     if ([mutableArray count]==count)
                     {
                         self.galleryImages=[[NSMutableArray alloc] initWithArray:mutableArray];
                     }
                 }
                failureBlock:^(NSError *error){ NSLog(@"operation was not successfull!"); } ];
    }
}
};

NSMutableArray *assetGroups = [[NSMutableArray alloc] init];

void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {
    if(group != nil) {
        [group enumerateAssetsUsingBlock:assetEnumerator];
        [assetGroups addObject:group];
        count=[group numberOfAssets];
    }
};

assetGroups = [[NSMutableArray alloc] init];

[library enumerateGroupsWithTypes: ALAssetsGroupAll
                       usingBlock:assetGroupEnumerator
                     failureBlock:^(NSError *error) {NSLog(@"There is an error");}];
}

これが使用する正しいコードであるかどうかさえわからないので、助けていただければ幸いです。ALAssetsLibraryと Core Image Documentationを読みましたが、どうすればよいかわかりません。

助言がありますか?ありがとうございました!

4

2 に答える 2

0

質問に対する可能な答えをまだ探している人のために。このコードを使用してアセットを列挙し、顔のあるアセットを保存しています。

[self.library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
                [group setAssetsFilter:[ALAssetsFilter allPhotos]];
                [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
                    if(result && self.galleryAssets.count <= 20) {
                       CIImage *ciImage = [CIImage imageWithCGImage:result.thumbnail];
                        NSNumber *orientation = [NSNumber numberWithInt:[[UIImage imageWithCIImage:ciImage] imageOrientation]+1];
                        NSDictionary *fOptions = [NSDictionary dictionaryWithObject:orientation forKey: CIDetectorImageOrientation];
                        NSArray *features = [detector featuresInImage:ciImage options:fOptions];

                        if(features.count != 0) {
                            [self.galleryAssets addObject:result];
                        }
                        *stop = NO;
                    } else {
                        *stop = YES; return;
                    }
                }];

                dispatch_async(dispatch_get_main_queue(), ^{
                    if(self.galleryAssets.count == 0) {
                        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Photos" message:@"You have no photos in your gallery." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                        [alert show];
                    } 
                });
            } failureBlock:nil];
于 2014-10-30T17:02:13.897 に答える