[翻译] DBCamera 轻量级定制摄像头

简介:

DBCamera 轻量级定制摄像头

https://github.com/danielebogo/DBCamera

 

DBCamera is a simple custom camera with AVFoundation.

DBCamera使用了AVFoundation框架并简单的定制了摄像头.

 

 

Getting Started

Installation

The recommended approach for installating DBCamera is via the CocoaPods package manager, as it provides flexible dependency management and dead simple installation. For best results, it is recommended that you install via CocoaPods >= 0.16.0 using Git>= 1.8.0 installed via Homebrew.

推荐你使用CocoaPods安装.

 

Integration

DBCamera has a simple integration:

DBCamera模块化很简单:

#import "DBCameraViewController.h"
#import "DBCameraContainer.h"
//Add DBCameraViewControllerDelegate protocol
@interface RootViewController () <DBCameraViewControllerDelegate>
//Present DBCameraViewController with different behaviours

- (void) openCamera
{
    DBCameraContainerViewController *cameraContainer = [[DBCameraContainerViewController alloc] initWithDelegate:self];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:cameraContainer];
    [nav setNavigationBarHidden:YES];
    [self presentViewController:nav animated:YES completion:nil];
}

- (void) openCameraWithoutSegue
{
    DBCameraContainerViewController *container = [[DBCameraContainerViewController alloc] initWithDelegate:self];
    DBCameraViewController *cameraController = [DBCameraViewController initWithDelegate:self];
    [cameraController setUseCameraSegue:NO];
    [container setCameraViewController:cameraController];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:container];
    [nav setNavigationBarHidden:YES];
    [self presentViewController:nav animated:YES completion:nil];
}

- (void) openCameraWithoutContainer
{
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[DBCameraViewController initWithDelegate:self]];
    [nav setNavigationBarHidden:YES];
    [self presentViewController:nav animated:YES completion:nil];
}
//Use your captured image
#pragma mark - DBCameraViewControllerDelegate

- (void) captureImageDidFinish:(UIImage *)image withMetadata:(NSDictionary *)metadata
{
    [_imageView setImage:image];
    [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}

By default, DBCameraViewController has another controller to display the image preview. When you create DBCameraViewController instance, you can set useCameraSegue: NO, to avoid it.

默认情况下,DBCameraViewController有一个其他的controller来展示图片列表,当你创建这个DBCameraViewController实例时,你可以手动设置关闭它.

- (void) openCameraWithoutSegue
{
    DBCameraContainerViewController *container = [[DBCameraContainerViewController alloc] initWithDelegate:self];
    DBCameraViewController *cameraController = [DBCameraViewController initWithDelegate:self];
    [cameraController setUseCameraSegue:NO];
    [container setCameraViewController:cameraController];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:container];
    [nav setNavigationBarHidden:YES];
    [self presentViewController:nav animated:YES completion:nil];
}

 

Customizing the camera

Basic

For simple customizations, you can customize the built-in camera view by sending a cameraSettingsBlock to the view controller.

对于简单的定制,你可以给这个controller传递一个cameraSettingsBlock来实现内置照相机view的定制.

#import "DBCameraView.h"
- (void)openCameraWithSettings:(CDVInvokedUrlCommand*)command
{
    DBCameraContainerViewController *cameraContainer = [[DBCameraContainerViewController alloc]
        initWithDelegate:self
        cameraSettingsBlock:^(DBCameraView *cameraView) {
            [cameraView.gridButton setHidden:YES];
        }];

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:cameraContainer];
    [nav setNavigationBarHidden:YES];
    [self presentViewController:nav animated:YES completion:nil];
}

Advanced

You can also create a custom interface, using a subclass of DBCameraView

当然,你也可以自己创建一个界面,通过继承DBCameraView子类的方式来实现.

#import "DBCameraView.h"

@interface CustomCamera : DBCameraView
- (void) buildInterface;
@end
#import "CustomCamera.h"

@interface CustomCamera ()
@property (nonatomic, strong) UIButton *closeButton;
@property (nonatomic, strong) CALayer *focusBox, *exposeBox;
@end

@implementation CustomCamera

- (void) buildInterface
{
    [self addSubview:self.closeButton];

    [self.previewLayer addSublayer:self.focusBox];
    [self.previewLayer addSublayer:self.exposeBox];

    [self createGesture];
}

- (UIButton *) closeButton
{
    if ( !_closeButton ) {
        _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeButton setBackgroundColor:[UIColor redColor]];
        [_closeButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
        [_closeButton setFrame:(CGRect){ CGRectGetMidX(self.bounds) - 15, 17.5f, 30, 30 }];
        [_closeButton addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
    }

    return _closeButton;
}

- (void) close
{
    if ( [self.delegate respondsToSelector:@selector(closeCamera)] )
        [self.delegate closeCamera];
}

#pragma mark - Focus / Expose Box

- (CALayer *) focusBox
{
    if ( !_focusBox ) {
        _focusBox = [[CALayer alloc] init];
        [_focusBox setCornerRadius:45.0f];
        [_focusBox setBounds:CGRectMake(0.0f, 0.0f, 90, 90)];
        [_focusBox setBorderWidth:5.f];
        [_focusBox setBorderColor:[[UIColor whiteColor] CGColor]];
        [_focusBox setOpacity:0];
    }

    return _focusBox;
}

- (CALayer *) exposeBox
{
    if ( !_exposeBox ) {
        _exposeBox = [[CALayer alloc] init];
        [_exposeBox setCornerRadius:55.0f];
        [_exposeBox setBounds:CGRectMake(0.0f, 0.0f, 110, 110)];
        [_exposeBox setBorderWidth:5.f];
        [_exposeBox setBorderColor:[[UIColor redColor] CGColor]];
        [_exposeBox setOpacity:0];
    }

    return _exposeBox;
}

- (void) drawFocusBoxAtPointOfInterest:(CGPoint)point andRemove:(BOOL)remove
{
    [super draw:_focusBox atPointOfInterest:point andRemove:remove];
}

- (void) drawExposeBoxAtPointOfInterest:(CGPoint)point andRemove:(BOOL)remove
{
    [super draw:_exposeBox atPointOfInterest:point andRemove:remove];
}

@end
//Present DBCameraViewController with a custom view.
@interface RootViewController () <DBCameraViewControllerDelegate>

- (void) openCustomCamera
{
    CustomCamera *camera = [CustomCamera initWithFrame:[[UIScreen mainScreen] bounds]];
    [camera buildInterface];

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[DBCameraViewController alloc] initWithDelegate:self cameraView:camera]];
    [nav setNavigationBarHidden:YES];
    [self presentViewController:nav animated:YES completion:nil];
}

目录
相关文章
|
4天前
|
人工智能 搜索推荐 API
Cobalt:开源的流媒体下载工具,支持解析和下载全平台的视频、音频和图片,支持多种视频质量和格式,自动提取视频字幕
cobalt 是一款开源的流媒体下载工具,支持全平台视频、音频和图片下载,提供纯净、简洁无广告的体验
98 9
Cobalt:开源的流媒体下载工具,支持解析和下载全平台的视频、音频和图片,支持多种视频质量和格式,自动提取视频字幕
|
25天前
|
机器学习/深度学习 人工智能 开发工具
Clone-voice:开源的声音克隆工具,支持文本转语音或改变声音风格,支持16种语言
Clone-voice是一款开源的声音克隆工具,支持16种语言,能够将文本转换为语音或将一种声音风格转换为另一种。该工具基于深度学习技术,界面友好,操作简单,适用于多种应用场景,如视频制作、语言学习和广告配音等。
121 9
Clone-voice:开源的声音克隆工具,支持文本转语音或改变声音风格,支持16种语言
|
22天前
|
人工智能 物联网 PyTorch
ChatTTSPlus:开源文本转语音工具,支持语音克隆,是 ChatTTS 的扩展版本
ChatTTSPlus 是一个开源的文本转语音工具,是 ChatTTS 的扩展版本,支持语音克隆、TensorRT 加速和移动模型部署等功能,极大地提升了语音合成的性能和灵活性。
76 5
ChatTTSPlus:开源文本转语音工具,支持语音克隆,是 ChatTTS 的扩展版本
|
4天前
|
机器学习/深度学习 API 语音技术
鸿蒙开发:文本合成语音
在鸿蒙当中,如何实现根据指定的文本进行合成语音合成播放呢,其实也是非常的简单,因为鸿蒙当中也有textToSpeech。
|
4月前
|
Ubuntu 机器人 语音技术
语音识别与语音控制的原理介绍
硬件平台 机器硬件:OriginBot(导航版/视觉版)PC主机:Windows(>=10)/Ubuntu(>=20.04)扩展硬件:X3语音版 运行案例 首先进入OriginBot主控系统,运行一下指令。请注意,部分操作OriginBot内暂未放入,请根据内容进行适当处理。 cd /userdata/dev_ws/ # 配置TogetheROS环境 source /opt/tros/setup.bash # 从tros.b的安装路径中拷贝出运行示例需要的配置文件。 cp -r /opt/tros/lib/hobot_audio/config/ . # 加载音频驱动,设备启动之后只
265 83
|
5月前
|
开发工具 数据安全/隐私保护 开发者
Windows平台RTMP推送|轻量级RTSP服务摄像头如何添加动态文字水印
本文介绍了在Windows平台上实现摄像头或屏幕流中动态文字水印的技术方法。通过大牛直播SDK示例,展示了如何从文本获取RGB数据,并将其叠加到视频流上。文中提供了代码片段来说明如何开启文字水印、生成包含实时信息的位图、以及如何更新和控制图层。最终实现了动态显示时间和位置信息的需求。对这一领域的开发者而言,本文提供了实用的参考与指导。
|
6月前
|
机器学习/深度学习 人工智能 语音技术
语音识别01-----语音合成,分离,变声实战模块介绍
语音识别01-----语音合成,分离,变声实战模块介绍
|
8月前
|
JSON 自然语言处理 Java
Android App开发语音处理之系统自带的语音引擎、文字转语音、语音识别的讲解及实战(超详细 附源码)
Android App开发语音处理之系统自带的语音引擎、文字转语音、语音识别的讲解及实战(超详细 附源码)
391 0
|
8月前
|
人工智能 搜索推荐 语音技术
有道开源的国产语音库EmotiVoice爆火了!具有情绪控制功能的语音合成引擎!
有道开源的国产语音库EmotiVoice爆火了!具有情绪控制功能的语音合成引擎!
1619 0
|
8月前
|
机器学习/深度学习 算法 数据库
DeepFace【部署 01】轻量级人脸识别和面部属性分析框架deepface安装使用详解(网盘分享模型文件)
DeepFace【部署 01】轻量级人脸识别和面部属性分析框架deepface安装使用详解(网盘分享模型文件)
1471 0

热门文章

最新文章