0

I want to open android tablet's camera and get the data from camera in C level. After that I will modify the data, and C level will be efficient.

Now I'm thinking using the V4L2 C code. But I find the open function of V4L2 need the parameter of the camera's name, such as '/dev/video0'. However I can't find something like that in my tablet's dev folder. Besides, I am not sure whether using the V4L2 will be the right solution.

Does anyone know anything about this?

2
  • 1
    What version of Android? Android 4.4 provides the new ImageReader class (developer.android.com/reference/android/media/ImageReader.html), which speeds access to YUV buffers from the camera. Commented Nov 18, 2013 at 15:39
  • Thank you. Any version would be fine. But I need to get them in C level so I will modify the data in C level directly, which is more efficient than Java. Commented Nov 19, 2013 at 1:56

2 Answers 2

1

on my device "OpenCV for Android" does not provide required performance neither in 'native' mode nor in 'java' mode. it gives FPS=2 in 1920x1080, in same time when java MediaRecorder can record 1920x1080 with FPS=15

I'm trying to solve it using the code from Android Open Source Project used by native Camera application:

static void android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz,
    jobject weak_this, jint cameraId)
{
    sp<Camera> camera = Camera::connect(cameraId);

    if (camera == NULL) {
        jniThrowRuntimeException(env, "Fail to connect to camera service");
        return;
    }

    // make sure camera hardware is alive
    if (camera->getStatus() != NO_ERROR) {
        jniThrowRuntimeException(env, "Camera initialization failed");
        return;
    }

    jclass clazz = env->GetObjectClass(thiz);
    if (clazz == NULL) {
        jniThrowRuntimeException(env, "Can't find android/hardware/Camera");
        return;
    }

    // We use a weak reference so the Camera object can be garbage collected.
    // The reference is only used as a proxy for callbacks.
    sp<JNICameraContext> context = new JNICameraContext(env, weak_this, clazz, camera);
    context->incStrong(thiz);
    camera->setListener(context);

    // save context in opaque field
    env->SetIntField(thiz, fields.context, (int)context.get());
}
Sign up to request clarification or add additional context in comments.

1 Comment

If you are good in ndk code for image processing ,help me to complete the ndk snippit of the receiver end from the below attached pdf. google.co.in/…
0

You can always build a JNI method for the Java classes to get access from C. Another way could be using OpenCV for Android: OpenCV4Android

This gives you a interface to the camera, but as far as I remember, there is currently no support for Android 4.3+.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.