Dzwebs.Net

撰写电脑技术杂文十余年

ocrad.js客户端识别图片上的文字

Admin | 2016-6-2 9:51:47 | 被阅次数 | 10332

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  ocrad.js是一个简单的 OCR (光学字符识别)程序,是一个OCP的实现库,纯javascript版本的 Ocrad 项目实现,可以扫描图像中的文字变成文本。

  简单的说,ocrad.js就是一个js库,专门用来在客户端识别图片上的文字。该ocrad.js库文件,大概只有1M左右的大小,非常方便。

  下面为大家介绍其使用方法。

  一、引用库文件

  <script src="ocrad.js"></script> 

  二、调用库文件方法的方法

  ①识别图片上的数字

  <script>
            function recognize_image(){
                document.getElementById('transcription').innerText = "(Recognizing...)"

                OCRAD(document.getElementById("pic"), {
                    numeric: true
                }, function(text){
                    document.getElementById('transcription').className = "done"
                    document.getElementById('transcription').innerText = text;
                })
            }
        </script>

  ②识别图片上的文字

  <script>
            function recognize_image(){
                document.getElementById('transcription').innerText = "(Recognizing...)"

                OCRAD(document.getElementById("pic"), function(text){
                    document.getElementById('transcription').className = "done"
                    document.getElementById('transcription').innerText = text;
                })
            }
        </script>

  ③通过电脑摄像头识别图片

  <script>
            function recognize_snapshot(){
                document.getElementById('text').innerText = "(Recognizing...)"
                document.getElementById('transcription').className = "recognizing"
                OCRAD(document.getElementById("video"), {
                    invert: document.getElementById('whiteText').checked // set this for white on black text
                }, function(text){
                    document.getElementById('transcription').className = "done"
                    document.getElementById('text').innerText = text || "(empty)";
                })
            }

            function acquiredVideo(stream){
                var video = document.getElementById('video')
                if ('mozSrcObject' in video) { video.mozSrcObject = stream;
                } else if (window.webkitURL) { video.src = window.webkitURL.createObjectURL(stream);
                } else { video.src = stream; }
                video.play();

                document.getElementById('blackText').checked = true;
            }
            window.onload = function(){
                navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
                if(navigator.getUserMedia) navigator.getUserMedia({ video: true }, acquiredVideo, function(){})
            }
        </script>

  好了,多就不说了,总之,个人还是觉得,其识别能力目前还有限,识别效果不是很好。


该杂文来自: 网页制作杂文

上一篇:canvas载入图片的正确代码

下一篇:js aler重写 不弹出

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计