Add object detection, tracking, mobile notifications, and search to any security camera.
remove unused stuff
roryclear7c44c00023f8
diff --git a/clearcam/Yolo.h b/clearcam/Yolo.hindex 3c9b234..561a6f1 100644--- a/clearcam/Yolo.h+++ b/clearcam/Yolo.h@@ -24,12 +24,7 @@ NS_ASSUME_NONNULL_BEGIN// Initializer- (instancetype)init;--- (CGFloat)intersectionBetweenBox:(NSArray *)box1 andBox:(NSArray *)box2;-- (CGFloat)unionBetweenBox:(NSArray *)box1 andBox:(NSArray *)box2;-- (CGFloat)iouBetweenBox:(NSArray *)box1 andBox:(NSArray *)box2;- (NSMutableDictionary<NSString *, id> *)extractValues:(NSString *)x;-- (NSArray *)processOutput:(const float *)output;@enddiff --git a/clearcam/Yolo.m b/clearcam/Yolo.mindex 6307273..529ec07 100644--- a/clearcam/Yolo.m+++ b/clearcam/Yolo.m@@ -151,84 +151,6 @@ UInt8 *rgbData;return self;}-- (NSArray *)processOutput:(const float *)output {- NSArray<NSNumber *> *yoloIndexes = [[NSUserDefaults standardUserDefaults] objectForKey:@"yolo_presets"][[[NSUserDefaults standardUserDefaults] objectForKey:@"yolo_preset_idx"]];- NSMutableArray *boxes = [NSMutableArray array];- //int numPredictions = pow(self.yolo_res / 32, 2) * 21;- int numPredictions = 8400; //todo, tied to res and stride-- for (int index = 0; index < numPredictions; index++) {- int classId = 0;- float prob = 0.0;-- for (int i = 0; i < yoloIndexes.count; i++) {- float confidence = output[numPredictions * ([yoloIndexes[i] intValue] + 4) + index];- if (confidence > prob) {- prob = confidence;- classId = [yoloIndexes[i] intValue];- }- }-- //if (prob < 0.25) continue;- if (prob < ([[NSUserDefaults standardUserDefaults] objectForKey:@"threshold"] ? [[NSUserDefaults standardUserDefaults] integerForKey:@"threshold"] / 100.0 : 0.25)) continue;-- float xc = output[index];- float yc = output[numPredictions + index];- float w = output[2 * numPredictions + index];- float h = output[3 * numPredictions + index];-- float x1 = (xc - w / 2);- float y1 = (yc - h / 2);- float x2 = (xc + w / 2);- float y2 = (yc + h / 2);-- [boxes addObject:@[@(x1), @(y1), @(x2), @(y2), @(classId), @(prob)]];- }-- [boxes sortUsingComparator:^NSComparisonResult(NSArray *box1, NSArray *box2) {- NSNumber *prob1 = box1[5];- NSNumber *prob2 = box2[5];- return [prob2 compare:prob1];- }];-- NSMutableArray *result = [NSMutableArray array];- while ([boxes count] > 0) {- NSArray *bestBox = boxes[0];- [result addObject:bestBox];- [boxes removeObjectAtIndex:0];-- NSMutableArray *filteredBoxes = [NSMutableArray array];- for (NSArray *box in boxes) {- if ([self iouBetweenBox:bestBox andBox:box] < 0.7) {- [filteredBoxes addObject:box];- }- }- boxes = filteredBoxes;- }- return result;-}--// Calculate intersection between two boxes-- (CGFloat)intersectionBetweenBox:(NSArray *)box1 andBox:(NSArray *)box2 {- CGFloat x1 = MAX([box1[0] floatValue], [box2[0] floatValue]);- CGFloat y1 = MAX([box1[1] floatValue], [box2[1] floatValue]);- CGFloat x2 = MIN([box1[2] floatValue], [box2[2] floatValue]);- CGFloat y2 = MIN([box1[3] floatValue], [box2[3] floatValue]);- return MAX(0, x2 - x1) * MAX(0, y2 - y1);-}--// Calculate union between two boxes-- (CGFloat)unionBetweenBox:(NSArray *)box1 andBox:(NSArray *)box2 {- CGFloat box1Area = ([box1[2] floatValue] - [box1[0] floatValue]) * ([box1[3] floatValue] - [box1[1] floatValue]);- CGFloat box2Area = ([box2[2] floatValue] - [box2[0] floatValue]) * ([box2[3] floatValue] - [box2[1] floatValue]);- return box1Area + box2Area - [self intersectionBetweenBox:box1 andBox:box2];-}--// Calculate Intersection over Union (IoU) between two boxes-- (CGFloat)iouBetweenBox:(NSArray *)box1 andBox:(NSArray *)box2 {- return [self intersectionBetweenBox:box1 andBox:box2] / [self unionBetweenBox:box1 andBox:box2];-}-// Extract values from a string- (NSMutableDictionary<NSString *, id> *)extractValues:(NSString *)x {NSMutableDictionary<NSString *, id> *values = [@{@"op": [x componentsSeparatedByString:@"("][0]} mutableCopy];