Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tesseract给出了高度不一致的结果_Python_Image Processing_Tesseract_Python Tesseract_Tess4j - Fatal编程技术网

Python tesseract给出了高度不一致的结果

Python tesseract给出了高度不一致的结果,python,image-processing,tesseract,python-tesseract,tess4j,Python,Image Processing,Tesseract,Python Tesseract,Tess4j,我想得到的结果,这是在图像格式的匹配。 下面是我用来从图像中读取文本的代码。我使用了python代码,它也给出了相同的结果。我如何提高产量,或者有没有其他更好的方法来解决我的问题 public String getImgText(String imageLocation) { ITesseract instance = new Tesseract(); try { instance.setDatapath("/tessdata

我想得到的结果,这是在图像格式的匹配。 下面是我用来从图像中读取文本的代码。我使用了python代码,它也给出了相同的结果。我如何提高产量,或者有没有其他更好的方法来解决我的问题

     public String getImgText(String imageLocation) {
      ITesseract instance = new Tesseract();

      try 
      {
          instance.setDatapath("/tessdata");
          instance.setLanguage("eng");
         String imgText = instance.doOCR(new File(imageLocation));

         return imgText;
      } 
      catch (TesseractException e) 
      {
         e.getMessage();
         return "Error while reading image";
      }
   } 
输出与输入完全不同

unnl lE

mam-m m,

mun-m, 1 ms "mm M

W urn-mm my A mm“ m

mus-1mm 1 m- m m

mfinlln um: ”mu“ m

ilk-M m.

mwnm mu 5 mm nu-

..mn. n w. tvhrzmr- m

2 rm.“- 0 w, mama: m.

mum-mp 5 mu mum n.

a bulb-h» m

tum-3mm nun mm,” M

3 mmn m; mum“ M

Ema W 7 a“. m

mzsm 5m mm»... m
Continue
输入图像为


您应该在运行Tesseract(带有opencv库的python代码)之前对图像进行预处理:

结果是这样的:

此外,英语traineddata似乎对PUBG字体的处理很差,因此您可能需要对其进行微调:

在OCR之前,您需要反转图像。
import cv2

img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
result = cv2.bitwise_not(img)
result[result >= 190] = 255

# To show the image
cv2.imshow("Threshold", result)
cv2.waitKey()