Why my image is in bad quality ?
fsn761304 at gmail.com
fsn761304 at gmail.com
Wed Dec 16 09:04:37 EST 2015
I'm trying to make OCR-recognition on a screenshot, after screenshot taken it goes to pibxbuffer, which content goes to pytesseract.
But after using pixbuffer image quality is bad (I tried to save it in a directory, instead of pixbuffer, and looked at it).
Below is the problematic snippets of code, further is the whole function.
pixbufObj = Gdk.pixbuf_get_from_window(window, x, y, width, height)
...
image = Image.frombuffer("RGB", (width, height),
pixbufObj.get_pixels(), 'raw', 'RGB', 0, 1)
image = image.resize((width*20,height*20), Image.ANTIALIAS)
...
print(pytesseract.image_to_string(image))
Full function:
def takeScreenshot(self, x, y, width = 150, height = 30):
self.width=width
self.height=height
window = Gdk.get_default_root_window()
#x, y, width, height = window.get_geometry()
#print("The size of the root window is {} x {}".format(width, height))
# get_from_drawable() was deprecated. See:
# https://developer.gnome.org/gtk3/stable/ch24s02.html#id-1.6.3.4.7
pixbufObj = Gdk.pixbuf_get_from_window(window, x, y, width, height)
height = pixbufObj.get_height()
width = pixbufObj.get_width()
image = Image.frombuffer("RGB", (width, height),
pixbufObj.get_pixels(), 'raw', 'RGB', 0, 1)
image = image.resize((width*20,height*20), Image.ANTIALIAS)
#image.save("saved.png")
print(pytesseract.image_to_string(image))
print("takenScreenshot:",x,y)
More information about the Python-list
mailing list