AttributeError: у объекта 'numpy.ndarray' нет ошибки атрибута 'split' при преобразовании изображения в текст - PullRequest
0 голосов
/ 02 мая 2019

Я пытаюсь преобразовать изображение в текст, но оно дает текст

pytesseract.image_to_string (roi, lang = 'eng', config = '- oem 1 --psm 6 -cpreserve_interword_spaces = 1 ') (11, 4) (11,)
Файл "C: \ Users \ Акшата \ Anaconda3 \ envs \ env_full \ lib \ site-packages \ pytesseract-0.1.7-py3.6.egg \pytesseract \ pytesseract.py ", строка 104, в image_to_string AttributeError: у объекта 'numpy.ndarray' нет атрибута 'split'. Есть ли способ исправить это.

import cv2
import pytesseract
import numpy as np


  pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files 
  (x86)\\Tesseract-OCR\\tesseract'

 def get_contour_precedence(contour, cols):
      tolerance_factor = 20
      origin = cv2.boundingRect(contour)
      return ((origin[0] // tolerance_factor) * tolerance_factor) * cols 
      + origin[1]
 img = cv2.imread("C:/Users/Akshatha/Desktop/text_detection_from 
  _image/images/news1.jpg")
 gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

  ret, thresh = cv2.threshold(gray, 0, 255,
                        cv2.THRESH_BINARY_INV +
                        cv2.THRESH_OTSU)

   kernel = np.ones((5, 5), np.uint8)
   erosion = cv2.erode(thresh, kernel, iterations=1)

   dilation = cv2.dilate(thresh, kernel, iterations=3)
   contours, heirarchy = cv2.findContours(dilation, cv2.RETR_EXTERNAL, 
   cv2.CHAIN_APPROX_SIMPLE)
   heirarchy = heirarchy[0]
   print(np.array(heirarchy).shape, np.array(contours).shape)
   contours.sort(key=lambda x: get_contour_precedence(x, img.shape[1]))

   # print(contours[0])
  idx = 0
  textlist = []
  i = 0
  rect_list = []
 for c in contours:
   # get the bounding rect
      x, y, w, h = cv2.boundingRect(c)
     rect_list.append((x, y, x + w, y + h))
    # draw a green rectangle to visualize the bounding rect
    cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 0), 3)

     roi = img[y:y + h, x:x + w]
       text = pytesseract.image_to_string(roi, lang='eng', config='--oem 
      1 --psm 6 -c preserve_interword_spaces=1 ')
    print(text)
   cv2.putText(img, "#{}".format(i + 1), (x, y - 15), 
       cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 4)
             i += 1

             cv2.namedWindow('Dilation', cv2.WINDOW_NORMAL)
         cv2.imshow('Dilation', img)
               cv2.waitKey(0)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...