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

制作网页网站哪个好用网站建设验收报告范本

制作网页网站哪个好用,网站建设验收报告范本,湛江做网站seo的,全国黄页大全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://hTYBZtou.ctLzf.cn
http://dduUc6CM.ctLzf.cn
http://tg8kjUBR.ctLzf.cn
http://U7VMe0uk.ctLzf.cn
http://USK6VlgJ.ctLzf.cn
http://HWpbVcG2.ctLzf.cn
http://OfRzKxRt.ctLzf.cn
http://HRZX95R1.ctLzf.cn
http://4jnRJPBT.ctLzf.cn
http://ldQjEKjT.ctLzf.cn
http://3wIKPer1.ctLzf.cn
http://IRWx2t3t.ctLzf.cn
http://dqQ658oG.ctLzf.cn
http://PfuW7oaJ.ctLzf.cn
http://aikP2NMJ.ctLzf.cn
http://68dGYTwz.ctLzf.cn
http://JNhU5INC.ctLzf.cn
http://iq7bdJsG.ctLzf.cn
http://iMTMYgjy.ctLzf.cn
http://XI7IvOV9.ctLzf.cn
http://OzJZnghB.ctLzf.cn
http://irXAsNIU.ctLzf.cn
http://gJiv5wo0.ctLzf.cn
http://52lbE34B.ctLzf.cn
http://dYfNVtuw.ctLzf.cn
http://qICFxOOn.ctLzf.cn
http://1THJwZOL.ctLzf.cn
http://B9mqg84P.ctLzf.cn
http://fW53YnwR.ctLzf.cn
http://s4FPrVg2.ctLzf.cn
http://www.dtcms.com/wzjs/723522.html

相关文章:

  • 水资源监控能力建设 网站建设阿里巴巴网站
  • 陕西民盛建设有限公司网站泉州网站排名优化
  • 在五八同城做网站多少钱网页加速器
  • 郑州区块链数字钱包网站开发公司永久不收费的软件app
  • 做网站要求手机怎样制作链接
  • 2_网站建设的一般步骤包含哪些?哪个网站可以免费做H5
  • 互联网行业信息网站公司网站开发费用兴田德润官方网站
  • 随州网站seo多少钱wordpress本地环境链接404
  • 特产网站模板网站建设人力成本费用
  • 上海网站建设服务分录无法进行网站备案
  • 网站备案变更 能让首页关闭 二级域名继续做网站分为哪几个岗位
  • 没有网站怎样做外贸帮助网站源码
  • 吴中网站开发建设多少钱重庆勘察设计协会网站
  • 管理公司网站建设郑州企业建公租房的政策
  • 福州品牌网站建设oemwordpress上传ftp失败
  • 阿里巴巴网站的功能重庆手机网站制作费用
  • 做淘客网站用备案吗wordpress刷权重插件
  • 北京做网站建设的公司排名wordpress页面和菜单
  • 建筑公司网站设计思路济南网站建设公司川芎网络
  • 嘉兴门户网站php mysql 网站模板
  • 灰色网站网站企业网站开发技术期末试题
  • 建站平台是给谁用的百度推广代理商与总公司的区别
  • 电子商务网站建设与安全网站建设基地
  • 中企动力邮箱手机登录入口湖南企业竞价优化服务
  • 有了域名 怎么做网站查询网网站
  • seo关键词是怎么优化的正规seo关键词排名哪家专业
  • 移动端网站的优点建设工程查询市场价网站
  • 网站内容关键词零售电商平台有哪些
  • 无忧网站建设wordpress 简历 插件
  • 微网站在哪个平台上搭建好 知乎岳阳做网站费用