Как распознать текст из нескольких фотографий Python и записать данные в таблицу

Discussion in 'Python' started by xakepok777, 25 Mar 2022.

  1. xakepok777

    xakepok777 New Member

    Joined:
    18 Mar 2016
    Messages:
    29
    Likes Received:
    0
    Reputations:
    0
    Есть фотографии ценников в папке. Нужно чтобы в Excele, при запуске python скрипта получалась таблица Название товара и Цена и записывались данные с ценников
     
  2. xakepok777

    xakepok777 New Member

    Joined:
    18 Mar 2016
    Messages:
    29
    Likes Received:
    0
    Reputations:
    0
    import cv2
    import pytesseract
    import os
    import csv
    import shutil

    pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
    config = r'--oem 3 --psm 6'

    directory = 'C:/Users/user/PycharmProjects/pythonProject1/'
    path = os.listdir(directory)
    for Images in path:
    if Images.endswith(('.jpg', '.png')):
    img = cv2.imread(Images)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    imgText = (pytesseract.image_to_string(img, lang='rus', config=config))
    myFile = open('123456.csv', 'a', newline='')
    with myFile:
    writer = csv.writer(myFile, delimiter=";")
    writer.writerow([Images,imgText])
    destination = 'trash'
    shutil.move(Images, destination)
    print(Images)
    print(imgText)
    cv2.waitKey(0)
     
  3. xakepok777

    xakepok777 New Member

    Joined:
    18 Mar 2016
    Messages:
    29
    Likes Received:
    0
    Reputations:
    0
    [​IMG] [​IMG]