I have connected a remote camera using Sony CameraRemoteAPI SDK. Camera is connected successfully and I am getting the frames. The following code gets the incoming UIImage and assign to a UIImageView
- (void) liveviewPaint:(UIImage*)image
{
@synchronized(self)
{
[self.liveviewImageView setImage:image];
image = NULL;
}
}
Then I needed to add face recognition to this UIImage. But when I try to do it the application runs out of memory and crashes. How can I effectively do face recognition with this remote camera feed? This is my current code
- (void) liveviewPaint:(UIImage*)image
{
@synchronized(self)
{
[self performSelectorInBackground:@selector(getFaceDetectedImage:) withObject:image];
if ([[RecognitionAPI getSharedInstance] detectedImage]) {
[self.liveviewImageView setImage:[[RecognitionAPI getSharedInstance] detectedImage]];
} else {
[self.liveviewImageView setImage:image];
}
image = NULL;
}
}
Here using a separate thread I am calling the face recognition function (getFaceDetectedImage). Once the face is recognized it is set as a instance variable in RecognitionAPI class(detectedImage). If the face is detected I set it to the image of the UIImageView(liveviewImageView) as follows
[self.liveviewImageView setImage:[[RecognitionAPI getSharedInstance] detectedImage]];
This is the output of the allocation tool without the face detection. App is not crashing this time.
This is the output of the allocation tool with the face detection. App is crashing this time.
I am using apple inbuilt CIDetector for face recognition. I tried with opencv, but at that time also the app is crashing.
This is error I am getting in the console
Recognition(483,0x6a51000) malloc: *** mach_vm_map(size=2691072) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Recognition(483,0x6a51000) malloc: *** mach_vm_map(size=675840) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Recognition(483,0x6a51000) malloc: *** mach_vm_map(size=2691072) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Recognition(483,0x6a51000) malloc: *** mach_vm_map(size=675840) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Recognition(483,0x6a51000) malloc: *** mach_vm_map(size=2691072) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Recognition(483,0x6a51000) malloc: ***
Also I am getting total 59 threads that fail to finish. This is a screenshot of it.
I want to know how to evade this crash and how to do the image processing efficiently. I think I will need a good design for this. Can anyone help?