AndroidStudio使用opencv

AndroidStudio使用opencv

1.AndroidStudio 导入OpenCV
2.验证(灰度转化)
3.训练库

一.AndroidStudio 导入OpenCV

环境:Android Studio 3.5.2,opencv-3.4.10-android-sdk

1. 下载opencv包

下载链接:OpenCV。选择Android下载。然后解压。

2. 导入opencv

第一步

新建一个android application 项目

第二步

选择File—>New—>Import Module
然后路径选择解压目录—>opencv-3.4.10-android-sdk—>OpenCV-android-sdk—>sdk—>java
在这里插入图片描述

第三步

修改OpenCVLibrary3410的build.gradle,使其和项目的build.gradle对应项一致。可以在工程目录下找到OpenCVLibrary3410的build.gradle文件。重新clean一下项目。

在这里插入图片描述
在这里插入图片描述

第四步

点击File-Project Structure会出现下图:左边菜单点击Dependencies,然后Modules下边找你新建的android项目。点击Declared Dependencies下面的+ 号,选择Module dependcy,选择openCVLibrary3410,导入。
在这里插入图片描述

第五步

把OpenCV-android-sdk\sdk\native下的libs文件夹拷贝到你的安卓项目下,即自己的项目\src\main下面,并且将libs改名为:jniLibs。

第六步

将OpenCV-android-sdk\samples\image-manipulations\res\layout下的xml文件拷贝到自己的项目\src\main\res下面

第七步

将OpenCV-android-sdk\samples\image-manipulations\src\org\opencv\samples\imagemanipulations下的java文件拷到自己的项目\src\main\java\你MainActivity所在的包名,即和MainActivity同级目录

至此,我的项目目录如下所示:
在这里插入图片描述

二.验证(灰度转化)

layout文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    tools:context="edu.finu.cse.opencv2.MainActivity">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="原图"
                android:id="@+id/textView" />

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/imageView_before"
                android:src="@drawable/duling"
                android:sc
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值