Convert Android Bitmap to OpenCV Mat and backwards

后端 未结 2 1302
庸人自扰
庸人自扰 2021-02-05 22:50

I wanted to simply convert a bitmap from Android to a Mat object for OpenCV. This topic is often adressed on Stack Overflow. For example:

convert Mat to Bitmap Opencv fo

2条回答
  •  悲&欢浪女
    2021-02-05 23:07

    You only can do your work with OpenCV after it is initialized. So you need to initialize it like that:

    1.Create a Callback:

    private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
            case LoaderCallbackInterface.SUCCESS:
                //DO YOUR WORK/STUFF HERE 
                break;
            default:
                super.onManagerConnected(status);
                break;
            }
        }
    };
    

    2.You need to initialize the callback in the onResume Method of your Activity:

    @Override
        protected void onResume() {
            super.onResume();
            OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_8, this,
                    mOpenCVCallBack);
        }
    

    and thats it, i hope it was helpful :D

提交回复
热议问题