我对一些pdf文件有问题。我需要将它们转换为jpg图像,使它们可用于OCR,但当我转换其中的一些,魔杖转我的jpg在那里有一个黑色的背景文本。我看到这是一个关于空间颜色的常见问题。这似乎发生在word转换为pdf文件的文件中,其中空间颜色变成了CMYK。Tesseract OCR仅接受空间颜色RGB。我已经写了一个可以转换的python脚本,但我想解决这个问题。你能帮我一下吗?谢谢。

原页pdf

已将pdf转换为jpg
发布于 2019-04-23 06:44:02
这是我的代码:
def convert_pdf(pdf_file):
# Get name file
title = os.path.splitext(os.path.basename(pdf_file))[0]
basename = os.path.basename(pdf_file)
pdf = wi(filename=pdf_file, resolution=100)
pdfImage = pdf.convert("jpg")
outputPath = PATH_IMAGES+"/" + basename
if not os.path.exists(outputPath):
os.mkdir(outputPath)
i=1
for img in pdfImage.sequence:
page = wi(image=img)
page.save(filename=outputPath+"/"+title+"(*page="+str(i)+"*)"+".jpg")
imagePathConverted = outputPath+"/"+title+"(*page="+str(i)+"*)"+".jpg"
'''image = Image.open(imagePathConverted)
if image.mode != 'RGB':
rgb_image = image.convert('RGB')
rgb_image.save(imagePathConverted)'''
i += 1
return outputPath发布于 2019-05-22 18:57:22
解决方案是在调用save之前设置这些参数:
page = wi(image=img)
page.background_color = Color('white')
page.alpha_channel = 'remove'
page.save(...)感谢this堆栈溢出答案。
https://stackoverflow.com/questions/55793027
复制相似问题