您现在的位置是:首页 > 文章详情

在Android 上运行 openCV ,并做灰度变化的一个例子

日期:2019-07-09点击:395

在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')
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)

}

  1. 灰度算法

    @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
版权声明:本文为博主原创文章,转载请附上博文链接!

原文链接:https://yq.aliyun.com/articles/708439
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章