Android Camera Library Comparison

Fotoapparat vs. CameraKit

Jason Pribble
6 min readNov 28, 2017

Intro

Android camera APIs can be notoriously difficult to use but luckily several open source camera libraries have been created to help ease development pains. After evaluating seventeen different camera libraries, I’ve selected two of my personal favorites for this comparison: Fotoapparat and CameraKit. We’ll evaluate them head-to-head to compare their features, performance, stability, configurability, and more.

Before we dive into their differences, let’s take a look at some of their similarities.

  • Both libraries were created within the last year and are under active development with good community support and documentation.
  • Both provide camera view objects that are not dependent on custom Activity/Fragments which allows for greater flexibility and customization.
  • Although Google has deprecated the Camera1 API, both libraries favor it over the newer Camera2 API due to its simplicity and ease of use.
  • They both contain some of level of code support for Camera2 but both libraries default to use Camera1 on all API levels.
  • Both libraries are recommended by Mark Murphy as alternatives to his excellent, but now deprecated CWAC-Camera and CWAC-Cam2 libraries.

Overview

Fotoapparat

CameraKit

  • Created by Wonderkiln in November 2016
  • Min API: 15
  • License: MIT
  • Version tested: 0.12.0

Features

Lets take a look at the features each library includes.

Notes:

  1. Fotoapparat has an open PR to add Touch Focus support.
  2. CameraKit has an open issue tracking adding Frame Processor support.
  3. Fotoapparat is considering adding video support.

Configurability

Both libraries allow for simple settings such as focus, flash, and camera front/back selection to be changed dynamically. However, they differ in how much configuration they allow beyond that.

CameraKit prefers ease of use over customization. It automatically selects the camera and preview resolutions for you and automatically crops the preview frames to fit in the space available.

Conversely, Fotoapparat favors customization and provides clever APIs that expose the device’s capabilities and allow them to be configured however you desire. In addition to being able to set specific resolutions, you can also configure the sensor’s sensitivity (ISO) and the frame processor’s FPS setting. The APIs provide filters and selectors to help you dynamically select ideal settings. For example, it allows for advanced logic such as:

Select the largest 16:9 resolution. If there are none available, then select the largest 4:3 resolution.

The code to implement that is very simple and looks like this:

builder.photoSize(
firstAvailable(
wideRatio(biggestSize()),
standardRatio(biggestSize())
)
)

Performance

CameraKit claims to be “extremely performant” and has optimized its bitmap processing code by moving it into native code. In this section we’ll compare each library’s capture speed to see if CameraKit’s native code gives it an advantage over Fotoapparat.

First, we’ll compare the capture speed of taking full resolution (4032x2268) images and receiving the output as a byte array with rotation correction.

Note: All data below was captured on a Samsung Galaxy S8 and measurements were averaged over ten runs.

Fotoapparat averaged 104ms (7%) quicker

Both libraries also support a quick capture mode that captures a lower resolution image from the preview stream. CameraKit calls this mode “Still” capture and Fotoapparat supports this via its frame processor. Let’s look at how the capture speed compares using the quick capture mode in each library.

Fotoapparat averaged 131ms (27%) quicker

Fotoapparat supports an additional option which allows images to be saved directly to a file instead of receiving them as a byte array. This option can be applied to both standard capture mode and quick capture mode. Since CameraKit doesn’t support this option, we’ll compare how Fotoapparat’s ‘Save to File’ option affects performance of its capture modes.

Saving to a file is 4x quicker than receiving the image as a byte array

The main reason saving to a file is quicker is because the image’s orientation information is written to the file’s EXIF data which means the image doesn’t have to be rotated programmatically.

Stability

To test stability, both libraries’ sample apps were tested across a variety of devices ranging from Android 4.1.1 to 7.0.

✓ == successful image capture; ✘ == fatal crash

Fotoapparat was crash-free and was able to successfully capture images on all devices tested. CameraKit crashed on 4 of 12 devices due to two distinct issues.

  1. Devices #9 and #10 crashed due to a NullPointerException when the capture button was clicked because the library returned a null byte array for the image. Issue is tracked here.
  2. Devices #11 and #12 crashed due to an UnsatisfiedLinkError while trying to load native libraries needed for bitmap processing. This issue appears to affect devices running Android 4.2 and older. Issue is tracked here.

Size

CameraKit is significantly larger than Fotoapparat due to its use of native code. If size is a concern and you don’t need support for all architectures included (hint: you don’t), you can reduce CameraKit’s size by using NDK abiFilters in your build.gradle file to only include the architectures that your project needs. For example, including the filter below which only includes armeabi-v7a and x86 reduces CameraKit’s size by 73% (from 1.5MB down to 0.4MB).

android {
...
defaultConfig {
...
ndk {
abiFilters "armeabi-v7a", "x86"
}

}
}

See Controlling APK Size When Using Native Libraries for more information.

Future Plans

CameraKit follows a monthly release schedule and has numerous improvements and new features coming in their next release v0.13.0. Here’s a sneak peek of their plans for CameraKit’s v1.0.0 release scheduled for January 2018:

  • Improved reliability and stability
  • More customization
  • Natural Language Processing text recognition
  • Pre-processing engine allowing for better filter support, on-face mapping of VFX, and more
  • Custom object tracking support
  • ARCore Integration

Summary

Based on the current versions, as long as you don’t need video support, Fotoapparat features more capabilities, is more configurable, has a quicker capture, is more stable, and is smaller sized. If you do need video in your app, check out CameraKit’s video feature.

Both libraries have a great community that are actively developing new features, so visit their repos to view their development progress or contribute to their roadmap.

DISCLOSURE STATEMENT: These opinions are those of the author. Unless noted otherwise in this post, Capital One is not affiliated with, nor is it endorsed by, any of the companies mentioned. All trademarks and other intellectual property used or displayed are the ownership of their respective owners. This article is © 2017 Capital One.

--

--