在Android 上运行 openCV ,并做灰度变化的一个例子
在Android 上运行 openCV ,并做灰度变化的一个例子
OpenCVImageProcessing
- 导入Opencv的 androrid SDK
灰度算法 OpenCVImageProcessing
导入opencv Jar包,配置OpenCVLibrary340 的 bulid.gradle , 配置Module:app 的 build.gradle , 在依赖里添加
implementation fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
1
在Gradle Scripts 里修改 dependencies
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs') implementation fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar') implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation project(':openCVLibrary340')
}
task nativeLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
destinationDir file("$buildDir/native-libs") baseName 'native-libs' from fileTree(dir: 'libs', include: '**/*.so') into 'lib/'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
-
灰度算法
@Override
public void onClick(View v) {convert2Gray();
}
private void convert2Gray() {
Mat src = new Mat(); Mat temp = new Mat(); Mat dst = new Mat(); Bitmap image = BitmapFactory.decodeResource(this.getResources(),R.drawable.tantuo); Utils.bitmapToMat(image,src); Imgproc.cvtColor(src, temp , Imgproc.COLOR_RGBA2BGR); Log.i( "CV", "image type:" + (temp.type() == CvType.CV_8UC3)); Imgproc.cvtColor(temp, dst, Imgproc.COLOR_BGR2GRAY); Utils.matToBitmap(dst,image); ImageView imageView = (ImageView) findViewById(R.id.imageView); imageView.setImageBitmap(image);
点击按钮,Imgproc.cvtColor(src, temp , Imgproc.COLOR_RGBA2BGR)
作者:谭妥
来源:CSDN
原文:https://blog.csdn.net/weixin_37734988/article/details/90411605
版权声明:本文为博主原创文章,转载请附上博文链接!
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Android主题更换换肤
Android主题更换换肤文章目录知识总览认识setFactory获取任意一个apk压缩文件的Resource对象1、如何创建自定义的Resource实例2、如何知道当前属性值在所在Resource中的id参考文章知识总览android主题换肤通常借助LayoutInflater#setFactory实现换肤。 换肤步骤: 通过解析外部的apk压缩文件,创建自定义的Resource对象去访问apk压缩文件的资源。借助LayoutInfater#setFactoy,将步骤(1)中的资源应用到View的创建过程当中。认识setFactory平常设置或者获取一个View时,用的较多的是setContentView或LayoutInflater#inflate,setContentView内部也是通过调用LayoutInflater#inflate实现(具体调用在AppCompatViewInflater#setContentView(ind resId)中)。 通过LayoutInflater#inflate可以将xml布局文件解析为所需要的View,通过分析LayoutInflate#in...
- 下一篇
android 文件读写
android 文件读写读取: public static String _getJsonString(String fileName) throws IOException { if ((fileName == null) || fileName.isEmpty()) { return ""; } String retString = ""; FileInputStream fis = null; String state = Environment.getExternalStorageState(); if (state.equals(Environment.MEDIA_MOUNTED)) { File file = new File(Environment.getExternalStorageDirectory() + "/" + fileName + ".json"); if (file.exists()) { fis = new FileInputStream(file); byte[] buffer = new byte[fis.available()]; fis.read...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Eclipse初始化配置,告别卡顿、闪退、编译时间过长
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- SpringBoot2整合Redis,开启缓存,提高访问速度
- CentOS8编译安装MySQL8.0.19
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Docker安装Oracle12C,快速搭建Oracle学习环境
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Windows10,CentOS7,CentOS8安装Nodejs环境