I'm planning to take a picture by camera phone (Android) then pass it to C function through JNI. The C function is generated by MATLAB Coder.
Here is the header of the generated C function:
real_T detection(const **uint8_T** OriginalImage[28755648])
Here is the data type of the image:
@Override
public void onPictureTaken(**byte[] data**, Camera camera) {.....}
Question: How to convert byte[] to uint8_T array? I found how to convert byte[] to jbyte *.. but I don't know how to deal with uint8_T?
I know only Java but not C.
Regards,
Java does not have unsigned integer types, but the camera does not really care. You can safely cast the byte array that arrives from onPictureTaken()
callback to uint8_t*
.
Sidenote: most likely, the picture will arrive as JPEG stream.
Update: Example of implementing onPictureTaken()
in C.
Here is what you have somewhere in your activity:
mCamera = Camera.open();
mCamera.setPreviewDisplay(surfaceHolder);
mCamera.startPreview();
...
mCamera.takePicture(null, null, new android.hardware.Camera.NativePictureCallback);
Here is the file src/android/hardware/Camera/NativePictureCallback.java:
package android.hardware.Camera;
class NativePictureCallback: implements PictureCallback {
static {
System.loadLibrary("NativeCamera");
}
public void native onPictureTaken(byte[] data, Camera camera);
}
And here is the C file that is part of libNativeCamera.so:
include <jni.h>
include <tmwtypes.h>
real_T detection(const uint8_T* OriginalImage);
JNIEXPORT void JNICALL
Java_android_hardware_Camera_NativePictureCallback_onPictureTaken(
JNIEnv* env, jobject thiz, jbytearray data, jobject camera) {
jbyte* dataPtr = (*env)->GetByteArrayElements(env, data, NULL);
real_T res = detection((const uint8_T*)dataPtr);
(*env)->ReleaseByteArrayElements(env, data, dataPtr, JNI_ABORT);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With