android - native activity camera on lollipop with opencv -
it seems opencv can't use native camera on android 5.+ ( lollipop ). cf : http://code.opencv.org/issues/4185
is there other way grab pictures native activity , convert cv::mat ? or, maybe use jni call grab function in java c++ activity ?
thank help
charles
you use jni call grab function in java c++ activity, 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; } // 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 helps!
Comments
Post a Comment