1 新建一个空项目
不再多说
2从官网下载opencv
下载opencv-4.9.0-android-sdk
3 导入模块
点击file->new->Import Module选择解压之后的opencv-android-sdk文件夹中的SDk文件夹,并将:sdk修改为:opencv(我的已安装)



等一会进行加载,会出现报错,找到build.gradle(opencv),注释掉apply plugin: ‘kotlin-android’

再build就能通过
4 导入依赖
点击file->project structure ->Dependencies->app->3 Module Dependency,然后给opencv打上对勾,应用即可



5 代码中连接opencv4
使用时候要先进行连接,不然不会在代码里报错,但是会闪退。
//连接opencv @Override protected void onResume() { super.onResume(); if (!OpenCVLoader.initDebug()){ Log.i("cv","未找到内部的opencv库,使用OpenCV Manager进行初始化"); }else { Log.i("cv","发现了内置的opencv库,使用它来进行操作"); } }