1
OCR号我几乎完成了sucessfull程序的代码,是用一个样本文件,但我不能让编辑我的表的照片,以便OCR工作。树莓派 - 从仪表
我发现我的输出图像是相当接近的工作模式,但我不知道还有什么我可以做形象得到它的工作。
这是我的代码:
import pytesseract
import Image
import sys
from PIL import Image
from PIL import ImageFilter
import PIL
import PIL.ImageOps
image_file_ocr = 'ocr_output.jpg'
image_file = 'image_original.jpg'
#image_file = 'ocr2.jpg'
#image_file = 'sample1.jpg'
#image_file = 'sample2.jpg'
#image_file = 'sample3.jpg'
#image_file = 'sample4.jpg' # texto largo
#image_file = 'sample5.jpg' #image_text = "1234567890"
print image_file
# LOAD THE IMAGE
#image = Image.open('sample5.jpg')
image = Image.open(image_file) # open colour image
image = image.convert('L') # convert image to monochrome - this works
#image = image.convert('1') # convert image to black and white
image = image.rotate(-90)
# EDIT THE IMAGE
w, h = image.size
#image = image.crop((0, 30, w, h-30))
image = image.crop((350, 680, 1100, 770))
image.filter(ImageFilter.SHARPEN)
image = PIL.ImageOps.invert(image)
image.save(image_file_ocr,'jpeg')
# PROCESS THE IMAGE
print "\n\nProcessing image: " + image_file_ocr
image = Image.open(image_file_ocr)
print "Process method 1:"
text = pytesseract.image_to_string(image, config='outputbase digits')
print text
print "Process method 2:"
text = pytesseract.image_to_string(image)
print text
下面的图片可以正常工作
我猜正方体内二值化灰度图像和过程可能不给你的图像上很好地工作。尝试先将其正确二值化,然后将其传递给tesseract;我敢打赌它的效果好得多。 –
我也建议将图像转换为1位像素('mode“1”')。请注意,您可能必须将其转换回8位灰度或rgb才能执行其余的处理。 – martineau
我与#image = image.convert尝试( '1')\t \t \t \t#转换图像以黑色和白色。但是由于背景中留下了许多点,所以效果不佳。你能帮助我如何使用python二进制化? – Serge