Python 3.x 如何仅保留pdf文本或其图像的注释部分?
我已经构建了将pdf文本转换为图像的程序,我只想保留括号之间的文本部分: 例如,我想保留的文本的第一部分是: 我知道我可以从Python 3.x 如何仅保留pdf文本或其图像的注释部分?,python-3.x,image-processing,Python 3.x,Image Processing,我已经构建了将pdf文本转换为图像的程序,我只想保留括号之间的文本部分: 例如,我想保留的文本的第一部分是: 我知道我可以从PIL使用Image,然后使用.crop(左、上、右、下)功能,但我不知道如何让它知道我想要文本中有[的部分 我知道即使我们按颜色提取图像也很有用。事实上,他们会找到轮廓并进行迭代。如果他们找到4个角点,他们会做另一件事来提取文本。这里我们有2个角点 以下是我从pdf格式的图像中获取文本的部分代码: for file_name in file_names: #
PIL
使用Image
,然后使用.crop(左、上、右、下)
功能,但我不知道如何让它知道我想要文本中有[
的部分
我知道即使我们按颜色提取图像也很有用。事实上,他们会找到轮廓并进行迭代。如果他们找到4个角点,他们会做另一件事来提取文本。这里我们有2个角点
以下是我从pdf格式的图像中获取文本的部分代码:
for file_name in file_names:
# load the image and convert it to grayscale
image = cv2.imread(file_name)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# check to see if we should apply thresholding to preprocess the
# image
if args["preprocess"] == "thresh":
gray = cv2.threshold(gray, 0, 255,
cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
# make a check to see if median blurring should be done to remove
# noise
elif args["preprocess"] == "blur":
gray = cv2.medianBlur(gray, 3)
# write the grayscale image to disk as a temporary file so we can
# apply OCR to it
filename = "{}.png".format(os.getpid())
cv2.imwrite(filename, gray)
# load the image as a PIL/Pillow image, apply OCR, and then delete
# the temporary file
text = pytesseract.image_to_string(Image.open(filename))
os.remove(filename)
#print(text)
with open('resume.txt', 'a+') as f:
print('***:', text, file=f)
使用cv2(pip安装opencv python)进行模板匹配或块检测