OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -


there several posts converting mat bitmap using utils.mattobitmap() function. i'm assuming function can called in java layer after importing utils class.

i want transfer data memory address pointed uint32_t* bmpcontent; in code below.

jniexport void jnicall java_com_nod_nodcv_nodcvactivity_runfilter(     jnienv *env, jclass clazz, jobject outbmp, jbytearray indata,     jint width, jint height, jint choice, jint filter) {     int outsz = width*height;     int insz = outsz + outsz/2;     androidbitmapinfo bmpinfo;      if (androidbitmap_getinfo(env, outbmp, &bmpinfo) < 0) {         throwjavaexception(env,"gaussianblur","error retrieving bitmap meta data");         return;     }     if (bmpinfo.format != android_bitmap_format_rgba_8888) {         throwjavaexception(env,"gaussianblur","expecting rgba_8888 format");         return;     }     uint32_t* bmpcontent;     if (androidbitmap_lockpixels(env, outbmp,(void**)&bmpcontent) < 0) {         throwjavaexception(env,"gaussianblur","unable lock bitmap pixels");         return;     }      //this function runs kernel on indata , gives matrix     tester(env, clazz, bmpcontent, outsz, indata, insz, width, height);      androidbitmap_unlockpixels(env, outbmp); } 

this happens in tester function:

jbyte*  b_mat  = env->getbytearrayelements(indata, 0); cv::mat mdata(h, w, cv_8uc4, (unsigned char *)b_mat);  cv::mat mat_src = imdecode(mdata,1);   cv::umat umat_src = mat_src.getumat(cv::access_read, cv::usage_allocate_device_memory); cv::umat umat_dst (mat_src.size(), mat_src.type(), cv::access_write, cv::usage_allocate_device_memory);  kernel.args(cv::ocl::kernelarg::readonlynosize(umat_src), cv::ocl::kernelarg::readwrite(umat_dst));  size_t globalthreads[3] = {static_cast<unsigned int>(mat_src.cols), static_cast<unsigned int>(mat_src.rows), 1 };  bool success = kernel.run(3, globalthreads, null, true);  cv::mat mat_dst = umat_dst.getmat(cv::access_read); 

mat_dst holds results need , need display on phone. how can that?

i'm assuming i'll need copy data mat_dst bmpcontent place, i'm not sure.

use convert mat bitmap.

jclass java_bitmap_class = (jclass)env->findclass("android/graphics/bitmap"); jmethodid mid = env->getmethodid(java_bitmap_class, "getconfig", "()landroid/graphics/bitmap$config;"); jobject bitmap_config = env->callobjectmethod(bitmap, mid); jobject _bitmap = mat_to_bitmap(env,dst,false,bitmap_config);  androidbitmap_unlockpixels(env, bitmap); return _bitmap; 

Comments

Popular posts from this blog

python - How to remove the Xframe Options header in django? -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -