Add object detection, tracking, mobile notifications, and search to any security camera.
start yolo settings
roryclear35ff1e10e10c
diff --git a/clearcam/SettingsManager.h b/clearcam/SettingsManager.hnew file mode 100644index 0000000..c74cd12--- /dev/null+++ b/clearcam/SettingsManager.h@@ -0,0 +1,11 @@+#import <Foundation/Foundation.h>++@interface SettingsManager : NSObject++@property (nonatomic, strong) NSArray<NSNumber *> *yolo_indexes;+++ (instancetype)sharedManager;+- (void)saveYoloIndexes;+- (void)loadYoloIndexes;++@enddiff --git a/clearcam/SettingsManager.m b/clearcam/SettingsManager.mnew file mode 100644index 0000000..14fa962--- /dev/null+++ b/clearcam/SettingsManager.m@@ -0,0 +1,46 @@+#import "SettingsManager.h"++@implementation SettingsManager+++ (instancetype)sharedManager {+ static SettingsManager *sharedManager = nil;+ static dispatch_once_t onceToken;+ dispatch_once(&onceToken, ^{+ sharedManager = [[self alloc] init];+ });+ return sharedManager;+}++- (instancetype)init {+ self = [super init];+ if (self) {+ [self loadYoloIndexes];+ }+ return self;+}++- (void)saveYoloIndexes {+ if (self.yolo_indexes) {+ [[NSUserDefaults standardUserDefaults] setObject:self.yolo_indexes forKey:@"yolo_indexes"];+ [[NSUserDefaults standardUserDefaults] synchronize];+ }+}++- (void)loadYoloIndexes {+ NSArray *savedIndexes = [[NSUserDefaults standardUserDefaults] arrayForKey:@"yolo_indexes"];+ if (savedIndexes) {+ self.yolo_indexes = savedIndexes;+ } else {+ self.yolo_indexes = [self generateDefaultYoloIndexes];+ }+}++- (NSArray<NSNumber *> *)generateDefaultYoloIndexes {+ NSMutableArray<NSNumber *> *defaultIndexes = [NSMutableArray array];+ for (int i = 0; i < 80; i++) { //todo unhardcode 80+ [defaultIndexes addObject:@(i)];+ }+ return [defaultIndexes copy];+}++@enddiff --git a/clearcam/Yolo.m b/clearcam/Yolo.mindex 9c0fae6..e0f81f1 100644--- a/clearcam/Yolo.m+++ b/clearcam/Yolo.m@@ -2,6 +2,7 @@#import <Metal/Metal.h>#import <UIKit/UIKit.h>#import <sys/utsname.h>+#import "SettingsManager.h"@implementation Yolo@@ -28,6 +29,7 @@ UInt8 *rgbData;self.mtl_buffers_in_flight = [[NSMutableArray alloc] init];self.yolo_res = 640;self.rgbData = (UInt8 *)malloc(self.yolo_res * self.yolo_res * 3);+self.yolo_classes = @[@[@"person", [UIColor redColor]],@[@"bicycle", [UIColor greenColor]],@[@"car", [UIColor blueColor]],@[@"motorcycle", [UIColor cyanColor]],@[@"airplane", [UIColor magentaColor]],@[@"bus", [UIColor yellowColor]],@@ -162,14 +164,17 @@ UInt8 *rgbData;}- (NSArray *)processOutput:(const float *)output {+ NSArray<NSNumber *> *yoloIndexes = [SettingsManager sharedManager].yolo_indexes;NSMutableArray *boxes = [NSMutableArray array];int numPredictions = pow(self.yolo_res / 32, 2) * 21;for (int index = 0; index < numPredictions; index++) {int classId = 0;float prob = 0.0;-- for (int col = 0; col < self.yolo_classes.count; col++) {++ for (int i = 0; i < yoloIndexes.count; i++) {+ NSNumber *indexNumber = yoloIndexes[i];+ int col = [indexNumber intValue];float confidence = output[numPredictions * (col + 4) + index];if (confidence > prob) {prob = confidence;