Android passing file path to OpenCV imread method -
i trying use opencv in android project , trying run native code don't know how use parameter
jniexport jint jnicall java_com_example_helloopencvactivity_nativecalls_filepath (jnienv * env, jobject jo, jstring str1, jstring str2) { cv::mat img1 = cv::imread(""); }
i tried using this
const char *nativestring = (*env)->getstringutfchars(env, str1, 0); cv::mat img1 = cv::imread(nativestring);
but getting error error: no matching function call '_jnienv::getstringutfchars
i need pass file path android file system opencv's native code processing, passing element string , should read imread
first in java side, codes looks like:
private string path="/mnt/sdcard/"; initfeature(width,height,path); public native void initfeature(int width, int height,string path);
then in jni side, it's:
//passed java part , release after initfreature const char* npath; //to save globle path char* g_path; jniexport void jnicall java_org_opencv_samples_tutorial6_tutorial2activity_initfeature(jnienv* env, jobject,jint width,jint height,jstring path); jniexport void jnicall java_org_opencv_samples_tutorial6_tutorial2activity_initfeature(jnienv* env, jobject,jint width,jint height,jstring path) { //jsize path_size; npath=env->getstringutfchars(path,null); //path_size=env->getarraylength(path); logd("path: %s \n",npath); int length=strlen(npath); logd("length: %d \n",length); g_path=new char[length+1]; memcpy(g_path,npath,length+1); logd("path_2: %s \n",g_path); logd("length: %d \n",strlen(g_path)); char l_path[128]; strcpy(l_path,g_path); strcat(l_path,"color.jpg"); logd("path_3: %s \n",l_path); logd("length: %d \n",sizeof(l_path)); m_width=width; m_height=height; center.x=float (m_width/2.0+0.5);//float (img_tmp->width/2.0+0.5); center.y=float (m_width/2.0+0.5);//float (img_tmp->height/2.0+0.5); env->releasestringutfchars(path,npath); }
since have different native calls, 1 initiate features(shown here) , others process every frame, , after env->releasestringutfchars(path,npath);
string invisible jni part. have copy string global char* g_path;
and little sample here well, file path "/mnt/sdcard/color.jpg" , check logs.
then can use imread() jpg. use other libs libjpg, not showing codes here.
Comments
Post a Comment