zoukankan      html  css  js  c++  java
  • 在Android 上运行 openCV ,并做灰度变化的一个例子

    OpenCVImageProcessing
    1. 导入Opencv的 androrid SDK
    灰度算法 OpenCVImageProcessing

    导入opencv Jar包,配置OpenCVLibrary340 的 bulid.gradle , 配置Module:app 的 build.gradle , 在依赖里添加 implementation fileTree(dir: “$buildDir/native-libs”, include: ‘native-libs.jar’)

    在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)
    }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22


    2. 灰度算法

    @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);

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    点击按钮,Imgproc.cvtColor(src, temp , Imgproc.COLOR_RGBA2BGR) 执行结果如下:
    (现在总是加班坐着胖得厉害,两年前的时候经常帅得睡不着觉的)

    https://img-blog.csdnimg.cn/2019052117390814.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zNzczNDk4OA==,size_16,color_FFFFFF,t_70

    https://img-blog.csdnimg.cn/20190521173707608.jpeg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zNzczNDk4OA==,size_16,color_FFFFFF,t_70
    --------------------- 

  • 相关阅读:
    C/C++字符串函数之复制函数
    tesseract api C++使用例子
    error C2275: “XXX”: 将此类型用作表达式非法
    Socket通信原理探讨(C++为例)
    模拟按键,点击,滑动,在光标处输出字符
    安卓使用Root权限实现后台模拟全局按键、触屏事件方法(类似按键精灵)
    【 转】__try,__except,__finally,__leave异常模型机制
    提高VS2010运行速度的技巧
    解决VS2010子目录中的.cpp文件引用上一级目录的stdafx.h找不到定义的问题
    1009MySQL数据库InnoDB存储引擎Log漫游
  • 原文地址:https://www.cnblogs.com/ly570/p/10970814.html
Copyright © 2011-2022 走看看