Text in capture video
kleruk opened this issue · comments
We need to record the text on video. For example, the date and time. I tried to do this using the method of the delegate
- (void)vision:(PBJVision *)vision didCaptureVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer
` CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress( pixelBuffer, 0 );
CIContext *ciContext = [CIContext contextWithEAGLContext:[PBJVision sharedInstance].context options:@{kCIContextWorkingColorSpace : [NSNull null]} ];
NSString *string = @"LOADING TEXT";
NSDictionary *attributes = @{NSFontAttributeName : [UIFont systemFontOfSize:20],
NSForegroundColorAttributeName : [UIColor whiteColor],
NSBackgroundColorAttributeName : [UIColor blackColor]};
UIImage *image = [UIImage imageFromString:string
attributes:attributes
size:CGSizeMake(320, 100)];
CIImage *filteredImage = [[CIImage alloc] initWithCGImage:image.CGImage];
[ciContext render:filteredImage toCVPixelBuffer:pixelBuffer bounds:[filteredImage extent] colorSpace:CGColorSpaceCreateDeviceRGB()];
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); `
but it does not work.
Would you like to add this opportunity?
Try modifying the buffer in the earlier delegate vision:didReceiveVideoSampleBuffer:
Your code will need to be super performant, so maybe cache that UIImage creation.
@imagine, thanks for your reply.
I would like to be able to do this with the help of a delegate, because it is not possible to modify it since it is used with Pods