ocr扫描拨打demo

http://e.anyoupin.cn/52/ocrDial/takePic.php

快递员使用扫描拨打。
手机端扫描纸质订单上传图片ocr识别一下电话号码拨打。


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="format-detection" content="telephone=no"/>
<title>OCR拨打电话号码</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
<style>

.modify_image{

width:99%;
}
.wrap{
margin:50px auto;
width:240px;
background-color:AliceBlue;
}
.result{
margin:20px auto;
}
</style>
    <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script type="text/javascript" src="/js/onerror.js"></script>
</head>
 
<body>
	<div class="wrap">
<h2>OCR拨打电话号码</h2>
<input id="photo" type="file" accept="image/*" capture />
<div class="result"></div>
<!--
<a id='telephone' href="tel:10086">10086</a>
-->
<div class="backgrd"><a href="https://www.52pojie.cn/thread-1689672-1-1.html">背景</a></div>
<img  class="modify_image" src=''>
	</div>

</body>
<script>
$('#photo').change(function(){
				var _this = $(this)[0],
				    _file = _this.files[0],
					fileType = _file.type;
				//alert(fileType)
					console.log(_file.size);
				if(/image\/\w+/.test(fileType)){
					var fileReader = new FileReader();
					fileReader.readAsDataURL(_file);
					fileReader.onload = function(event){
						var result = event.target.result;   //返回的dataURL
						var image = new Image();
						image.src = result;
						image.onload = function(){  //创建一个image对象,给canvas绘制使用
							var cvs = document.createElement('canvas');
							var scale = 1;  
							if(this.width > 600 || this.height > 600){  //1000只是示例,可以根据具体的要求去设定  
								if(this.width > this.height){  
									scale = 1600 / this.width;
								}else{  
									scale = 1600 / this.height;  
								}  
							}
							cvs.width = this.width*scale;  
                			                cvs.height = this.height*scale;     //计算等比缩小后图片宽高
							var ctx = cvs.getContext('2d');  
							ctx.drawImage(this, 0, 0, cvs.width, cvs.height);   
			                              var newImageData = cvs.toDataURL(fileType, 0.98);   //重新生成图片,<span style="font-family: Arial, Helvetica, sans-serif;">fileType为用户选择的图片类型</span>
         $('.modify_image').attr('src',newImageData);
//	alert(newImageData)
         
							var sendData = newImageData.replace("data:"+fileType+";base64,",'');
			$.post('upload_index.php',{type:'photo',image:sendData},function(data){
           //   alert(data)  
				regexp=/\d{11}/;
				if(data.match(regexp)!=null){
//		alert('mm'+data.match(regexp))
//window.location.href='tel:'+data

	result=`<a  id="telephone" href="tel:${data}">${data}</a>`
	document.querySelector(".result").innerHTML=result;
//	window.location.href='tel:'+data
//	setTimeout("window.location.href='tel:${data}'",3)				
	setTimeout("document.querySelector('#telephone').click()",100)				

				}else{
				
				
				alert(data);
				} 
			

							});
						}
						
					}
				}else{
					//$.notify.show('请选择图片格式文件', {placement: 'center'});
				}
			});
</script>
</html>

更多推荐