Fail: Simultaneous Front and Back Camera Access on a Samsung Galaxy S4

Programmatically access video streams of front and back camera of a Samsung  Galaxy S4 simultaneously. This feature is available in the Samsung Camera app which ships with the Galaxy S4 as can be seen here:

So far, I have not been successful in programmatically accessing both camera streams at the same time.  I tried: 1) the Android API, 2) OpenCV Android Java API, 3) OpenCV Android C++ API. For the results of my individual attempts see below

First Try – Android API
The expected way to access both front and back camera for me was to use the official Android Camera API.

The camera object provides the open() function which “Creates a new Camera object to access a particular hardware camera.” In your code you would do something like:

Camera cback = null;
Camera cfront = null;
try {
cback =;
cfront =;
catch (Exception e){
// Camera is not available (in use or does not exist)
Log.e("camtest", e.toString() );

If this would be successful you could continue to create your SurfaceView objects and display the camera streams as explained here. But for me this approach did not work out but rather generated following exception:

 java.lang.RuntimeException: Fail to connect to camera service

Code available at on my bitbucket repo.

Second try – OpenCV Android Java API

The OpenCV SDK for Android is a powerful computer vision library which I use for many of my projects. OpenCV for Android provides a Java API which can be used to access the cameras. in fact, OpenCV ships with a bunch of tutorials, including the Camera Preview tutorial. To access the camera you use the CameraBridgeViewBase and the subclass JavaCameraView. Unfortunately, JavaCameraView is merely a wrapper around the Android camera API (as can be seen here on line 85) and hence results in the same problems.

Third try – OpenCV Android Native API
OpenCV also gives you the option to use their native camera implementation which can be accessed through NativeCameraView (basically wrapping a VideoCapture object). While working quite well on a number of devices, so far (May 2014, OpenCV version 2.4.9) the Samsung Galaxy S4 does not run the code but rather aborts with (an issue discussed in the OpenCV community):

A/libc(6804): Fatal signal 11 (SIGSEGV) at 0xf5a0000c (code=1), thread 6804 (mples.tutorial1)

Three attempts, three failures. If you have other ideas what could be tried to programmatically access both camera streams of the back and front camera simultaneously on an Samsung Galaxy S4 please feel free to drop me a line or post a comment.



One thought on “Fail: Simultaneous Front and Back Camera Access on a Samsung Galaxy S4

  1. Pingback: Success: Simultaneous Front and Back Camera Access on a HTC One M8 | Excursions into Augmented Reality and Mobile HCI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s