视频,扫描,识别相关
2014-09-05 16:48
148 查看
头文件
包含AVFoundation.framework
1、初始化Capture // Grab the back-facing camera
AVCaptureDevice *backFacingCamera = nil;
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices)
{
if ([device position] == AVCaptureDevicePositionBack)
{
backFacingCamera = device;
break;
}
}
// Create the capture session
_captureSession = [[AVCaptureSession alloc] init];
// Add the video input
NSError *error = nil;
_videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:backFacingCamera error:&error];
if ([_captureSession canAddInput:_videoInput])
{
[_captureSession addInput:_videoInput];
}
// Add the video frame output
_videoOutput = [[AVCaptureVideoDataOutput alloc] init];
[_videoOutput setAlwaysDiscardsLateVideoFrames:YES];
// Use RGB frames instead of YUV to ease color processing
NSDictionary *settings = @{(id)kCVPixelBufferPixelFormatTypeKey: [NSNumber numberWithInt:kCVPixelFormatType_32BGRA]};
[_videoOutput setVideoSettings:settings];
// dispatch_queue_t videoQueue = dispatch_queue_create("com.sunsetlakesoftware.colortracking.videoqueue", NULL);
// [videoOutput setSampleBufferDelegate:self queue:videoQueue];
[_videoOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
if ([_captureSession canAddOutput:_videoOutput])
{
[_captureSession addOutput:_videoOutput];
}
else
{
NSLog(@"Couldn't add video output");
}
[_captureSession setSessionPreset:AVCaptureSessionPresetMedium];
2、启动 录制
[_captureSession startRunning];
3、检测识别
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
unsigned char *data = (unsigned char *)CVPixelBufferGetBaseAddress(pixelBuffer);
// int bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer);
int bufferHeight = (int)CVPixelBufferGetHeight(pixelBuffer);
int bufferWidth = (int)CVPixelBufferGetWidth(pixelBuffer);
int countPerRow = bufferWidth * 4;
//do something
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
}
3、停止 录制
[_captureSession stopRunning];
4、注意事项
> 处理时,尽量避免算法过于复杂,导致卡顿
> 注意数据的 R、G、B、A分量与设定一致
包含AVFoundation.framework
1、初始化Capture // Grab the back-facing camera
AVCaptureDevice *backFacingCamera = nil;
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices)
{
if ([device position] == AVCaptureDevicePositionBack)
{
backFacingCamera = device;
break;
}
}
// Create the capture session
_captureSession = [[AVCaptureSession alloc] init];
// Add the video input
NSError *error = nil;
_videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:backFacingCamera error:&error];
if ([_captureSession canAddInput:_videoInput])
{
[_captureSession addInput:_videoInput];
}
// Add the video frame output
_videoOutput = [[AVCaptureVideoDataOutput alloc] init];
[_videoOutput setAlwaysDiscardsLateVideoFrames:YES];
// Use RGB frames instead of YUV to ease color processing
NSDictionary *settings = @{(id)kCVPixelBufferPixelFormatTypeKey: [NSNumber numberWithInt:kCVPixelFormatType_32BGRA]};
[_videoOutput setVideoSettings:settings];
// dispatch_queue_t videoQueue = dispatch_queue_create("com.sunsetlakesoftware.colortracking.videoqueue", NULL);
// [videoOutput setSampleBufferDelegate:self queue:videoQueue];
[_videoOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
if ([_captureSession canAddOutput:_videoOutput])
{
[_captureSession addOutput:_videoOutput];
}
else
{
NSLog(@"Couldn't add video output");
}
[_captureSession setSessionPreset:AVCaptureSessionPresetMedium];
2、启动 录制
[_captureSession startRunning];
3、检测识别
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
unsigned char *data = (unsigned char *)CVPixelBufferGetBaseAddress(pixelBuffer);
// int bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer);
int bufferHeight = (int)CVPixelBufferGetHeight(pixelBuffer);
int bufferWidth = (int)CVPixelBufferGetWidth(pixelBuffer);
int countPerRow = bufferWidth * 4;
//do something
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
}
3、停止 录制
[_captureSession stopRunning];
4、注意事项
> 处理时,尽量避免算法过于复杂,导致卡顿
> 注意数据的 R、G、B、A分量与设定一致
相关文章推荐
- 韩文、日语相关 文档扫描识别 的福音
- 视频相关名词大全
- 票据扫描识别现状分析
- Android手机识别相关
- tesseract-ocr 识别中文扫描图片
- 看了奇点大学的总决赛相关的视频,一些感悟
- 关于LEADTOOLS解决企业表单识别的相关策略
- APP拍照扫描识别银行卡SDK
- SugarCRM相关视频
- 有关视频会议系统用到的相关协议-2
- Dynamic Web TWAIN扫描识别工具改变缓冲区图像大小
- 项目视频讲解_银行、证券行业云计算身份识别服务器深度开发(令牌加密算法、认证协议、驱动、云布署)
- android视频合成相关整理
- 小视频-消息推送原理及相关问题解决
- 图像识别-基于BIM的实验室视频监控系统 20140528
- 如何扫描出android系统媒体库中视频文件
- EditPlus最新汉化绿色版的下载、破解,以及开发java文件时的一些相关设置操作视频
- LEADTOOLS表单识别应用:自动归档扫描文件
- LEADTOOLS表单识别应用:自动归档扫描文件
- 纯干货-8 21套深度学习相关的视频教程分享