How to get the Mat object from the Byte[] in openCV android?

后端 未结 5 2180
梦谈多话
梦谈多话 2020-12-29 10:46

I am working with OpenCV library in Android. I have a class which implements PictureCallBack.

The override method onPictureTaken() is as g

5条回答
  •  Happy的楠姐
    2020-12-29 11:06

    For me, the next works fine for me:

    Java side:

        Bitmap bitmap = mTextureView.getBitmap(mWidth, mHeight);
        int[] argb = new int[mWidth * mHeight];
        // get ARGB pixels and then proccess it with 8UC4 OpenCV convertion
        bitmap.getPixels(argb, 0, mWidth, 0, 0, mWidth, mHeight);
        // native method (NDK or CMake)
        processFrame8UC4(argb, mWidth, mHeight);
    

    OpenCV side (NDK):

    JNIEXPORT jint JNICALL com_native_detector_Utils_processFrame8UC4
        (JNIEnv *env, jobject object, jint width, jint height, jintArray frame) {
    
        jint *pFrameData = env->GetIntArrayElements(frame, 0);
        // it is the line:
        Mat mFrame = Mat(height,width,CV_8UC4,pFrameData).clone();
        // your code..
        env->ReleaseIntArrayElements(frame, pFrameData, 0);
    
    }
    

提交回复
热议问题