Pytesseract无法加载,因为无法找到tesseract

时间:2019-03-27 14:08:41

标签: python python-3.x tesseract python-tesseract

尝试在Windows 10上使用pytesseract在python上安装和使用tesseract时出现错误:

  File "C:\ProgramData\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 194, in run_tesseract
    raise TesseractError(status_code, get_errors(error_string))

TesseractError: (1, 'Error opening data file \\Program Files (x86)\\Tesseract-OCR\\eng.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'eng\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')

我尝试重新安装tesseract。 我已将C:\ Program Files(x86)\ Tesseract-OCR设置为PATH环境变量 我已将TESSDATA_PREFIX添加到C:\ Program Files(x86)\ Tesseract-OCR \ tessdata 我已经证实,当我在CMD作品中输入“ tesseract”时

我使用的代码:

import cv2
import pytesseract


# Uncomment the line below to provide path to tesseract manually
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe"

# Define config parameters.
# '-l eng'  for using the English language
# '--oem 1' for using LSTM OCR Engine
config = ('-l eng --oem 1 --psm 3')

# Read image from disk
im = cv2.imread("Serie1/NL83LHL9.JPG", cv2.IMREAD_COLOR)

# Run tesseract OCR on image
text = pytesseract.image_to_string(im, config=config)
# Print recognized text
print(text)

结果:

CMD> tesseract:显示tesseract界面

2 个答案:

答案 0 :(得分:0)

如果您的PATH中没有tesseract可执行文件,请包括以下内容:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>Photo Sphere Viewer</title>
        <meta name="viewport" content="initial-scale=1.0" />
        <link rel="stylesheet" href="node_modules/photo-sphere-viewer/dist/photo-sphere-viewer.css">

        <script type="text/javascript" src="node_modules/photo-sphere-viewer/node_modules/uevent/uevent.js"></script>
        <script type="text/javascript" src="node_modules/three/build/three.js"></script>
        <script type="text/javascript" src="node_modules/dot/doT.js"></script>
        <script type="text/javascript" src="node_modules/photo-sphere-viewer/dist/photo-sphere-viewer.js"></script>
    </head>

    <body>
        <div id="viewer"></div>

        <style>
            #viewer {
              width: 100vw;
              height: 50vh;
            }
          </style>

        <script>

        //var radianLat = 3.19267140400974 * Math.PI / 180; 
        //var radianLon = -101.606916778012 * Math.PI / 180; 
        //radianLon += -0.5

        //var degreeLat = 3.191343 * Math.PI / 180;
        //var degreeLon = 101.606001 * Math.PI / 180;
        var degreeLat = '3.191343deg';
        var degreeLon = '-101.606001deg';

        // var degreeLat = 3.19069555218933 * (180 / Math.PI);
        // var degreeLon = -101.605626082019 * (180 / Math.PI);

        /*
            var phi = (degreeLat)*Math.PI/180;
            var theta = (degreeLon-180)*Math.PI/180;
            var x = -(6371) * Math.cos(phi) * Math.cos(theta);
            var y = (6371) * Math.sin(phi);
            lat = 3.19069555218933
            lon = 101.605626082019
            var cosLat = Math.cos(lat * Math.PI / 180.0);
            var sinLat = Math.sin(lat * Math.PI / 180.0);
            var cosLon = Math.cos(lon * Math.PI / 180.0);
            var sinLon = Math.sin(lon * Math.PI / 180.0);
            var rad = 6378137.0;
            var f = 1.0 / 298.257224;
            var C = 1.0 / Math.sqrt(cosLat * cosLat + (1 - f) * (1 - f) * sinLat * sinLat);
            var S = (1.0 - f) * (1.0 - f) * C;
            var h = 0.0;
            //degreeLat = (rad * C + h) * cosLat * cosLon;
            //degreeLon = (rad * C + h) * cosLat * sinLon;
            // marker_mesh.position.z = (rad * S + h) * sinLat;
            //var xLoc = 11310830.24;
            //var yLoc = 355590.62;
            */

            console.log(degreeLon + " " + degreeLat);
            //console.log(radianLon + " " + radianLat);
            //console.log(x + " " + y);

            let PSV = new PhotoSphereViewer({
                    panorama: 'Panoramic2/20181214-145610-000002827.jpg',
                    container: document.querySelector('#viewer'),
                    time_anim: 3000,
                    //navbar: true,
                    //navbar_style: {backgroundColor: 'rgba(58, 67, 77, 0.7)'},

                markers: [
                    {
                    // image marker that opens the panel when clicked
                    id: 'image',
                    longitude: degreeLon,
                    latitude: degreeLat,
                    //longitude: x,
                    //latitude: y,
                    //x: xLoc,
                    //y: yLoc,  
                    image: 'assets/pin.png',
                    width: 32,
                    height: 32,
                    anchor: 'bottom center',
                    tooltip: 'Asset marker. <b>Click me!</b>',
                    //content: document.getElementById('lorem-content').innerHTML
                    },
                    {
                    // circle marker
                    id: 'circle',
                    circle: 20,
                    x: 1,
                    y: 1,
                    tooltip: 'A circle marker'
                    }
                ]

                }
                );

                /**
                * Create a new marker when the user clicks somewhere
                */

                PSV.on('click', function(e) {
                PSV.addMarker({
                    id: '#' + Math.random(),
                    longitude: e.longitude,
                    latitude: e.latitude,
                    image: 'assets/pin.png',
                    width: 32,
                    height: 32,
                    anchor: 'bottom center',
                    tooltip: 'Generated pin',
                    data: {
                    generated: true
                    }
                });
                //alert((e.longitude * 180 / Math.PI) + ' ' + (e.latitude * 180 / Math.PI))
                alert((e.longitude) + ' ' + (e.latitude));
                var objLatLong = e.getPositionInDegrees();
                alert((objLatLong.longitude) + ' ' + (objLatLong.latitude));
                });
        </script>
    </body>
</html>

答案 1 :(得分:0)

由Dmitrii Z解决。

  

实际上看起来有点奇怪。您可以尝试做的一件事是将tessdata路径添加到您的配置-config = r'--tessdata-dir "C:\Program Files (x86)\Tesseract-OCR\tessdata" -l eng --oem 1 --psm 3'

相关问题