2014 snapchat source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.2 KiB

  1. //
  2. // SCCaptureMetadataObjectParser.m
  3. // Snapchat
  4. //
  5. // Created by Jiyang Zhu on 3/13/18.
  6. // Copyright © 2018 Snapchat, Inc. All rights reserved.
  7. //
  8. #import "SCCaptureMetadataObjectParser.h"
  9. #import <SCBase/SCMacros.h>
  10. @import UIKit;
  11. @implementation SCCaptureMetadataObjectParser
  12. - (NSDictionary<NSNumber *, NSValue *> *)parseFaceBoundsByFaceIDFromMetadataObjects:
  13. (NSArray<__kindof AVMetadataObject *> *)metadataObjects
  14. {
  15. NSMutableArray *faceObjects = [NSMutableArray array];
  16. [metadataObjects
  17. enumerateObjectsUsingBlock:^(__kindof AVMetadataObject *_Nonnull obj, NSUInteger idx, BOOL *_Nonnull stop) {
  18. if ([obj isKindOfClass:[AVMetadataFaceObject class]]) {
  19. [faceObjects addObject:obj];
  20. }
  21. }];
  22. SC_GUARD_ELSE_RETURN_VALUE(faceObjects.count > 0, nil);
  23. NSMutableDictionary<NSNumber *, NSValue *> *faceBoundsByFaceID =
  24. [NSMutableDictionary dictionaryWithCapacity:faceObjects.count];
  25. for (AVMetadataFaceObject *faceObject in faceObjects) {
  26. [faceBoundsByFaceID setObject:[NSValue valueWithCGRect:faceObject.bounds] forKey:@(faceObject.faceID)];
  27. }
  28. return faceBoundsByFaceID;
  29. }
  30. @end