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)}

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

点击按钮,Imgproc.cvtColor(src, temp , Imgproc.COLOR_RGBA2BGR) 执行结果如下:

更多相关文章

  1. Android应用之基本的组件(一)
  2. android实现分享
  3. Android仿硅谷商城实现购物车实例代码
  4. android滑动按钮事件
  5. Android(安卓)/ Java ------ Sha1 and Md5
  6. Android(安卓)动态获取权限(6.0 , 7.0)
  7. Android(安卓)Device Monitor结构和用法
  8. android PickerView自定义实现
  9. java算法之去重查找重复元素

随机推荐

  1. Android 默认Tab标签大小及间距修改
  2. View 的绘制流程
  3. Android群英传第五章Scroll分析读书笔记
  4. Android多渠道打包,Android签名包,Android
  5. Android NDK学习之 一. Android NDK简介
  6. android_USB_Host API
  7. app launcher 名称不是清单文件中的andro
  8. 认识Android中的双向绑定
  9. Android AIDL机制范例解析
  10. Android 属性动画原理与DataBinding