似乎opencv无法在Android 5. +(棒棒糖)上使用原生相机。 cf: http://code.opencv.org/issues/4185
还有其他方法从本机活动中获取图片然后转换为cv :: mat吗? 或者,也许我可以使用jni从我的c ++活动中调用java中的抓取函数?
感谢您的帮助
查尔斯
答案 0 :(得分:0)
您可以使用jni从c ++活动中调用java中的抓取函数,如下所示(阈值示例):
Java代码:
//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 ++代码:
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()");
}
}
希望这有帮助!