Natural activity camera on lollipop with opencv
It seems that opencv cannot use the built-in camera on Android 5.+ (lollipop). cf: http://code.opencv.org/issues/4185
Is there any other way to grab images from native activity and then convert to cv :: mat? Or maybe I could use jni to call the grab function in java from my C ++ activity?
thanks for the help
Charles
+3
source to share
1 answer
You can use jni to call grab function in java from c ++ activity like this (threshold example):
Java code:
//Override JavaCameraView OpenCV function
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
ProcessImage.threshold(mGray, mGray, 97, 0);
return mGray;
}
// Your functions
public static void threshold(Mat srcGray, Mat dst, int thresholdValue, int thresholdType) {
nativeThreshold(srcGray.getNativeObjAddr(), dst.getNativeObjAddr(), thresholdValue, thresholdType.ordinal());
}
private static native void nativeThreshold(long srcGray, long dst, int thresholdValue, int thresholdType);
JNI C ++ code:
JNIEXPORT void JNICALL Java_{package}_nativeThreshold
(JNIEnv * jenv, jobject jobj, jlong scrGray, jlong dst, jint thresholdValue, jint thresholdType)
{
try
{
Mat matDst = *((Mat*)dst);
Mat matSrcGray = *((Mat*)scrGray);
threshold( matSrcGray, matDst, thresholdValue, max_BINARY_value, thresholdType );
}
catch(cv::Exception& e)
{
LOGD("nativeThreshold caught cv::Exception: %s", e.what());
jclass je = jenv->FindClass("org/opencv/core/CvException");
if(!je)
je = jenv->FindClass("java/lang/Exception");
jenv->ThrowNew(je, e.what());
}
catch (...)
{
LOGD("nativeThreshold caught unknown exception");
jclass je = jenv->FindClass("java/lang/Exception");
jenv->ThrowNew(je, "Unknown exception in JNI code ProcessImage.nativeThreshold()");
}
}
Hope this helps!
0
source to share