ocr中身份证识别回填表单

一.查看官网中身份证识别的技术文档

https://ai.baidu.com/ai-doc/OCR/rk3h7xzckicon-default.png?t=N6B9https://ai.baidu.com/ai-doc/OCR/rk3h7xzck

二.申请client_id和client_secret的编号,以便下面的使用

1.打开ocr官方文档,登录进入,在页面中选择文档以及文档里面的文字识别

 

 2.创建应用,即可得到client_id和client_secret

填写完点击“立即创建”即可获得

 3.查看创建完的应用,其中可以更改client_id和client_secret

更改操作:点击“操作”的“管理”,在弹出的页面中点击“更新Secret Key”即可

 4.领取免费使用ocr识别

 三.代码的实现

 效果图:

 1.html

	<view class="realName">
		<view class="realNameTop">
			<view class="realNameTopBox">
				<view class="realNameTopTitle">
					姓名
				</view>
				<view class="realNameTopContent">
					<u-input v-model="name" type="text" placeholder="请扫描录入姓名" :placeholder-style="placeholderStyle" />
				</view>
			</view>
			<view class="realNameTopBox">
				<view class="realNameTopTitle">
					身份证号码
				</view>
				<view class="realNameTopContent">
					<u-input v-model="idCard" type="text" placeholder="请扫描录入身份证号" :placeholder-style="placeholderStyle" />
				</view>
			</view>
			<view class="realNameTopBox">
				<view class="realNameTopTitle">
					身份证地址
				</view>
				<view class="realNameTopContent">
					<u-input v-model="idAddress" type="text" placeholder="请扫描录入身份证地址" :placeholder-style="placeholderStyle" />
				</view>
			</view>
			<view class="realNameTopBox">
				<view class="realNameTopTitle">
					行政区域
				</view>
				<view class="realNameTopContent">
					<!-- <uni-section> -->
					<uni-data-picker placeholder="请选择所在行政区域" popup-title="请选择所在地区" :localdata="dataTree" v-model="classes"
						@change="onchange" @nodeclick="onnodeclick" @popupopened="onpopupopened" @popupclosed="onpopupclosed">
					</uni-data-picker>
				</view>
			</view>
		</view>
		<view class="realNameBottom">
			<view class="realIdFront" @click="frontClick()">
				<!-- <img class="realIdImg" :src="imgbaseUrl + src1" alt=""> -->
				<img class="realIdImg" :src="src1" alt="">
			</view>
			<view class="realIdFront" style="margin-top: 10px;" @click="oppositeClick()">
				<img class="realIdImg" :src="src2" alt="">
			</view>
			<view class="realIdBtn" @click="uploadClick()">
				下一步
			</view>
		</view>
	</view>
</template>

2.script

<script>
	import {
		pathToBase64,
		base64ToPath
	} from 'image-tools'
	export default {
		data() {
			return {
				name: '',
				idCard: '',
				idAddress: '',
				value: '',
				zmsrc: '',
				fmsrc: '',
				placeholderStyle: "color:#7d7d7d;font-size:12px",
				show: false,
				classes: '1-3',
				dataTree: [],

				// ocr
				dataObj: {
					client_id: '此处需自己申请',
					client_secret: '此处需自己申请',
				},
				baseImageList: '',
				baseImageList1: '',
				src1: require("static/index/身份证正面.png"),
				src2: require("static/index/身份证反面.png"),
				imgbaseUrl: '此处为上传图片的接口',
			}
		},
		props: {
			dataType: {
				type: String,
				default: 'idcard',
			}
		},
		onLoad() {
			this.getSumuInfo()
			this.getGachaInfo()
		},
		methods: {
			onnodeclick(e) {
				console.log(e, '1');
			},
			onpopupopened(e) {
				console.log('popupopened');
			},
			onpopupclosed(e) {
				console.log('popupclosed');
			},
			onchange(e) {
				console.log('onchange:', e);
				console.log(e.detail.value, '666');
			},
			// 跳转到上传手持身份证和签字照片页
			uploadClick() {
				uni.navigateTo({
					url: `/pages/index/uploadIdAndText?name=${this.name}&idCard=${this.idCard}&idAddress=${this.idAddress}&value=${this.value}&zmsrc=${this.zmsrc}&fmsrc=${this.fmsrc}`
				})
			},
			// 身份证正面照片
			frontClick() {
				if (this.src1 == require("static/index/身份证正面.png")) {
					let self = this
					uni.chooseImage({
						count: 1,
						success: (ress) => {
							uni.showLoading({
								title: '正在识别中...'
							})
							console.log(ress.tempFiles[0].name, '上传的图片');
							uni.uploadFile({
								url: this.imgbaseUrl + "sys/common/upload",
								filePath: ress.tempFilePaths[0],
								name: 'file',
								formData: {
									'user': 'test' // 上传附带参数
								},
								success: (uploadFileRes) => {
									// 根据接口具体返回格式   赋值具体对应url
									console.log(uploadFileRes.data, '555');
									var obj = JSON.parse(uploadFileRes.data)
									this.zmsrc = obj.message
								}
							})
							pathToBase64(ress.tempFilePaths[0])
								.then((res) => {
									console.log(res, 'zhe');
									self.baseImageList = self.baseImageList.concat(
										res); //成功后利用concat方法追加到baseImageList中
									console.log(self.baseImageList, '打印的base64图片');
									this.src1 = self.baseImageList
									console.log(ress, '11111');
									self.getAccessToken(res, ress)
									// uni.$emit("src1", this.src1)
								})
								.catch(error => {
									console.error(error)
								})
						},
						fail(err) {
							uni.hideLoading()
							console.log(err)
						}
					});
				}
			},
			// 身份证反面照片
			oppositeClick() {
				if (this.src2 == require("static/index/身份证反面.png")) {
					let self = this
					uni.chooseImage({
						count: 1,
						success: (ress) => {
							uni.showLoading({
								title: '正在识别中...'
							})
							uni.uploadFile({
								url: this.imgbaseUrl + "sys/common/upload",
								filePath: ress.tempFilePaths[0],
								name: 'file',
								formData: {
									'user': 'test' // 上传附带参数
								},
								success: (uploadFileRes) => {
									// 根据接口具体返回格式   赋值具体对应url
									console.log(uploadFileRes.data, '555');
									var obj = JSON.parse(uploadFileRes.data)
									this.fmsrc = obj.message
								}
							})
							pathToBase64(ress.tempFilePaths[0])
								.then((res) => {
									self.baseImageList1 = self.baseImageList1.concat(
										res); //成功后利用concat方法追加到baseImageList中
									console.log(self.baseImageList1, '打印的base64图片');
									this.src2 = self.baseImageList1
									self.getAccessToken(res, ress)
									uni.$emit("src2", this.src2)
								})
								.catch(error => {
									console.error(error)
								})
						},
						fail(err) {
							uni.hideLoading()
							console.log(err)
						}
					});
				}
			},
			getAccessToken(path, ress) {
				let self = this
				uni.request({
					// url: '/baseUrlTest/oauth/2.0/token?grant_type=client_credentials&client_id=此处需自己申请&client_secret=此处需自己申请',
					// url: 'https://aip.baidubce.com/oauth/2.0/token',
					url: '/baseUrlTest/oauth/2.0/token',
					data: {
						grant_type: 'client_credentials',
						client_id: self.dataObj.client_id,
						client_secret: self.dataObj.client_secret
					},
					method: 'POST',
					header: {
						'Content-Type': 'application/x-www-form-urlencoded',
					},
					success: (res) => {
						if (self.dataType == 'idcard') {
							self.uploadImage(path, res.data.access_token, ress)
						} else {
							self.uploadlicense(path, res.data.access_token, ress)
						}
						uni.hideLoading()
					},
					fail(err) {
						uni.hideLoading()
						console.log(err, '错误提示')
					}
				})
				console.log(self, '打印11');
			},
			// 身份证识别
			uploadImage(path, token, ress) {
				let self = this
				uni.request({
					url: '/baseUrlTest/rest/2.0/ocr/v1/idcard',
					data: {
						image: path,
						access_token: token,
						// front:身份证含照片的一面;back带国徽的一面
						id_card_side: 'back'
					},
					method: 'POST',
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					success: (res) => {
						console.log(res, '识别成功之后')
						uni.hideLoading()
						self.$emit('end', {
							path: ress,
							animal: false,
							words: res.data
						})
						console.log(res, '识别的信息');
						this.name = res.data.words_result.姓名.words
						this.idCard = res.data.words_result.公民身份号码.words
						this.idAddress = res.data.words_result.住址.words
					},
					fail(err) {
						uni.hideLoading()
						console.log(err)
					}
				})
			},
		}
	}
</script>

3.style

<style scoped>
	.realNameTopBox {
		display: flex;
		align-items: center;
		padding: 5px 10px;
		background-color: #fff;
		color: #2c2c2c;
		border-bottom: 1px solid #ededed;
		font-size: 12px;
		width: 100%;
		/* border: 1px solid blue; */
	}

	.realNameTopTitle {
		width: 20%;
		/* border: 1px solid yellow; */
	}

	/deep/ uni-view.realNameTopContent {
		/* border: 1px solid red; */
		/* width: 280px !important; */
		margin-left: 5%;
		width: 75%;
	}

	.realNameBottom {
		background-color: #fff;
		padding: 10px 0;
	}

	.realIdFront {
		width: 95%;
		height: 200px;
		margin: 0 auto;
		display: flex;
		align-items: center;
		justify-content: center;
		border: 1px solid #cdcdcd;
	}

	.realIdImg {
		width: 99%;
		height: 98%;
	}

	.realIdBtn {
		width: 95%;
		margin: 20px auto;
		background-color: #fccf36;
		line-height: 40px;
		text-align: center;
		color: #626262;
		border-radius: 3px;
		box-shadow: 0 2px 2px #cdcdcd;
	}
</style>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
简介:class IdcardAction extends Action{   function get_xingzuo($cid) {      if (!$this->isIdCard($cid)) return ';     $bir = substr($cid,10,4);     $month = (int)substr($bir,0,2);     $day = (int)substr($bir,2);     $strValue = ';     if (($month == 1 && $day >= 20) || ($month == 2 && $day <= 18)) {       $strValue = "水瓶座";     } else if (($month == 2 && $day >= 19) || ($month == 3 && $day <= 20)) {       $strValue = "双鱼座";     } else if (($month == 3 && $day > 20) || ($month == 4 && $day <= 19)) {       $strValue = "白羊座";     } else if (($month == 4 && $day >= 20) || ($month == 5 && $day <= 20)) {       $strValue = "金牛座";     } else if (($month == 5 && $day >= 21) || ($month == 6 && $day <= 21)) {       $strValue = "双子座";     } else if (($month == 6 && $day > 21) || ($month == 7 && $day <= 22)) {       $strValue = "巨蟹座";     } else if (($month == 7 && $day > 22) || ($month == 8 && $day <= 22)) {       $strValue = "狮子座";     } else if (($month == 8 && $day >= 23) || ($month == 9 && $day <= 22)) {       $strValue = "处女座";     } else if (($month == 9 && $day >= 23) || ($month == 10 && $day <= 23)) {       $strValue = "天秤座";     } else if (($month == 10 && $day > 23) || ($month == 11 && $day <= 22)) {       $strValue = "天蝎座";     } else if (($month == 11 && $day > 22) || ($month == 12 && $day <= 21)) {       $strValue = "射手座";     } else if (($month == 12 && $day > 21) || ($month == 1 && $day <= 19)) {       $strValue = "魔羯座";     }     return $strValue;   } PHP根据身份证号,自动获取对应的星座函数,然后自动返回对应的星座,自动返回性别,判断是否成年
OCR身份证识别模块是一种基于光学字符识别技术的自动识别身份证信息的工具。它可以将身份证上的文字、号码等信息转化为计算机可识别的数据,以方便后续的数据处理和应用。 OCR身份证识别模块通常由图像预处理、文字区域检测、文字分割和文字识别等步骤组成。首先,该模块会对输入的身份证图像进行预处理,包括灰度化、二值化、降噪等操作,以提高后续处理步骤的准确性。然后,模块会使用特定的算法和技术来检测身份证的文字区域,识别出身份证上的文字位置和边界框。接下来,模块会将文字区域进行分割,将每个字符单独提取出来,以便进行后续的识别。最后,识别模块会使用OCR技术,通过训练好的模型和算法,将每个字符转化为计算机可读的文字数据。 OCR身份证识别模块可以广泛应用于各种需要自动化、高效率身份证信息识别的场景。比如,银行、机场、酒店等需要进行身份验证的场所,可以使用OCR身份证识别模块快速读取身份证信息,提高操作效率和准确性。同时,该技术也可以应用在人工智能、大数据等领域,用于身份证信息的统计分析和应用开发。 然而,OCR身份证识别模块也存在一定的局限性。例如,图像质量差、身份证文字模糊、字体特殊等情况都可能影响识别的准确性。因此,在实际应用,我们还需要根据具体需求进行优化和改进,以提高识别效果和用户体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值