Because I had to analyze the RGB and HSV values I couldn’t use the solution @Settembrini mentioned. To solve my problem, I created a function in C using the Android NDK. The C function handles the analyzing and returns the result. Even on slower devices I reach the 30 FPS I need to. Probably in most cases the solution of @Miao Wang will stand.
For Android studio users:
- Install the NDK from SDK Tools (File > Preferences > Appearance & Behavior > System Settings > Android SDK (SDK Tools tab)
- Create a sub-directory called "jni" and place all the native sources here.
- Create a "Android.mk" to describe your native sources to the NDK build system.
- Build your native code by running the "ndk-build" (in NDK installed directory) script from your project's directory. The build tools copy the stripped, shared libraries needed by your application to the proper location in the application's project directory.
Integrate the native method in your Activity:
// loading native c module/lib
static {
try {
System.loadLibrary("rgbhsvc");
} catch (UnsatisfiedLinkError ule) {
Log.e(DEBUG_TAG, "WARNING: Could not load native library: " + ule.getMessage());
}
}
//Create native void to calculate the RGB HSV
private native void YUVtoRBGHSV(double[] rgb_hsv, byte[] yuv, int width, int height);
Create the C part to process the data:
JNIEXPORT
void
JNICALL Java_nl_example_project_classes_Camera_YUVtoRBGHSV(JNIEnv * env, jobject obj, jdoubleArray rgb_hsv, jbyteArray yuv420sp, jint width, jint height)
{
// process data
(*env)->SetDoubleArrayRegion(env, rgb_hsv, 0, sz, ( jdouble * ) &rgbData[0] );
//Release the array data
(*env)->ReleaseByteArrayElements(env, yuv420sp, yuv, JNI_ABORT);
}
A good introduction to the Android NDK: https://www.sitepoint.com/using-c-and-c-code-in-an-android-app-with-the-ndk/
Thanks for all the answers!