当前位置: 首页 > wzjs >正文

郑州移动端网站建设企业培训内容包括哪些内容

郑州移动端网站建设,企业培训内容包括哪些内容,北京响应式网站建设公司,云南网页Google ML Kit 是一个现代、功能强大、跨平台的机器学习 SDK。在这篇文章中,我们将使用 ML Kit 在 Android 应用中识别图片文字,以提取美国驾照上的关键信息:DL(驾照号) 和 EXP(有效日期)。 &am…

Google ML Kit 是一个现代、功能强大、跨平台的机器学习 SDK。在这篇文章中,我们将使用 ML Kit 在 Android 应用中识别图片文字,以提取美国驾照上的关键信息:DL(驾照号) 和 EXP(有效日期)


🛠️ 步骤一:项目配置

1. 添加依赖

打开 app/build.gradle,添加以下 ML Kit 的文字识别依赖:

dependencies { implementation 'com.google.mlkit:text-recognition:16.0.0' }

2. 添加权限(可选)

如果你需要从相册或相机中读取图片,还需要添加读取权限:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

🧾 示例功能说明

我们将:

  • 加载一张美国驾照图片(假设叫 license.jpg

  • 使用 ML Kit 提取图片上的文字

  • 使用正则表达式提取出驾驶证号(DL ABC1234567)和出生日期(DOB 05/01/1990


📄 布局文件:activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/main"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello World!"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent" /><ImageViewandroid:id="@+id/imageView"android:layout_width="303dp"android:layout_height="189dp"android:layout_marginStart="54dp"android:layout_marginTop="62dp"android:layout_marginEnd="54dp"android:layout_marginBottom="105dp"app:layout_constraintBottom_toTopOf="@+id/textView"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toTopOf="parent"tools:src="@tools:sample/backgrounds/scenic" /><Buttonandroid:id="@+id/button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginStart="165dp"android:layout_marginTop="264dp"android:layout_marginEnd="156dp"android:layout_marginBottom="43dp"android:text="Loading"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintStart_toStartOf="parent"app:layout_constraintTop_toBottomOf="@+id/textView" /></androidx.constraintlayout.widget.ConstraintLayout>


🔧 主逻辑:MainActivity.kt

package com.example.mlimport android.graphics.BitmapFactory
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.google.mlkit.vision.common.InputImage
import com.google.mlkit.vision.text.TextRecognition
import java.io.InputStream
import com.google.mlkit.vision.text.latin.TextRecognizerOptionsclass MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)val imageView = findViewById<ImageView>(R.id.imageView)val button = findViewById<Button>(R.id.button)// 加载图片(assets 文件夹中的 jiazhao.webp)val inputStream: InputStream = assets.open("license.jpg")val bitmap = BitmapFactory.decodeStream(inputStream)imageView.setImageBitmap(bitmap)button.setOnClickListener {extractTextFromBitmap(bitmap)}}private fun extractTextFromBitmap(bitmap: android.graphics.Bitmap) {val image = InputImage.fromBitmap(bitmap, 0)val textView = findViewById<TextView>(R.id.textView)val recognizer = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS)recognizer.process(image).addOnSuccessListener { visionText ->val fullText = visionText.text// 提取 DOB 和 DLval expRegex = Regex("""EXP\s+\d{2}/\d{2}/\d{4}""")val dlRegex = Regex("""DL\s+[A-Z0-9]+""")val exp = expRegex.find(fullText)?.value ?: "未识别到有效日期"val dl = dlRegex.find(fullText)?.value ?: "未识别到驾驶证号"textView.text =  "有效日期: $exp" + "\n" + "驾驶证号: $dl"}.addOnFailureListener { e ->textView.text = "识别失败:${e.message}"}}
}

🧪 测试效果

确保你将美国驾照样本命名为 license.jpg 并放入 res/drawable/ 目录。点击按钮后,在日志中可以看到类似如下输出:

有效日期: EXP 08/31/2026
驾驶证号: DL I1234568

http://www.dtcms.com/wzjs/57385.html

相关文章:

  • 2017做那个网站能致富营销推广投放平台
  • 单页面网站模板怎么做seo网站推广软件
  • 做房产网站需要了解什么seo用什么论坛引流
  • 江西省建设监理网站小说网站排名
  • 一个虚拟主机绑定2个网站软文营销的案例
  • php 深圳 电子商务网站开发baike seotl
  • 做网站 新域名 还是卖网站链接
  • 网站建设 网站优化win7优化大师好不好
  • 宁夏住房和建设厅官方网站seo分析报告怎么写
  • z-blog和wordpress网站排名优化软件哪家好
  • 外贸推广免费网站拉新项目官方一手平台
  • 郑州快速网站建设冯耀宗seo
  • 福州企业网站建设seo秘籍优化课程
  • 网站改版方案原则网络销售的工作内容
  • 龙岗区网站建设公司抖音seo搜索引擎优化
  • 公司做网站要注意什么企业网站搭建
  • 做网站登录页面的论文公司的公关
  • 网站建设调查分析百度2020新版下载
  • 扁平化 网站联合早报 即时消息
  • 政府 网站建设 投标百度seo搜索
  • 广东汕头最新传染疫情seo一个月工资一般多少
  • 网站推广服务怎么做安徽seo推广公司
  • 小程序开发需要什么技术aso安卓优化公司
  • 网站建设颜色注意事项郑州seo代理商
  • 学做衣服网站优化方法
  • 企业管理系统官网江苏搜索引擎优化公司
  • 专门做软陶的网站新疆今日头条新闻
  • 在线购物网站建设seo根据什么具体优化
  • 做网站什么数据库用的多成都网站快速开发
  • 网站源码交易网关键词推广优化排名品牌