Re: Why my image is in bad quality ?

2015-12-17 Thread fsn761304
On Thursday, December 17, 2015 at 5:27:28 AM UTC+4, Nobody wrote:
> On Wed, 16 Dec 2015 06:04:37 -0800, fsn761304 wrote:
> 
> > pixbufObj = Gdk.pixbuf_get_from_window(window, x, y, width, height) ...
> > image = Image.frombuffer("RGB", (width, height),
> >  pixbufObj.get_pixels(), 'raw', 'RGB', 0, 1)
> 
> The second-to-last argument should probably be Gdk.pixbuf_get_rowstride()
> rather than 0.

No, this:
image = Image.frombuffer("RGB", (width, height), 
 pixbufObj.get_pixels(), 'raw', 'RGB', 
Gdk.pixbuf_get_rowstride(), 1)

doesn't work:

AttributeError: 'gi.repository.Gdk' object has no attribute 
'pixbuf_get_rowstride'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread Nobody
On Wed, 16 Dec 2015 06:04:37 -0800, fsn761304 wrote:

> pixbufObj = Gdk.pixbuf_get_from_window(window, x, y, width, height) ...
> image = Image.frombuffer("RGB", (width, height),
>  pixbufObj.get_pixels(), 'raw', 'RGB', 0, 1)

The second-to-last argument should probably be Gdk.pixbuf_get_rowstride()
rather than 0.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread BartC

On 16/12/2015 21:53, fsn761...@gmail.com wrote:

On Thursday, December 17, 2015 at 1:36:55 AM UTC+4, BartC wrote:



You need to test step by step to see at what point it goes wrong. You're
scaling by 20 (which is a massive amount); what happens when scaling by
1? And anti-alias is turned off? (Which might let you see by how many
pixels each successive line is out and could give a clue.)

It does seem as though something is going amiss with recognising the
image dimensions, or you've inadvertently applied a 'shear' or 'slant'
transformation. (Maybe you can apply a reverse transform to fix it!)

--
Bartc


Original size: 150x30
Original image the same, but without skew (usual upright letters).
When scaling by less than 20 recognition quality is bad (in another code, which 
doesn't use buffer, screenshot, but loads image from a directory).
Antialias makes no difference.
Shear, slant - ok, show me how.


I've played with a 150x30 reduced image. The best I can do is apply a 
shift that makes the letters slant the other way, but at only half the 
angle. Trying to get them upright makes them wobbly. (I did this with 
some code - not Python - that read each pixel and stored it at a shifted 
position. But this is because I'm not familiar with manipulation programs.)


So whatever's gone wrong might be more complex. You should forget about 
recognition quality, and find out what it is that's applying the skew 
(another name for shear or slant). That seems to be being applied before 
the scaling, which is giving the 'steps' in the sloping edges.


--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread fsn761304
On Thursday, December 17, 2015 at 1:36:55 AM UTC+4, BartC wrote:
> On 16/12/2015 17:17, fsn761...@gmail.com wrote:
> > ...here is the bad image: http://wikisend.com/download/748118/saved.png
> >
> 
> This is 3000x600 pixels; what was the original size? (150x30?)
> 
> What does the original look like?
> 
> You need to test step by step to see at what point it goes wrong. You're 
> scaling by 20 (which is a massive amount); what happens when scaling by 
> 1? And anti-alias is turned off? (Which might let you see by how many 
> pixels each successive line is out and could give a clue.)
> 
> It does seem as though something is going amiss with recognising the 
> image dimensions, or you've inadvertently applied a 'shear' or 'slant' 
> transformation. (Maybe you can apply a reverse transform to fix it!)
> 
> -- 
> Bartc

Original size: 150x30
Original image the same, but without skew (usual upright letters).
When scaling by less than 20 recognition quality is bad (in another code, which 
doesn't use buffer, screenshot, but loads image from a directory).
Antialias makes no difference.
Shear, slant - ok, show me how.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread BartC

On 16/12/2015 17:17, fsn761...@gmail.com wrote:

...here is the bad image: http://wikisend.com/download/748118/saved.png



This is 3000x600 pixels; what was the original size? (150x30?)

What does the original look like?

You need to test step by step to see at what point it goes wrong. You're 
scaling by 20 (which is a massive amount); what happens when scaling by 
1? And anti-alias is turned off? (Which might let you see by how many 
pixels each successive line is out and could give a clue.)


It does seem as though something is going amiss with recognising the 
image dimensions, or you've inadvertently applied a 'shear' or 'slant' 
transformation. (Maybe you can apply a reverse transform to fix it!)


--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread fsn761304
...here is the bad image: http://wikisend.com/download/748118/saved.png
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread fsn761304
On Wednesday, December 16, 2015 at 8:41:23 PM UTC+4, Chris Angelico wrote:
> On Thu, Dec 17, 2015 at 3:33 AM,   wrote:
> > On Wednesday, December 16, 2015 at 6:33:56 PM UTC+4, Chris Angelico wrote:
> >> On Thu, Dec 17, 2015 at 1:21 AM,   wrote:
> >> > I tried also another code (see below) and without scaling by 20 quality 
> >> > of recognition was very bad.
> >> >
> >> > from pytesseract import image_to_string
> >> > from PIL import Image
> >> >
> >> > im = Image.open("screen.png")
> >> > print(im)
> >> > im = im.resize((214*20,26*20), Image.ANTIALIAS)
> >> > print(image_to_string(im))
> >>
> >> If you need to scale by 20x20 to get the text recognition to work, I
> >> would recommend using something other than an anti-alias filter. Omit
> >> the second argument to use a simpler algorithm; you'll get a blocky
> >> result, which might parse more cleanly for you.
> >>
> >> ChrisA
> >
> > It didn't help to recognize words, the main problem is that image is 
> > inclined to the left, like backslash.
> 
> Interesting. I'm not sure what exactly is going on, as I can't see
> your image or the result, but is it possible that the text is getting
> wrapped? Try printing it to a file, then pulling the file up in a text
> editor with word wrap disabled. Maybe it'll look different.
> 
> ChrisA
When I saved image to a directory it was ok (quality) and recognition was good. 
(there are commented string, which saves into dictory: #image.save("saved.png") 
) It seems I did something wrong with image buffer.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread Chris Angelico
On Thu, Dec 17, 2015 at 3:33 AM,   wrote:
> On Wednesday, December 16, 2015 at 6:33:56 PM UTC+4, Chris Angelico wrote:
>> On Thu, Dec 17, 2015 at 1:21 AM,   wrote:
>> > I tried also another code (see below) and without scaling by 20 quality of 
>> > recognition was very bad.
>> >
>> > from pytesseract import image_to_string
>> > from PIL import Image
>> >
>> > im = Image.open("screen.png")
>> > print(im)
>> > im = im.resize((214*20,26*20), Image.ANTIALIAS)
>> > print(image_to_string(im))
>>
>> If you need to scale by 20x20 to get the text recognition to work, I
>> would recommend using something other than an anti-alias filter. Omit
>> the second argument to use a simpler algorithm; you'll get a blocky
>> result, which might parse more cleanly for you.
>>
>> ChrisA
>
> It didn't help to recognize words, the main problem is that image is inclined 
> to the left, like backslash.

Interesting. I'm not sure what exactly is going on, as I can't see
your image or the result, but is it possible that the text is getting
wrapped? Try printing it to a file, then pulling the file up in a text
editor with word wrap disabled. Maybe it'll look different.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread fsn761304
On Wednesday, December 16, 2015 at 8:34:15 PM UTC+4, fsn7...@gmail.com wrote:
> On Wednesday, December 16, 2015 at 6:33:56 PM UTC+4, Chris Angelico wrote:
> > On Thu, Dec 17, 2015 at 1:21 AM,   wrote:
> > > I tried also another code (see below) and without scaling by 20 quality 
> > > of recognition was very bad.
> > >
> > > from pytesseract import image_to_string
> > > from PIL import Image
> > >
> > > im = Image.open("screen.png")
> > > print(im)
> > > im = im.resize((214*20,26*20), Image.ANTIALIAS)
> > > print(image_to_string(im))
> > 
> > If you need to scale by 20x20 to get the text recognition to work, I
> > would recommend using something other than an anti-alias filter. Omit
> > the second argument to use a simpler algorithm; you'll get a blocky
> > result, which might parse more cleanly for you.
> > 
> > ChrisA
> 
> It didn't help to recognize words, the main problem is that image is inclined 
> to the left, like backslash.

...and sometimes there are green horizontal lines above the image.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread fsn761304
On Wednesday, December 16, 2015 at 6:33:56 PM UTC+4, Chris Angelico wrote:
> On Thu, Dec 17, 2015 at 1:21 AM,   wrote:
> > I tried also another code (see below) and without scaling by 20 quality of 
> > recognition was very bad.
> >
> > from pytesseract import image_to_string
> > from PIL import Image
> >
> > im = Image.open("screen.png")
> > print(im)
> > im = im.resize((214*20,26*20), Image.ANTIALIAS)
> > print(image_to_string(im))
> 
> If you need to scale by 20x20 to get the text recognition to work, I
> would recommend using something other than an anti-alias filter. Omit
> the second argument to use a simpler algorithm; you'll get a blocky
> result, which might parse more cleanly for you.
> 
> ChrisA

It didn't help to recognize words, the main problem is that image is inclined 
to the left, like backslash.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread Chris Angelico
On Thu, Dec 17, 2015 at 1:21 AM,   wrote:
> I tried also another code (see below) and without scaling by 20 quality of 
> recognition was very bad.
>
> from pytesseract import image_to_string
> from PIL import Image
>
> im = Image.open("screen.png")
> print(im)
> im = im.resize((214*20,26*20), Image.ANTIALIAS)
> print(image_to_string(im))

If you need to scale by 20x20 to get the text recognition to work, I
would recommend using something other than an anti-alias filter. Omit
the second argument to use a simpler algorithm; you'll get a blocky
result, which might parse more cleanly for you.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread fsn761304
On Wednesday, December 16, 2015 at 6:18:00 PM UTC+4, Denis McMahon wrote:
> On Wed, 16 Dec 2015 06:04:37 -0800, fsn761304 wrote:
> 
> > 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
> 
> > image = image.resize((width*20,height*20), Image.ANTIALIAS)
> 
> This appears to attempt to extrapolate 400 pixels from each pixel in the 
> original image.
> 
> That only works on TV crime dramas, you can't do it in real life.
> 
> -- 
> Denis McMahon, denismfmcma...@gmail.com

I tried also another code (see below) and without scaling by 20 quality of 
recognition was very bad.

from pytesseract import image_to_string
from PIL import Image

im = Image.open("screen.png")
print(im)
im = im.resize((214*20,26*20), Image.ANTIALIAS)
print(image_to_string(im))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why my image is in bad quality ?

2015-12-16 Thread Denis McMahon
On Wed, 16 Dec 2015 06:04:37 -0800, fsn761304 wrote:

> 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

> image = image.resize((width*20,height*20), Image.ANTIALIAS)

This appears to attempt to extrapolate 400 pixels from each pixel in the 
original image.

That only works on TV crime dramas, you can't do it in real life.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Why my image is in bad quality ?

2015-12-16 Thread fsn761304
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)
-- 
https://mail.python.org/mailman/listinfo/python-list