Convert Android Bitmap to OpenCV Mat and backwards

后端 未结 2 1306
庸人自扰
庸人自扰 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

    0 讨论(0)
  • 2021-02-05 23:14

    you should add OpenCV lib dependecy to your android prj config(properties->Android->Library ->add [opencv andrid prg])

    0 讨论(0)
提交回复
热议问题