java - OpenCV predict takes too much time and freezes the screen -
i have tried following code predict using camerabridgeviewbase
.
public mat oncameraframe(camerabridgeviewbase.cvcameraviewframe inputframe) { mgray = inputframe.gray(); if (mabsolutefacesize == 0) { int height = mgray.rows(); if (math.round(height * mrelativefacesize) > 0) { mabsolutefacesize = math.round(height * mrelativefacesize); } } matofrect faces = new matofrect(); if (mjavadetector != null) mjavadetector.detectmultiscale(mgray, faces, 1.1, 2, 2, new size(mabsolutefacesize, mabsolutefacesize), new size()); rect[] facesarray = faces.toarray(); if (facesarray.length == 0) { return mrgba; } if (facetype == predict && canpredictnext) { canpredictnext = false; mat m = mgray.submat(facesarray[0]); int[] label = new int[1]; double[] d = new double[1]; facerecognizer.predict(m, label, d);
here screen freezes until log has been gets printed. may know how avoid this?
log.v(tag, "id: "+label[0]+", confidence: "+d[0]); canpredictnext = true; } return mrgba; }
this predict
freezes screen minimum 3 sec.
predict in facerecognizer class.
public void predict(mat mgrey, int[] label, double[] confidence) { predict(mgrey.getnativeobjaddr(), label, confidence); }
and native predict method declared
public native void predict(long mats, int[] integer, double[] d);
jni method predict is
jniexport void jnicall java_com_opencv_test_facerecognizer_predict (jnienv *env, jobject thisobj, jlong images1, jintarray label, jdoublearray confidence) { mat &mgr = *(mat *) images1; jint *labelbody = (*env).getintarrayelements(label, 0); jdouble *confidencebody = (*env).getdoublearrayelements(confidence, 0); int &mylabel = labelbody[0]; double &myconfidence = confidencebody[0]; model->predict(mgr, mylabel, myconfidence); (*env).releaseintarrayelements(label, labelbody, 0); (*env).releasedoublearrayelements(confidence, confidencebody, 0); }
any increase speed of predict , resolve predict issue highly appreciated.
Comments
Post a Comment