Grabbing speed using OpenCV2.3.1

Skip to first unread message


Jan 25, 2012, 11:32:25 AM1/25/12
to android-opencv
Since many members have talked/asked about OpenCV and speed, I was
wandering what would be the FPS if no processing is done.
In order to achieve that, I modified "tutorial-2-opencvcamera" and
commented out this line
bmp = processFrame(mCamera);
so basically, what's left is just the time of mCamera.grab()

Surprisingly, I got ~10FPS (in average even less) even for the
smallest image size (width = 128, height = 96) on my Samsung Galaxy
Nexus !
Do u guys have any idea why?

I'm afraid that if that's the case, no matter how optimized our code
is written - will never achieve better than 10FPS.

Rui Marques

Jan 26, 2012, 10:45:03 AM1/26/12
to android-opencv
That is weird i have about 30fps, even without removing all
processing, on my Motorola Atrix.


Jan 27, 2012, 12:46:42 AM1/27/12
to android-opencv
Thanks Rui,
Your OS is gingerbread...
Could it be that the "new" camera libraries for ICS (my OS is ICS)
cause the slow-down?
Message has been deleted

Ricardo Aires

Jan 27, 2012, 7:03:23 AM1/27/12
to android-opencv
Well, actually I am facing the same issue on the GalaxyS running

I created an application and the only thing it does is show a 640x480
rgba camera image, and by measuring fps on each execution of the while
cycle, I can only obtain ~15fps. This is not an acceptable performance
for my application wherein I also need to use SURF and OF. The problem
is resolved by decreasing the image res, but I need an image that fits
the entire screen!

This is my app file:

The weirdest thing is that when I run the same code in the GalaxyTab
with the same image resolution it runs slower (8FPS)! This is very
strange, since the tab is a Tegra2 dual-code 1Ghz. Although I suspect,
in this case, there are some memory issues, since it seems the gc gets
the bitmap reference and does a memory dealloc/alloc every frame, this
is a good example on how trickly different android devices work.

I also noticed that there is a Log tag like this:
"I/OpenCV_NativeCamera(19783): ### Camera FPS ### [8580] Frames, 30.06

However, even when my application is slowing down, it ALWAYS shows the
same value... around 30FPS. This might actually be the "grabing" speed
and not the retrieving!

I have to agree with Philip, that no matter we optimize code, we will
never achieve better speeds?

Is there anyway to solve these problems?

On Jan 26, 6:57 pm, Philip <> wrote:
> Tnx Rui for your input.
> Your OS is Gingerbread, while Galaxy Nexus is ICS. Could it be that
> the "new" native libraries cause the slow down:
> On Jan 26, 5:45 pm, Rui Marques <> wrote:

Ricardo Aires

Jan 27, 2012, 7:03:33 AM1/27/12
to android-opencv

Rui Marques

Jan 27, 2012, 10:38:11 AM1/27/12
to android-opencv
If you run the sample tutorial, without your changes, is it also


Jan 27, 2012, 11:16:56 AM1/27/12
to android-opencv
Same issue here. I can only obtain 5-15 fps (android-opencv samples
with fixed camera libs).
I'm going to use android-opencv to implement a traffic sign
recognition and detection algorithm.
I'm currently thinking about offloading the processing to the cloud
(e.g. Amazon EC2).
Message has been deleted
Message has been deleted
Message has been deleted


Jan 29, 2012, 1:15:08 PM1/29/12
to android-opencv
Rui - are you using the opencv native camera interface VideoCapture?
I'm afraid that native camera calls are much slower than using the
Java camera implementation.

Does anyone have any insight on this issue (VideoCapture Vs. Camera)?
Message has been deleted

Ricardo Aires

Jan 30, 2012, 6:36:43 AM1/30/12
to android-opencv
Hello again!

Yes, it is slow with all the samples, with the 640,480 rgba image.

I've tested both implementations and for that type of image, the
Android camera works slowly. The problem here is, I think, the
conversion between the Yuv frame that comes from the Android camera
and the Rgba Mat format used by most OpenCV routines.

You can check the tests I tried here:

Android camera:
Opencv camera:

Feel free to scrutinize!

The results with the SGS are as follows
W/Android Camera(24643): Average frame time: 95.829ms ##Frame Rate:
W/Opencv Camera(25051): Average frame time: 64.445ms ##Frame Rate:

On Jan 29, 2:23 pm, Philip <> wrote:
> T

Rui Marques

Jan 30, 2012, 10:54:53 AM1/30/12
to android-opencv
I've used the native camera, from what i read it is faster.
Here some info about the cameras (i found it its not mine):

native camera:
+ higher framerate
+ capture RGBA, no need to convert from android yuv format
- compiled only for armv7 architecture
- not work on all devices (for now)
- not support autofocus, setting gain.. (for now)

Andrey Kamaev

Jan 30, 2012, 11:56:16 AM1/30/12
Hi Rui,

The info about camera is not fully correct:

+ higher framerate

It is expected that this will be the case. At least native camera avoids two full-frame data copies: native to java and java to native.
But it takes accurate benchmarking to be objective.
+ capture RGBA, no need to convert from android yuv format

It just means that conversion is performed implicitly. You can get gray-scale frame on the cost of copying and RGB or RGBA on the cost of color conversion.
- compiled only for armv7 architecture

Camera libraries for Android 2.2.x, 2.3.x, 3.x.x are compiled both for armv5te (armeabi) and arm-v7a (armeabi-v7a). Prebuilt libraries for Android 4.0.x are available only for arm-v7a.
Most probably x86 version will be available in upcoming OpenCV release.
- not work on all devices (for now)

It is true for devices running Android 2.x.x (for example, Motorola devices). The problem should be fixed for Android 3.0.1 and newer.

- not support autofocus, setting gain.. (for now)

Correct. Might be fixed in upcoming OpenCV release.



Jan 30, 2012, 1:28:38 PM1/30/12
to android-opencv
Hi Andrey,

Though I didn't take a benchmark on it, I found that I achieve much
higher frame rate for Java camera implementation over VideoCapture if
no processing is taking at all (meaning, just obtaining images and
Yet, in both cases if I do take any kind of precessing the frame rate
drops drastically.

From your experience, have u achieved acceptable (>20) frame rate for
the OpenCV samples?



Feb 2, 2012, 2:37:19 AM2/2/12
to android-opencv
I found this long and interesting thread:
which discuss in detail the huge overhead of allocating and freeing
memory in onPreviewFrame(byte[] data, Camera camera)
The thread also offers an alternative which is to use:
public final void setPreviewCallbackWithBuffer(PreviewCallback cb)
public native final void addCallbackBuffer(byte[] callbackBuffer);

I guess that OpenCV VideoCapture doesn't implement such buffer, and
therefore suffers from a bottleneck in the performance (low fps)

As I wrote before, I tried to run the OpenCV samples without doing any
image processing (I commented out the processFrame function) and got
10-15fps for full image size on my Galaxy Nexus. I did the same test
with the example from the above thread and got 30fps!

Why hasn't OpenCV implemented such buffer for their VideoCapture


Kirill Kornyakov

Feb 2, 2012, 2:57:19 AM2/2/12
Sounds interesting! It this approach is better, you can contribute a patch to OpenCV4Android.

Why hasn't OpenCV implemented such buffer for their VideoCapture

Don't you know that library still has a beta-status and the development team has limited resources? The library is developed professionally, but we have tons on TODOs on every level: C++, Java API, accuracy, performance, samples, feature requests and yes, interaction with Android camera. So, if you have a piece of useful code, please share it. We will integrate it with pleasure!



Feb 2, 2012, 3:36:03 AM2/2/12
to android-opencv
Dear Kirill,
I didn't mean to be rude. Your work is highly appreciated and great.
I'm sure that you guys have a lot on your desk...

It's just that this issue (capturing performance) has been discussed
widely on the web for almost 2 year, so I assumed that you experts
have decided to implement VideoCapture in the way you did for a good


On Feb 2, 9:57 am, Kirill Kornyakov <>

Kirill Kornyakov

Feb 2, 2012, 5:49:24 AM2/2/12
OK, we'll look into it. Actually ICS provide native OpenMAX API for the camera access and Video IO, and we're going to switch to this officially supported native API. Older native camera implementation is a bit hacky because Google supported only Java API for camera and changed C++ API - this is why older implementation of native camera was broken on Android 3.2 and 4.0. Currently we have a workaround for new Android, yes it is slow, and we'll work on native camera before the next public release. But our goal here is OpenMAX, because it is officially supported and may give us video files reading/writing as a bonus :)



Feb 7, 2012, 9:39:37 PM2/7/12
Hi Kirill,

Are you sure the OpenCV native camera can be change to use OpenMAX API? According to the Android NDK document: android-ndk-r7/docs/openmaxal/index.html, CreateCameraDevice is not supported yet. 

Linda Li

Mar 7, 2013, 11:54:05 AM3/7/13
This is an old post. But I happen to meet a similar problem.
I need to process the video frame, and then present on the screen, and save to a video file.

From what I researched, it seems the previewFrame can not fit the requirement.
One ID said: "The preview callback is merely giving you a sample of the actual video capture, not the entire video capture -- since most 15fps videos will still look smooth, the preview callback is only giving you a lower resolution, lower fps preview version of the actual video being captured. Even the built-in samsung capture application will only show the preview version, because that's all the preview interface is being given."

So preview is only for presentation purpose. The real frame needs to be from video recording.
Reply all
Reply to author
0 new messages