Browse Source

修改车牌识别方式为腾讯ocr

tianhui 3 years ago
parent
commit
4102d4649f

+ 4 - 1
common/apiurl.js

@@ -71,7 +71,10 @@ const apiurl = {
 	
 	lockControl: '/payee/hardware/lock/control',
 	
-	lockList: '/payee/roadinfo/lockList/'
+	lockList: '/payee/roadinfo/lockList/',
+	
+	//车牌识别
+	tencentOcrUrl:'/tencent/ocr'
 }
 
 export {

+ 2 - 2
common/config.js

@@ -1,5 +1,5 @@
-// const host = 'https://wx.hw.hongweisoft.com/parking';//本地
-const host = 'https://parking.pdzhtc.com';//正式
+const host = 'https://wx.hw.hongweisoft.com/parking';//本地
+// const host = 'https://parking.pdzhtc.com';//正式
 // const host = 'http://172.16.90.64:7000';
 const config = {
 	wxAppid:'wxbe90cc7c5233dd84',// wxAppid 

+ 5 - 2
common/http.api.js

@@ -59,7 +59,9 @@ const install = (Vue, vm) => {
 	
 	let lockList = (params = {}) => vm.$u.get(apiurl.lockList + params.roadNo);
 	
-	let bindRoads = (params = {}) => vm.$u.post(apiurl.bindRoadsUrl,params);
+	let bindRoads = (params = {}) => vm.$u.post(apiurl.bindRoadsUrl, params);
+	
+	let tencentOcr = (params = {}) => vm.$u.post(apiurl.tencentOcrUrl, params);
 	
 	// 将各个定义的接口名称,统一放进对象挂载到vm.$u.api(因为vm就是this,也即this.$u.api)下
 	vm.$u.api = {
@@ -92,7 +94,8 @@ const install = (Vue, vm) => {
 		lockControl,
 		lockList,
 		bindRoads,
-		cashPay
+		cashPay,
+		tencentOcr
 	};
 }
 

+ 53 - 52
pages/getcarno/getcarno.vue

@@ -35,61 +35,62 @@
 		},
 		methods:{
 			getPic(){
-				let that = this;
-				ocr.ocrVehicleNo((ret) => {
-					if (ret.success){
-						that.confirmData.vehicleNo = ret.vehicleNo;
-						//that.vehicleImage =  'data:image/png;base64,' + ret.imageBase64;
-						// speak('成功识别车牌' + ret.vehicleNo);
-					}else {
-						plus.nativeUI.toast('识别失败');
-					}
-				});
 				// let that = this;
-				// uni.chooseImage({
-				// 	count: 1, //默认9
-				// 	sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
-				// 	sourceType: ['camera'], //
-				// 	success: function (res) {
-				// 		// console.log('img',res)
-				// 		uni.showLoading({});
-				// 		const tempFilePaths = res.tempFilePaths;
-				// 		// 若多选,需循环调用uni.uploadFile ,因微信小程序只支持单文件上传
-				// 		uni.uploadFile({
-				// 			url: `${that.config.fileUrl}/baidu/ocr`,
-				// 			filePath: tempFilePaths[0],
-				// 			name: 'file',
-				// 			formData: {
-				// 				'test': 'test'  // 上传附带参数
-				// 			},
-				// 			success: (res) => {
-				// 				// 根据接口具体返回格式   赋值具体对应url
-				// 				// alert(uploadFileRes.data);
-				// 				let resobj=eval("("+res.data+")");
-				// 				uni.hideLoading();
-				// 				if(resobj.code==200){
-				// 					console.log(resobj);
-				// 					that.newPlateNumber = resobj.data.vehicleNo;
-				// 					that.vehicleClor = resobj.data.vehicleClor;
-				// 				}else{
-				// 					that.$refs.uToast.show({
-				// 						title: resobj.msg,
-				// 						type: 'error'
-				// 					});
-				// 				}
-								
-				// 				console.log(res);
-				// 			},
-				// 			fail: (err) => {
-				// 				that.$refs.uToast.show({
-				// 					title:err.msg,
-				// 					type: 'error'
-				// 				});
-				// 				uni.hideLoading();
-				// 			}
-				// 		});
+				// ocr.ocrVehicleNo((ret) => {
+				// 	if (ret.success){
+				// 		that.confirmData.vehicleNo = ret.vehicleNo;
+				// 		//that.vehicleImage =  'data:image/png;base64,' + ret.imageBase64;
+				// 		// speak('成功识别车牌' + ret.vehicleNo);
+				// 	}else {
+				// 		plus.nativeUI.toast('识别失败');
 				// 	}
 				// });
+				
+				let that = this;
+				uni.chooseImage({
+					count: 1, //默认9
+					sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
+					sourceType: ['camera'], //
+					success: function (res) {
+						// console.log('img',res)
+						uni.showLoading({});
+						const tempFilePaths = res.tempFilePaths;
+						// 若多选,需循环调用uni.uploadFile ,因微信小程序只支持单文件上传
+						uni.uploadFile({
+							url: `${that.config.fileUrl}/tencent/ocr`,
+							filePath: tempFilePaths[0],
+							name: 'file',
+							formData: {
+								'test': 'test'  // 上传附带参数
+							},
+							success: (res) => {
+								// 根据接口具体返回格式   赋值具体对应url
+								// alert(uploadFileRes.data);
+								let resobj=eval("("+res.data+")");
+								uni.hideLoading();
+								if(resobj.code==200){
+									console.log(resobj);
+									that.newPlateNumber = resobj.data.vehicleNo;
+									that.vehicleClor = resobj.data.vehicleClor;
+								}else{
+									that.$refs.uToast.show({
+										title: resobj.msg,
+										type: 'error'
+									});
+								}
+								
+								console.log(res);
+							},
+							fail: (err) => {
+								that.$refs.uToast.show({
+									title:err.msg,
+									type: 'error'
+								});
+								uni.hideLoading();
+							}
+						});
+					}
+				});
 					
 				
 			},

+ 68 - 63
pages/getin/getin.vue

@@ -458,72 +458,77 @@
 				});
 			},
 			getPic(){
+				// let that = this;
+				// ocr.ocrVehicleNo((ret) => {
+				// 	if (ret.success){
+				// 		that.vehicleNo = ret.vehicleNo;
+				// 		that.carImg = 'data:image/png;base64,' + ret.imageBase64;
+				// 		this.$u.api.tencentBase64Upload({
+				// 			base64: ret.imageBase64,
+				// 			suffix: 'png'
+				// 		})
+				// 		.then(res=>{
+				// 				that.vehicleImage =  res.data.url;
+				// 		}).catch(err=>{});
+				// 	}else {
+				// 		plus.nativeUI.toast('识别失败');
+				// 	}
+				// });
+				
 				let that = this;
-				ocr.ocrVehicleNo((ret) => {
-					if (ret.success){
-						that.vehicleNo = ret.vehicleNo;
-						that.carImg = 'data:image/png;base64,' + ret.imageBase64;
-						this.$u.api.tencentBase64Upload({
-							base64: ret.imageBase64,
-							suffix: 'png'
-						})
-						.then(res=>{
-								that.vehicleImage =  res.data.url;
-						}).catch(err=>{});
-					}else {
-						plus.nativeUI.toast('识别失败');
+				uni.chooseImage({
+					count: 1, //默认9
+					sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
+					sourceType: ['camera'], //
+					success: function (res) {
+						console.log('img',res)
+						that.carImg = res.tempFilePaths[0];
+						uni.showLoading({});
+						const tempFilePaths = res.tempFilePaths;
+						// 若多选,需循环调用uni.uploadFile ,因微信小程序只支持单文件上传
+						uni.uploadFile({
+							url: `${that.config.fileUrl}/tencent/ocr`,
+							filePath: tempFilePaths[0],
+							name: 'file',
+							formData: {
+								'isUpload': '1'  // 上传附带参数
+							},
+							success: (res) => {
+								// 根据接口具体返回格式   赋值具体对应url
+								// alert(uploadFileRes.data);
+								let resobj=eval("("+res.data+")");
+								uni.hideLoading();
+								if(resobj.code==200){
+									console.log(resobj);
+									//#ifdef APP-PLUS
+									speak(resobj.data.vehicleNo);
+									//#endif
+									that.vehicleNo = resobj.data.vehicleNo;
+									that.vehicleClor = resobj.data.vehicleClor;
+									that.vehicleImage =  resobj.data.url;
+									that.carImg = 'data:image/png;base64,' + resobj.data.imageBase64;
+									this.$u.api.tencentBase64Upload({
+										base64: resobj.data.imageBase64,
+										suffix: 'png'
+									})
+								}else{
+									that.$refs.uToast.show({
+										title: resobj.msg,
+										type: 'error'
+									});
+								};
+								console.log('resobj',resobj);
+							},
+							fail: (err) => {
+								that.$refs.uToast.show({
+									title:err.msg,
+									type: 'error'
+								});
+								uni.hideLoading();
+							}
+						});
 					}
 				});
-				
-				
-				// uni.chooseImage({
-				// 	count: 1, //默认9
-				// 	sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
-				// 	sourceType: ['camera'], //
-				// 	success: function (res) {
-				// 		console.log('img',res)
-				// 		that.carImg = res.tempFilePaths[0];
-				// 		uni.showLoading({});
-				// 		const tempFilePaths = res.tempFilePaths;
-				// 		// 若多选,需循环调用uni.uploadFile ,因微信小程序只支持单文件上传
-				// 		uni.uploadFile({
-				// 			url: `${that.config.fileUrl}/baidu/ocr`,
-				// 			filePath: tempFilePaths[0],
-				// 			name: 'file',
-				// 			formData: {
-				// 				'isUpload': '1'  // 上传附带参数
-				// 			},
-				// 			success: (res) => {
-				// 				// 根据接口具体返回格式   赋值具体对应url
-				// 				// alert(uploadFileRes.data);
-				// 				let resobj=eval("("+res.data+")");
-				// 				uni.hideLoading();
-				// 				if(resobj.code==200){
-				// 					console.log(resobj);
-				// 					//#ifdef APP-PLUS
-				// 					speak(resobj.data.vehicleNo);
-				// 					//#endif
-				// 					that.vehicleNo = resobj.data.vehicleNo;
-				// 					that.vehicleClor = resobj.data.vehicleClor;
-				// 					that.vehicleImage =  resobj.data.url;
-				// 				}else{
-				// 					that.$refs.uToast.show({
-				// 						title: resobj.msg,
-				// 						type: 'error'
-				// 					});
-				// 				};
-				// 				console.log('resobj',resobj);
-				// 			},
-				// 			fail: (err) => {
-				// 				that.$refs.uToast.show({
-				// 					title:err.msg,
-				// 					type: 'error'
-				// 				});
-				// 				uni.hideLoading();
-				// 			}
-				// 		});
-				// 	}
-				// });
 			},
 			messageInputClick(){
 				this.keyboardshow = true;

+ 69 - 62
pages/getout/getout.vue

@@ -319,71 +319,78 @@
 				console.log('this.confirmData',this.confirmData)
 			},
 			getPic(){
+				// let that = this;
+				// ocr.ocrVehicleNo((ret) => {
+				// 	if (ret.success){
+				// 		that.confirmData.vehicleNo = ret.vehicleNo;
+				// 		that.confirmData.carImg =  'data:image/png;base64,' + ret.imageBase64;
+				// 		this.$u.api.tencentBase64Upload({
+				// 			base64: ret.imageBase64,
+				// 			suffix: 'png'
+				// 		})
+				// 		.then(res=>{
+				// 				that.confirmData.vehicleImage =  res.data.url;
+				// 		}).catch(err=>{});
+				// 	}else {
+				// 		plus.nativeUI.toast('识别失败');
+				// 	}
+				// });
+				
 				let that = this;
-				ocr.ocrVehicleNo((ret) => {
-					if (ret.success){
-						that.confirmData.vehicleNo = ret.vehicleNo;
-						that.confirmData.carImg =  'data:image/png;base64,' + ret.imageBase64;
-						this.$u.api.tencentBase64Upload({
-							base64: ret.imageBase64,
-							suffix: 'png'
-						})
-						.then(res=>{
-								that.confirmData.vehicleImage =  res.data.url;
-						}).catch(err=>{});
-					}else {
-						plus.nativeUI.toast('识别失败');
+				uni.chooseImage({
+					count: 1, //默认9
+					sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
+					sourceType: ['camera'], //
+					success: function (res) {
+						console.log('img',res)
+						that.confirmData.carImg = res.tempFilePaths[0];
+						uni.showLoading({});
+						const tempFilePaths = res.tempFilePaths;
+						// 若多选,需循环调用uni.uploadFile ,因微信小程序只支持单文件上传
+						uni.uploadFile({
+							url: `${that.config.fileUrl}/tencent/ocr`,
+							filePath: tempFilePaths[0],
+							name: 'file',
+							formData: {
+								'isUpload': '1'  // 上传附带参数
+							},
+							success: (res) => {
+								// 根据接口具体返回格式   赋值具体对应url
+								// alert(uploadFileRes.data);
+								let resobj=eval("("+res.data+")");
+								uni.hideLoading();
+								if(resobj.code==200){
+									console.log(resobj);
+									//#ifdef APP-PLUS
+									speak(resobj.data.vehicleNo);
+									//#endif
+									that.confirmData.vehicleNo = resobj.data.vehicleNo;
+									that.confirmData.vehicleClor = resobj.data.vehicleClor;
+									that.confirmData.vehicleImage =  resobj.data.url;
+									that.confirmData.carImg =  'data:image/png;base64,' + resobj.data.imageBase64;
+									this.$u.api.tencentBase64Upload({
+										base64: resobj.data.imageBase64,
+										suffix: 'png'
+									})
+									console.log('that.confirmData',that.confirmData);
+								}else{
+									that.$refs.uToast.show({
+										title: resobj.msg,
+										type: 'error'
+									});
+								};
+								console.log('resobj',resobj);
+							},
+							fail: (err) => {
+								that.$refs.uToast.show({
+									title:err.msg,
+									type: 'error'
+								});
+								uni.hideLoading();
+							}
+						});
 					}
 				});
-				// uni.chooseImage({
-				// 	count: 1, //默认9
-				// 	sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
-				// 	sourceType: ['camera'], //
-				// 	success: function (res) {
-				// 		console.log('img',res)
-				// 		that.confirmData.carImg = res.tempFilePaths[0];
-				// 		uni.showLoading({});
-				// 		const tempFilePaths = res.tempFilePaths;
-				// 		// 若多选,需循环调用uni.uploadFile ,因微信小程序只支持单文件上传
-				// 		uni.uploadFile({
-				// 			url: `${that.config.fileUrl}/baidu/ocr`,
-				// 			filePath: tempFilePaths[0],
-				// 			name: 'file',
-				// 			formData: {
-				// 				'isUpload': '1'  // 上传附带参数
-				// 			},
-				// 			success: (res) => {
-				// 				// 根据接口具体返回格式   赋值具体对应url
-				// 				// alert(uploadFileRes.data);
-				// 				let resobj=eval("("+res.data+")");
-				// 				uni.hideLoading();
-				// 				if(resobj.code==200){
-				// 					console.log(resobj);
-				// 					//#ifdef APP-PLUS
-				// 					speak(resobj.data.vehicleNo);
-				// 					//#endif
-				// 					that.confirmData.vehicleNo = resobj.data.vehicleNo;
-				// 					that.confirmData.vehicleClor = resobj.data.vehicleClor;
-				// 					that.confirmData.vehicleImage =  resobj.data.url;
-				// 					console.log('that.confirmData',that.confirmData);
-				// 				}else{
-				// 					that.$refs.uToast.show({
-				// 						title: resobj.msg,
-				// 						type: 'error'
-				// 					});
-				// 				};
-				// 				console.log('resobj',resobj);
-				// 			},
-				// 			fail: (err) => {
-				// 				that.$refs.uToast.show({
-				// 					title:err.msg,
-				// 					type: 'error'
-				// 				});
-				// 				uni.hideLoading();
-				// 			}
-				// 		});
-				// 	}
-				// });
 			},
 			confirmIn(){
 				let files = [];

+ 50 - 49
pages/ownersquery/ownersquery.vue

@@ -46,57 +46,58 @@
 			},
 			getPic(){
 				let that = this;
-				ocr.ocrVehicleNo((ret) => {
-					if (ret.success){
-						that.newPlateNumber = ret.vehicleNo;
-					}else {
-						plus.nativeUI.toast('识别失败');
-					}
-				});
-				// uni.chooseImage({
-				// 	count: 1, //默认9
-				// 	sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
-				// 	sourceType: ['camera'], //
-				// 	success: function (res) {
-				// 		// console.log('img',res)
-				// 		uni.showLoading({});
-				// 		const tempFilePaths = res.tempFilePaths;
-				// 		// 若多选,需循环调用uni.uploadFile ,因微信小程序只支持单文件上传
-				// 		uni.uploadFile({
-				// 			url: `${that.config.fileUrl}/baidu/ocr`,
-				// 			filePath: tempFilePaths[0],
-				// 			name: 'file',
-				// 			formData: {
-				// 				'isUpload': 0  // 上传附带参数
-				// 			},
-				// 			success: (res) => {
-				// 				// 根据接口具体返回格式   赋值具体对应url
-				// 				// alert(uploadFileRes.data);
-				// 				let resobj=eval("("+res.data+")");
-				// 				uni.hideLoading();
-				// 				if(resobj.code==200){
-				// 					console.log(resobj);
-				// 					that.newPlateNumber = resobj.data.vehicleNo;
-				// 					// that.vehicleClor = resobj.data.vehicleClor;
-				// 				}else{
-				// 					that.$refs.uToast.show({
-				// 						title: resobj.msg,
-				// 						type: 'error'
-				// 					});
-				// 				}
-								
-				// 				console.log(res);
-				// 			},
-				// 			fail: (err) => {
-				// 				that.$refs.uToast.show({
-				// 					title:err.msg,
-				// 					type: 'error'
-				// 				});
-				// 				uni.hideLoading();
-				// 			}
-				// 		});
+				// ocr.ocrVehicleNo((ret) => {
+				// 	if (ret.success){
+				// 		that.newPlateNumber = ret.vehicleNo;
+				// 	}else {
+				// 		plus.nativeUI.toast('识别失败');
 				// 	}
 				// });
+				
+				uni.chooseImage({
+					count: 1, //默认9
+					sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
+					sourceType: ['camera'], //
+					success: function (res) {
+						// console.log('img',res)
+						uni.showLoading({});
+						const tempFilePaths = res.tempFilePaths;
+						// 若多选,需循环调用uni.uploadFile ,因微信小程序只支持单文件上传
+						uni.uploadFile({
+							url: `${that.config.fileUrl}/tencent/ocr`,
+							filePath: tempFilePaths[0],
+							name: 'file',
+							formData: {
+								'isUpload': 0  // 上传附带参数
+							},
+							success: (res) => {
+								// 根据接口具体返回格式   赋值具体对应url
+								// alert(uploadFileRes.data);
+								let resobj=eval("("+res.data+")");
+								uni.hideLoading();
+								if(resobj.code==200){
+									console.log(resobj);
+									that.newPlateNumber = resobj.data.vehicleNo;
+									// that.vehicleClor = resobj.data.vehicleClor;
+								}else{
+									that.$refs.uToast.show({
+										title: resobj.msg,
+										type: 'error'
+									});
+								}
+								
+								console.log(res);
+							},
+							fail: (err) => {
+								that.$refs.uToast.show({
+									title:err.msg,
+									type: 'error'
+								});
+								uni.hideLoading();
+							}
+						});
+					}
+				});
 					
 				
 			},

+ 91 - 29
pages/parking/parking.vue

@@ -193,36 +193,98 @@
 				this.placeStatus=roadspace.placeStatus;
 				this.currentVehicleNo=roadspace.vehicleNo
 				console.log('roadspace',roadspace);
+				//let that = this;
+				// ocr.ocrVehicleNo((ret) => {
+				// 	if (ret.success){
+				// 		that.vehicleNo = ret.vehicleNo;
+				// 		// this.carImg = 'data:image/png;base64,' + ret.imageBase64;
+				// 		this.$u.api.tencentBase64Upload({
+				// 			base64: ret.imageBase64,
+				// 			suffix: 'png'
+				// 		})
+				// 		.then(res=>{
+				// 				that.carImg =  res.data.url;
+				// 				that.vehicleImage =  res.data.url;
+				// 				this.$u.route({
+				// 					type: 'redirectTo',
+				// 					url: 'pages/getin/getin',
+				// 					params: {
+				// 						spaceId: this.spaceId,
+				// 						spaceName:this.spaceName,
+				// 						roadNo:this.roadNo,
+				// 						vehicleNo:this.vehicleNo,
+				// 						carImg:that.carImg,
+				// 						vehicleImage:that.vehicleImage,
+				// 						inTime:this.inTime,
+				// 						placeStatus:this.placeStatus,
+				// 						currentVehicleNo:this.currentVehicleNo
+				// 					}
+				// 				});
+				// 		}).catch(err=>{});
+				// 	}else {
+				// 		plus.nativeUI.toast('识别失败');
+				// 	}
+				// });
+				
 				let that = this;
-				ocr.ocrVehicleNo((ret) => {
-					if (ret.success){
-						that.vehicleNo = ret.vehicleNo;
-						// this.carImg = 'data:image/png;base64,' + ret.imageBase64;
-						this.$u.api.tencentBase64Upload({
-							base64: ret.imageBase64,
-							suffix: 'png'
-						})
-						.then(res=>{
-								that.carImg =  res.data.url;
-								that.vehicleImage =  res.data.url;
-								this.$u.route({
-									type: 'redirectTo',
-									url: 'pages/getin/getin',
-									params: {
-										spaceId: this.spaceId,
-										spaceName:this.spaceName,
-										roadNo:this.roadNo,
-										vehicleNo:this.vehicleNo,
-										carImg:that.carImg,
-										vehicleImage:that.vehicleImage,
-										inTime:this.inTime,
-										placeStatus:this.placeStatus,
-										currentVehicleNo:this.currentVehicleNo
-									}
-								});
-						}).catch(err=>{});
-					}else {
-						plus.nativeUI.toast('识别失败');
+				uni.chooseImage({
+					count: 1, //默认9
+					sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
+					sourceType: ['camera'], //
+					success: function (res) {
+						// console.log('img',res)
+						uni.showLoading({});
+						const tempFilePaths = res.tempFilePaths;
+						// 若多选,需循环调用uni.uploadFile ,因微信小程序只支持单文件上传
+						uni.uploadFile({
+							url: `${that.config.fileUrl}/tencent/ocr`,
+							filePath: tempFilePaths[0],
+							name: 'file',
+							formData: {
+								'test': 'test'  // 上传附带参数
+							},
+							success: (res) => {
+								let resobj=eval("("+res.data+")");
+								uni.hideLoading();
+								if(resobj.code==200){
+									that.vehicleNo =resobj.data.vehicleNo;
+									// this.carImg = 'data:image/png;base64,' + ret.imageBase64;
+									this.$u.api.tencentBase64Upload({
+										base64: resobj.data.imageBase64,
+										suffix: 'png'
+									})
+									.then(res=>{
+											that.carImg =  res.data.url;
+											that.vehicleImage =  res.data.url;
+											this.$u.route({
+												type: 'redirectTo',
+												url: 'pages/getin/getin',
+												params: {
+													spaceId: this.spaceId,
+													spaceName:this.spaceName,
+													roadNo:this.roadNo,
+													vehicleNo:this.vehicleNo,
+													carImg:that.carImg,
+													vehicleImage:that.vehicleImage,
+													inTime:this.inTime,
+													placeStatus:this.placeStatus,
+													currentVehicleNo:this.currentVehicleNo
+												}
+											});
+									}).catch(err=>{});
+								}else{
+									that.$refs.uToast.show({
+										title: resobj.msg,
+										type: 'error'
+									});
+								}
+								
+							},
+							fail: (err) => {
+								plus.nativeUI.toast('识别失败');
+								uni.hideLoading();
+							}
+						});
 					}
 				});
 			},