项目作者: remirobert

项目描述 :
:monkey::camera: Camera engine for iOS, written in Swift, above AVFoundation. :monkey:
高级语言: Swift
项目地址: git://github.com/remirobert/CameraEngine.git
创建时间: 2015-09-11T09:43:46Z
项目社区:https://github.com/remirobert/CameraEngine

开源协议:MIT License

下载


cameraenginelogo

🌟 The most advanced Camera framework in Swift 🌟

License MIT
Carthage compatible
CocoaPods
Build Status
CocoaPods
Support
codebeat badge
Donate

CameraEngine is an iOS camera engine library that allows easy integration of special capture features and camera customization in your iOS app.



:fire: Features

CameraEngine
:relaxed: Support iOS8 - iOS9
:triangular_ruler: Support orientation device
:checkered_flag: Fast capture
:camera: Photo capture
:movie_camera: Video capture
:chart_with_upwards_trend: quality settings presset video / photo capture
:raising_hand: switch device (front, back)
:bulb: flash mode management
:flashlight: torch mode management
:mag_right: focus mode management
:bowtie: detection face, barecode, and qrcode
:rocket: GIF encoder

🔨 Installation

CocoaPods

  • Add pod "CameraEngine" to your Podfile.
  • Run pod install or pod update.
  • import CameraEngine

Carthage

  • Add github "remirobert/CameraEngine" to your Cartfile.
  • Run carthage update and add the framework to your project.
  • import CameraEngine

Manually

  • Download all the files in the CameraEngine subdirectory.
  • Add the source files to your Xcode project.
  • import CameraEngine

To add the Framework, you can also create a workspace for your project, then add the CameraEngine.xcodeproj, and the CameraEngine, then you should be able to compile the framework, and import it in your app project.

CameraEngine supports swift3, see the development branch for a swift 3 integration.

:rocket: Quick start

First let’s init and start the camera session. You can call that in viewDidLoad, or in appDelegate.

  1. override func viewDidLoad() {
  2. super.viewDidLoad()
  3. self.cameraEngine.startSession()
  4. }

Next time to display the preview layer

  1. override func viewDidLayoutSubviews() {
  2. let layer = self.cameraEngine.previewLayer
  3. layer.frame = self.view.bounds
  4. self.view.layer.insertSublayer(layer, atIndex: 0)
  5. self.view.layer.masksToBounds = true
  6. }

Capture a photo

  1. self.cameraEngine.capturePhoto { (image: UIImage?, error: NSError?) -> (Void) in
  2. //get the picture tooked in the 👉 image
  3. }

Capture a video

  1. private func startRecording() {
  2. guard let url = CameraEngineFileManager.documentPath("video.mp4") else {
  3. return
  4. }
  5. self.cameraEngine.startRecordingVideo(url, blockCompletion: { (url, error) -> (Void) in
  6. })
  7. }
  8. private func stopRecording() {
  9. self.cameraEngine.stopRecordingVideo()
  10. }

Generate animated image GIF

  1. guard let url = CameraEngineFileManager.documentPath("animated.gif") else {
  2. return
  3. }
  4. self.cameraEngine.createGif(url, frames: self.frames, delayTime: 0.1, completionGif: { (success, url) -> (Void) in
  5. //Do some crazy stuff here
  6. })

:wrench: configurations

CameraEngine, allows you to set some parameters, such as management of flash, torch and focus. But also on the quality of the media, which also has an impact on the size of the output file.

Flash

  1. self.cameraEngine.flashMode = .On
  2. self.cameraEngine.flashMode = .Off
  3. self.cameraEngine.flashMode = .Auto

Torch

  1. self.cameraEngine.torchMode = .On
  2. self.cameraEngine.torchMode = .Off
  3. self.cameraEngine.torchMode = .Auto

Focus

  1. | CameraEngine focus

—————————————|——————————————————————————————
.Locked | means the lens is at a fixed position
.AutoFocus | means setting this will cause the camera to focus once automatically, and then return back to Locked
.ContinuousAutoFocus | means the camera will automatically refocus on the center of the frame when the scene changes

  1. self.cameraEngine.cameraFocus = .Locked
  2. self.cameraEngine.cameraFocus = .AutoFocus
  3. self.cameraEngine.cameraFocus = .ContinuousAutoFocus

Camera presset Photo

  1. self.cameraEngine.sessionPresset = .Low
  2. self.cameraEngine.sessionPresset = .Medium
  3. self.cameraEngine.sessionPresset = .High
  4. ...

Camera presset Video

  1. self.cameraEngine.videoEncoderPresset = .Preset640x480
  2. self.cameraEngine.videoEncoderPresset = .Preset960x540
  3. self.cameraEngine.videoEncoderPresset = .Preset1280x720
  4. self.cameraEngine.videoEncoderPresset = .Preset1920x1080
  5. self.cameraEngine.videoEncoderPresset = .Preset3840x2160

:eyes: Object detection

CameraEngine can detect faces, QRcodes, or barcode. It will return all metadata on each frame, when it detects something. To exploit you whenever you want later.

Set the detection mode

  1. self.cameraEngine.metadataDetection = .Face
  2. self.cameraEngine.metadataDetection = .QRCode
  3. self.cameraEngine.metadataDetection = .BareCode
  4. self.cameraEngine.metadataDetection = .None //disable the detection

exploiting face detection

  1. self.cameraEngine.blockCompletionFaceDetection = { faceObject in
  2. let frameFace = (faceObject as AVMetadataObject).bounds
  3. self.displayLayerDetection(frame: frameFace)
  4. }

exploiting code detection (barecode and QRCode)

  1. self.cameraEngine.blockCompletionCodeDetection = { codeObject in
  2. let valueCode = codeObject.stringValue
  3. let frameCode = (codeObject as AVMetadataObject).bounds
  4. self.displayLayerDetection(frame: frameCode)
  5. }

:car::dash: Example

You will find a sample project, which implements all the features of CameraEngine, with an interface that allows you to test and play with the settings.
To run the example projet, run pod install, because it uses the current prod version of CameraEngine.

Contributors 🍻

License

This project is licensed under the terms of the MIT license. See the LICENSE file.

This project is in no way affiliated with Apple Inc. This project is open source under the MIT license, which means you have full access to the source code and can modify it to fit your own needs.

If you want to support the development of this library, feel free to
Donate. Thanks to all contributors so far!

bannabot