Library for iOS Camera API. CameraKit helps you add reliable camera to your app quickly.

Related tags

Camera camerakit-ios
Overview

CameraKit Header

Join Spectrum Buddy.Works

CameraKit helps you add reliable camera to your app quickly. Our open source camera platform provides consistent capture results, service that scales, and endless camera possibilities.

With CameraKit you are able to effortlessly do the following:

  • Ability to extend and create custom sessions.
  • Image and video capture seamlessly working with the same preview session.
  • Automatic system permission handling.
  • Automatic preview scaling.
  • Automatic preview/image/video output orientation handling.
  • 📷 Ability to set a custom resolution for capturing photos.
  • 📹 Ability to set resolution/frame rate for capturing videos.
  • 👱‍ Built-in face detection.
  • 📐 Built-in overlay grid.
  • 👆 Built-in tap to focus.
  • 🔍 Built-in pinch to zoom.
  • 📸 Built-in flash toggle for both photos and videos.
  • 🤳 Built-in camera position toggle.
  • 🖥 Objective-C compatible.

Sponsored By

Expensify Buddy.Works

Installation

Demo

If you want to test out the demo app first you can clone this repo to your local disk:

git clone https://github.com/CameraKit/camerakit-ios.git

and then navigate to camerakit-ios and open the CameraKit.xcworkspace file with Xcode. Near the run button select the CameraKitDemo scheme, resolve the signing conflicts using your Apple account and then run it on a real device. You cannot do much on a simulator, since we need an actual camera hardware.

Cocoapods

If you don't have Cocoapods already installed you can install it by running the code below in a terminal:

sudo gem install cocoapods

If you don't have any Podfile run:

pod init

Then open the Podfile file in your project and add this line to your app target:

pod CameraKit-iOS

and it will automatically create a Podfile and integrate the pods into the project by creating a separate .xcworkspace file. You will open this file in Xcode from now on.

Carthage

If you don't have Carthage installed run:

brew install carthage

Then create a Cartfile and add the following line:

github "CameraKit/camerakit-ios"

Code

Before adding our camera related code, make sure you include the permissions needed for your code to work in the app project Info.plist file:


NSCameraUsageDescription



NSMicrophoneUsageDescription



NSPhotoLibraryAddUsageDescription

Below is a quick start code sample with session + live camera preview:

import CameraKit

...

override func viewDidLoad() {
    super.viewDidLoad()

    // Init a photo capture session
    let session = CKFPhotoSession()
    
    // Use CKFVideoSession for video capture
    // let session = CKFVideoSession()
    
    let previewView = CKFPreviewView(frame: self.view.bounds)
    previewView.session = session
}

For capturing a image using the CKFPhotoSession class use this code below:

session.capture({ (image, settings) in
    // TODO: Add your code here
}) { (error) in
    // TODO: Handle error
}

If you want to record a video using the CKFVideoSession class use this code below to start the recording:

// You can also specify a custom url for where to save the video file
session.record(url: URL(string: ""), { (url) in
    // TODO: Add your code here
}) { (error) in
    // TODO: Handle error
}

and end the recording:

// You can also specify a custom url for where to save the video file
session.stopRecording()

You can get the current record status via the isRecording property to determine if a recording is in progress or not.

Session properties and methods

CKFPhotoSession CKFVideoSession
zoom: Double zoom: Double
resolution: CGSize isRecording: Bool
cameraPosition: CameraPosition cameraPosition: CameraPosition
cameraDetection: CameraDetection flashMode: FlashMode
flashMode: FlashMode start()
start() stop()
stop() togglePosition()
focus(at point: CGPoint) setWidth(_ width: Int, height: Int, frameRate: Int)
togglePosition() record(url: URL? = nil, _ callback: @escaping (URL) -> Void, error: @escaping (Error) -> Void)
capture(_ callback: @escaping (UIImage, AVCaptureResolvedPhotoSettings) -> Void, _ error: @escaping (Error) -> Void) stopRecording()

Import into Objective-C projects

Go to Project Settings, Build Settings, Always Embed Swift Standard Libraries and set the value to Yes.

Then import the CameraKit framework using:

@import CameraKit;

Creating custom sessions

CameraKit can be splitted into 2 main pieces: preview and sessions. The sessions are made by extending the base CKFSession class. If you want a custom session you can extend the CKFSession class and use its static helpers to initialize yours. Or you can also extend the built-in sessions and add custom logic.

class MyCustomSession: CKFSession {

    public override init() {
        super.init()
        
        do {
            let deviceInput = try CKFSession.captureDeviceInput(type: .backCamera)
            self.session.addInput(deviceInput)
        } catch let error {
            print(error.localizedDescription)
        }
    }

    // TODO: Add your code here
}

License

CameraKit is released under the MIT License.

Comments
  • Broken preview in landscape

    Broken preview in landscape

    Is this a bug report?

    Yes

    Have you read the Contributing Guidelines?

    There is no such file

    Environment

    CameraKit Version:

    0.1

    iOS Device:

    iPhone 6S

    iOS Version:

    12.1.4

    Steps to Reproduce

    1. Include the component in your app or change the Demo app to support landscape
    2. Rotate the device to landscape

    Expected Behavior

    The preview should show what the camera sees in landscape

    Actual Behavior

    Preview showing zoomed picture rotated 90 degrees

    Reproducible Demo

    This project, the demo when allowing landscape

    Type: Bug Status: Pending 
    opened by igorkulman 3
  • Prefix collision with CloudKit framework

    Prefix collision with CloudKit framework

    Hello. Thank you for the initiative to bring this framework for all developers. :)

    I'm afraid, however, with the class name prefix you choose, that could be collisions with Apple's CloudKit framework.

    Apple suggests that ObjC "safe" prefixes use 3 letters and not only 2 (two letters prefixes would be reserved for Apple use only).

    In Swift prefixes are not usually required, so they can be removed and only specified for ObjC compatibility purposes.

    I'd suggest using something like CKF ("CameraKitFramework") as prefix while in ObjC (CKFSession, for example). And something like CameraSession, for example, while using it in Swift.

    Type: Enhancement Status: In Progress 
    opened by vmartinelli 2
  • iOS Build Error -  Unable to use  CKFPhotoSession With Objective-C

    iOS Build Error - Unable to use CKFPhotoSession With Objective-C

    Is this a bug report?

    I am testing this camerakit-ios library with Objective-C, but unfortunately i am unable to create CKFPhotoSession object it's showing compile time error on Xcode.

    Have you read the Contributing Guidelines?

    Yes

    Environment

    Xcode Version 11.3.1 (11C504)

    CameraKit Version: v1.2.1

    iOS Device: Simulator (iPhone 11 Pro Max)

    iOS Version: 13.3

    Steps to Reproduce

    (Write your steps here:)

    1. Follow installation guide for Objective-C

    2. Import CameraKit_iOS in to ViewController.h Header file

    #import <UIKit/UIKit.h>
    
    @import CameraKit_iOS;
    
    @interface ViewController : UIViewController
    
    
    @end
    
    1. Add flowing code into ViewController.m file
    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        CKFPhotoSession *ckPhotoSession = [[CKFPhotoSession alloc] init];    // Error:  'init' is unavailable
    
        CKFPreviewView *ckfPreviewView = [[CKFPreviewView alloc] initWithFrame:self.view.bounds];
    
        *ckfPreviewView.session = ckPhotoSession;  // Error:  Assigning to 'CKFSession' from incompatible type 'CKFPhotoSession *__strong'
    }
    @end
    

    Expected Behavior

    CKFPhotoSession must allow to create an Objective-C object. Unfortunately it's not allow me to create any Session Object.

    Actual Behavior

    Compile tine error

    Reproducible Demo

    rahadurr/HelloCamera

    opened by rahadurr 1
  • Landscape photo always saved as portrait

    Landscape photo always saved as portrait

    Is this a bug report?

    Yes

    Have you read the Contributing Guidelines?

    No such file

    Environment

    CameraKit Version:

    0.1

    iOS Device:

    iPhone 6S

    iOS Version:

    12.1.4

    Steps to Reproduce

    (Write your steps here:)

    1. Rotate the device to landscape
    2. Take a photo
    3. Save the photo

    Expected Behavior

    Photon saved as landscape

    Actual Behavior

    Photo saved as portrait

    Reproducible Demo

    Demo in this repo

    Type: Bug Status: Pending 
    opened by igorkulman 1
  • Swift Package Manager Support (SPM SUPPORT) ADDED

    Swift Package Manager Support (SPM SUPPORT) ADDED

    Is this a bug report?

    It's not a bug that i am creating issue for.. I am adding SPM support for this CameraKit. And creating a pull request from https://github.com/dipcse07/camerakit-ios

    Have you read the Contributing Guidelines?

    Yes

    Environment

    (Please include the following information along with any other relevant environment details.)

    CameraKit Version: 1.2.1

    iOS Device:

    iOS Version:

    Steps to Reproduce

    (Write your steps here:)

    Expected Behavior

    (Write what you thought would happen.)

    Actual Behavior

    (Write what happened. Add screenshots!)

    Reproducible Demo

    (Paste the link to an example project and exact instructions to reproduce the issue.)

    (Include your CameraKit setup and usage.)

    opened by dipcse07 0
  • Release v1.2.0

    Release v1.2.0

    Release v1.2.0 of CameraKit-iOS

    • New prefix of CKF due to potential conflict with CloudKit
    • Resolved bugs related to orientation

    Close #8 Close #7 Close #10

    opened by austinkettner 0
  • How to get EXIF data from the image captured?

    How to get EXIF data from the image captured?

    Is there a way in the library to get the EXIF data from the image captured? I need the date & time the image was taken and additionally name of the image. The only thing I am getting from Exif is below:

    "{Exif}" = { PixelXDimension = 1000; PixelYDimension = 1000; };

    Full data:

    { ColorModel = RGB; Depth = 8; Orientation = 6; PixelHeight = 1000; PixelWidth = 1000; ProfileName = "Display P3"; "{Exif}" = { PixelXDimension = 1000; PixelYDimension = 1000; }; "{JFIF}" = { DensityUnit = 0; JFIFVersion = ( 1, 0, 1 ); XDensity = 72; YDensity = 72; }; "{TIFF}" = { Orientation = 6; }; }

    opened by oxnnj 0
  • Rotate photo to always portrait

    Rotate photo to always portrait

    How do I take photo always in portrait mode even if the device is in landscape or orientation lock is enabled or not all I want is to take photo in portrait mode.

    Settings I have done:

    photoSession.session.sessionPreset = .photo
            photoSession.flashMode = .auto
            
            previewView.session = self.photoSession
            previewView.autorotate = false
            previewView.previewLayer?.videoGravity = .resizeAspectFill
    

    Taken in landscape mode and device orientation is locked:

    Screen Shot 2022-06-03 at 12 51 21 PM

    Taken in landscape mode but device orientation is unlocked: Screen Shot 2022-06-03 at 12 52 02 PM

    opened by oxnnj 0
  • Using AVAudioSession for audio

    Using AVAudioSession for audio

    Need a little help, how can i add audio input device that was initiated with avAudioSession so i can record video using playAndRecord and ShareWithOthers.

    I have tried using it individually but then i have to merge audio video files which takes a lot of time and is making app slower.

    opened by RaheelAhmad123 0
  • Face detection not working correctly...

    Face detection not working correctly...

    Hello,

    I have noticed that if I start up and the back camera is on and view a face there is not face detection... then I tap more and enable face detection it does not show the face detection box, HOWEVER, if I switch camera and then switch back the face detection is on.

    So, is there a problem for the first time?

    opened by DevStreamLine 0
  • Swift Package Manager Support (SPM SUPPORT) ADDED

    Swift Package Manager Support (SPM SUPPORT) ADDED

    Is this a bug report?

    It's not a bug that i am creating issue for.. I am adding SPM support for this CameraKit. And creating a pull request from https://github.com/dipcse07/camerakit-ios Specific SPM Support repo https://github.com/dipcse07/CameraKit-SPM_Supported

    Have you read the Contributing Guidelines?

    Yes

    Environment

    (Please include the following information along with any other relevant environment details.)

    CameraKit Version: 1.2.1

    iOS Device:

    iOS Version:

    Steps to Reproduce

    (Write your steps here:)

    Expected Behavior

    (Write what you thought would happen.)

    Actual Behavior

    (Write what happened. Add screenshots!)

    Reproducible Demo

    (Paste the link to an example project and exact instructions to reproduce the issue.)

    (Include your CameraKit setup and usage.)

    opened by dipcse07 0
  • SPM SUPPORT

    SPM SUPPORT

    Proposed changes

    I used Swift Package Manager to So that everyone can use this with directly from Swift Package Manager

    Types of changes

    What types of changes does your code introduce to CameraKit? Put an x in the boxes that apply

    • [ ] Bugfix (non-breaking change which fixes an issue)
    • [ x] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

    Checklist

    Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

    • [ x] I have read the CONTRIBUTING doc
    • [x ] Lint and unit tests pass locally with my changes
    • [ ] I have added tests that prove my fix is effective or that my feature works
    • [ ] I have added necessary documentation (if appropriate)
    • [ ] Any dependent changes have been merged and published in downstream modules

    Further comments

    If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

    opened by dipcse07 0
Releases(v1.2.1)
Owner
CameraKit
CameraKit: Unified, Reliable, Camera API on Android
CameraKit
This plugin defines a global navigator.camera object, which provides an API for taking pictures and for choosing images from the system's image library.

title description Camera Take pictures with the device camera. AppVeyor Travis CI cordova-plugin-camera This plugin defines a global navigator.camera

null 0 Nov 2, 2021
A camera app we will dive deep into AVFoundation library

Camera App In this project you are going to discover few concepts in Swift that I've been working on for few weeks, Core Animations with CAShape Layer

Dheeraj Kumar Sharma 12 Nov 13, 2022
An iOS framework that uses the front camera, detects your face and takes a selfie.

TakeASelfie An iOS framework that uses the front camera, detects your face and takes a selfie. This api opens the front camera and draws an green oval

Abdullah Selek 37 Jan 3, 2023
NextLevel is a Swift camera system designed for easy integration, customized media capture, and image streaming in iOS

NextLevel is a Swift camera system designed for easy integration, customized media capture, and image streaming in iOS. Integration can optionally leverage AVFoundation or ARKit.

NextLevel 2k Jan 2, 2023
Custom camera with AVFoundation. Beautiful, light and easy to integrate with iOS projects.

?? Warning This repository is DEPRECATED and not maintained anymore. Custom camera with AVFoundation. Beautiful, light and easy to integrate with iOS

Tudo Gostoso Internet 1.4k Dec 16, 2022
A fully customisable and modern camera implementation for iOS made with AVFoundation.

Features Extremely simple and easy to use Controls autofocus & exposure Customizable interface Code-made UI assets that do not lose resolution quality

Gabriel Alvarado 1.3k Nov 30, 2022
iOS camera engine with Vine-like tap to record, animatable filters, slow motion, segments editing

SCRecorder A Vine/Instagram like audio/video recorder and filter framework in Objective-C. In short, here is a short list of the cool things you can d

Simon Corsin 3.1k Dec 25, 2022
A simple, customizable camera control - video recorder for iOS.

LLSimpleCamera: A simple customizable camera - video recorder control LLSimpleCamera is a library for creating a customized camera - video recorder sc

Ömer Faruk Gül 1.2k Dec 12, 2022
Fasttt and easy camera framework for iOS with customizable filters

FastttCamera is a wrapper around AVFoundation that allows you to build your own powerful custom camera app without all the headaches of using AVFounda

IFTTT 1.8k Dec 10, 2022
A light weight & simple & easy camera for iOS by Swift.

DKCamera Description A light weight & simple & easy camera for iOS by Swift. It uses CoreMotion framework to detect device orientation, so the screen-

Bannings 86 Aug 18, 2022
Camera engine for iOS, written in Swift, above AVFoundation. :monkey:

?? The most advanced Camera framework in Swift ?? CameraEngine is an iOS camera engine library that allows easy integration of special capture feature

Remi ROBERT 575 Dec 25, 2022
A Snapchat Inspired iOS Camera Framework written in Swift

Overview SwiftyCam is a a simple, Snapchat-style iOS Camera framework for easy photo and video capture. SwiftyCam allows users to capture both photos

Andrew Walz 2k Dec 21, 2022
Video and photo camera for iOS

Features: Description Records video ?? takes photos ?? Flash on/off ⚡ Front / Back camera ↕️ Hold to record video ✊ Tap to take photo ?? Tap to focus

André J 192 Dec 17, 2022
ALCameraViewController - A camera view controller with custom image picker and image cropping.

ALCameraViewController A camera view controller with custom image picker and image cropping. Features Front facing and rear facing camera Simple and c

Alex Littlejohn 2k Dec 6, 2022
UIView+CameraBackground - Show camera layer as a background to any UIView.

UIView+CameraBackground Show camera layer as a background to any UIView. Features Both front and back camera supported. Flash modes: auto, on, off. Co

Yonat Sharon 63 Nov 15, 2022
Instagram-like photo browser and a camera feature with a few line of code in Swift.

Fusuma is a Swift library that provides an Instagram-like photo browser with a camera feature using only a few lines of code.

Yuta Akizuki 2.4k Dec 31, 2022
BarcodeScanner is a simple and beautiful wrapper around the camera with barcode capturing functionality and a great user experience.

Description BarcodeScanner is a simple and beautiful wrapper around the camera with barcode capturing functionality and a great user experience. Barco

HyperRedink 1.6k Jan 7, 2023
A camera designed in Swift for easily integrating CoreML models - as well as image streaming, QR/Barcode detection, and many other features

Would you like to use a fully-functional camera in an iOS application in seconds? Would you like to do CoreML image recognition in just a few more sec

David Okun 868 Dec 29, 2022
Mock UIImagePickerController for testing camera based UI in simulator

Mock UIImagePickerController to simulate the camera in iOS simulator.

Yonat Sharon 18 Aug 18, 2022