OpenCV-Android平台应用实战 - 银行卡卡号识别(03、算法流程与界面设计)

版权声明:本文由 Micheal 超 博客 创作,未经博主允许不得转载。 https://blog.csdn.net/qq_42887760/article/details/86701395

算法流程

在这里插入图片描述

界面设计

1.UI界面一:

  • 两个Button元素+一个TextView元素
    在这里插入图片描述
  • XML界面设计
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    tools:context="com.example.opencvtest.MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="拍照"
        android:id="@+id/take_picture_btn"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/take_picture_btn"
        android:text="选择照片"
        android:id="@+id/select_picture_btn"
        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Micheal 超 - 卡号识别演示"/>


</RelativeLayout>

  • java代码
package com.example.opencvtest;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    Button btn_take_picture,btn_select_picture;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn_take_picture = (Button) this.findViewById(R.id.take_picture_btn);
        btn_select_picture = (Button) this.findViewById(R.id.select_picture_btn);
        btn_take_picture.setOnClickListener(this);
        btn_select_picture.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent(this.getApplication(),CardOCRActivity.class);
        switch (v.getId()){
            case R.id.take_picture_btn:
                Toast.makeText(this, "Take Picture ...", Toast.LENGTH_SHORT).show();
                startActivity(intent);
                break;
            case R.id.select_picture_btn:
                Toast.makeText(this, "Select Picture ...", Toast.LENGTH_SHORT).show();
                startActivity(intent);
                break;
            default:
                break;
        }
    }
}

2.UI界面二:(创建一个新的Activity)

  • 一个Button元素+TextView元素+ImageView元素
    在这里插入图片描述
  • XML界面设计
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.opencvtest.CardOCRActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="识别"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:id="@+id/recognition_btn"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="20dp"
        android:layout_toRightOf="@+id/recognition_btn"
        android:text="结果:空"
        android:id="@+id/textView" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/recognition_btn"
        android:layout_marginTop="10dp"
        android:scaleType="fitCenter"
        android:src="@drawable/idcard" />

</RelativeLayout>

  • Java代码(暂时无需编写)

运行图:(界面图见上)

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

相册所用图片(下图)来自百度图片,若有侵权,请联系删除
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_42887760/article/details/86701395