Add object detection, tracking, mobile notifications, and search to any security camera.
takes a very low res image
roryclear8102eabe42d0
diff --git a/clearcam/FileServer.m b/clearcam/FileServer.mindex a705355..6699685 100644--- a/clearcam/FileServer.m+++ b/clearcam/FileServer.m@@ -862,12 +862,10 @@currentTime = CMTimeAdd(currentTime, asset.duration);}- // 🔹 Output file setupNSString *outputPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObjectstringByAppendingPathComponent:@"merged_video.mp4"];NSURL *outputURL = [NSURL fileURLWithPath:outputPath];- // Remove existing file if it exists- [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];+ [[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];//todo remove after user has downloaded too?AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetHighestQuality];exportSession.outputURL = outputURL;diff --git a/clearcam/SceneState.h b/clearcam/SceneState.hindex 898b38d..3cadd45 100644--- a/clearcam/SceneState.h+++ b/clearcam/SceneState.h@@ -1,5 +1,6 @@#import <Foundation/Foundation.h>#import <CoreData/CoreData.h>+#import <AVFoundation/AVFoundation.h>@interface SceneState : NSObject@@ -8,7 +9,7 @@@property (nonatomic, strong) NSArray<NSNumber *> *events;@property (nonatomic, strong) NSDictionary *alerts;@property (strong, nonatomic) NSManagedObjectContext *backgroundContext;-- (void)processOutput:(NSArray *)array;+- (void)processOutput:(NSArray *)array withImage:(CGImageRef)image;- (void)writeToFileWithString:(NSString *)customString;@enddiff --git a/clearcam/SceneState.m b/clearcam/SceneState.mindex 10a5d1d..5213dbd 100644--- a/clearcam/SceneState.m+++ b/clearcam/SceneState.m@@ -19,7 +19,7 @@return self;}-- (void)processOutput:(NSArray *)array {+- (void)processOutput:(NSArray *)array withImage:(CGImageRef)image {NSMutableDictionary *frame = [[NSMutableDictionary alloc] init];// Count occurrences in the current frame@@ -48,7 +48,36 @@if (current_state != last_state) {NSDate *date = [NSDate date];NSTimeInterval unixTimestamp = [date timeIntervalSince1970];++ // Convert CGImageRef to UIImage+ UIImage *uiImage = [UIImage imageWithCGImage:image];++ // Get the app's Documents directory+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);+ NSString *documentsDirectory = [paths firstObject];+ NSString *imagesDirectory = [documentsDirectory stringByAppendingPathComponent:@"images"];++ // Create the images directory if it doesn't exist+ if (![[NSFileManager defaultManager] fileExistsAtPath:imagesDirectory]) {+ [[NSFileManager defaultManager] createDirectoryAtPath:imagesDirectory+ withIntermediateDirectories:YES+ attributes:nil+ error:nil];+ }++ // File path for the image+ NSString *filePath = [imagesDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%f.png", unixTimestamp]];++ // Convert UIImage to PNG data+ NSData *imageData = UIImagePNGRepresentation(uiImage);+ // Write the image data to file+ if (![imageData writeToFile:filePath atomically:YES]) {+ NSLog(@"Failed to save image at path: %@", filePath);+ } else {+ NSLog(@"Image saved at path: %@", filePath);+ }+[self.backgroundContext performBlockAndWait:^{NSManagedObject *newEvent = [NSEntityDescription insertNewObjectForEntityForName:@"EventEntity"inManagedObjectContext:self.backgroundContext];diff --git a/clearcam/ViewController.m b/clearcam/ViewController.mindex 4c9529d..a8c07e7 100644--- a/clearcam/ViewController.m+++ b/clearcam/ViewController.m@@ -747,7 +747,7 @@ NSMutableDictionary *classColorMap;CIImage *croppedImage = [resizedImage imageByCroppingToRect:cropRect];CGImageRef cgImage = [self.ciContext createCGImage:croppedImage fromRect:cropRect];-+NSArray *output = [self.yolo yolo_infer:cgImage withOrientation:videoOrientation];CGImageRelease(cgImage);diff --git a/clearcam/Yolo.m b/clearcam/Yolo.mindex 577f91b..ed42eba 100644--- a/clearcam/Yolo.m+++ b/clearcam/Yolo.m@@ -361,14 +361,14 @@ UInt8 *rgbData;memcpy(floatArray, bufferPointer, buffer.length);NSArray *output = [self processOutput:floatArray];-+ free(floatArray);+NSMutableString *classNamesString = [NSMutableString string];for (int i = 0; i < output.count; i++) {[classNamesString appendString:self.yolo_classes[[output[i][4] intValue]][0]];if (i < output.count - 1) [classNamesString appendString:@", "];}- //NSLog(@"Class Names: %@", classNamesString);- [self.scene processOutput:output];+ [self.scene processOutput:output withImage:cgImage];if(output.count > 0){NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];@@ -380,9 +380,6 @@ UInt8 *rgbData;[fileHandle writeData:[[logEntry stringByAppendingString:@"\n"] dataUsingEncoding:NSUTF8StringEncoding]];[fileHandle closeFile];}-- free(floatArray);-return output;}