首页 > 解决方案 > 如何使用 OCR Pytesseract 删除文本提取后出现的箭头符号

问题描述

嗨,我正在使用坐标从简历中提取一些文本。从 OCR Pytesseract 提取文本后,每次将文本写入 txt 文件后都会弹出一个箭头

这是我的代码

import cv2

import numpy as np

import pytesseract
import threading

image = cv2.imread(r'C:\Users\Ramesh\Desktop\Parsing_Project\Resumes_jpg\Akhil\Akhil.jpg')
image = cv2.resize(image,(800,740))

kernel = np.array([[-1,-1,-1], 
                   [-1, 9,-1],
                   [-1,-1,-1]])

sharpened = cv2.filter2D(image, -1, kernel)

f = open(r'C:\Users\Ramesh\Desktop\Parsing_Project\result_text.txt', "a")

def designation(image):
    
    designation_cropped = image[65
                                :90, 290:600]
    text = pytesseract.image_to_string(designation_cropped).replace(',', ' ')
    print(text)
    f.write(text + '\n' )

def skills(image):
    skills_cropped = sharpened[110:210, 10:220]
    text = pytesseract.image_to_string(skills_cropped).replace(',', ' ')
    print(text)
    f.write(text + '\n' )
    f.close()

threading.Thread(target =designation(image)).start()
threading.Thread(target =skills(image)).start()

这是提取的文本片段。每次我将文本写入 txt 文件时,都会看到一个箭头

这是结果文件

我想摆脱箭头标志。有人可以帮我吗?

标签: pythonpython-3.xfunctionopencvocr

解决方案


大家好,我找到了解决方案

我用了

text.replace('\f','')

这删除了我的结果中捕获的箭头


推荐阅读