gif file to translate into text
#1
Question 
Hi everybody.

I know my question can be strange... I made, some times ago, a French TV program based on a website parsing.
I was parsing many program informations and one of those was the time of the show. It used to be written as plain text :
21.15 (for a quarter past eleven )
but now, they use a picture showing the time. Parsing can't retrieve a text from this picture...

I would like to know, if one of you guys have got an idea on how to retrieve the time as plain text, from a gif file showing this time...
Here is an example :
21.15 : Image
an other url give us :
21.20 : Image
but I can get the same time from another url :
Image

I hope someone will find a trick to rretrieve text from pic file...

If you need more time pictures, you can get here :
http://telecable.lesagencestv.com/ (it is absolutely not an advertising, and furthermore it is a french website. You'll can catch pic time there)
Reply
#2
This might be an ass backward way to accomplish it, but atleast its a simple concept.. Gifs are lossy compressed palleted images. BMP's are simple to parse manually as far as a simple blocklike font goes.. (I've done this in other languages, you'll just need to map out similarities/differences of chars.)
So basically I'd convert the gifs to bmp's, then parse them as binary files (bmp format is all over.. Beyond the header who's size can vary depending on attributes, its a beautifully simple array of pixels)..

I found this on the net, and ripped some non xbox stuff out of it.. It should fit into your script easily enough with a bit of tinkering..
Quote:#!/usr/bin/env python

#This code will not work as is.. It can be easily modified to work on a single file, or group depending on your needs..
#For that matter it may not be compatible with xbmc although I'm nearly positive I've seen Image imported in other scripts
#Not at my xbox right now to try/test

import os, os.path, string, sys
import Image

openfile = '' # full pathname: dir(abs) + root + ext
indir = ''
outdir = ''
def getinfilename():
global openfile, indir
openfile = 'filename.ext' #Or variable
indir = os.path.dirname(openfile)

def getoutdirname():
global indir, outdir
indir = os.path.dirname(openfile)
outfile = 'filename.ext2' #Or variable
outdir = os.path.dirname(outfile)

def save(infile, outfile):
if infile != outfile:
try:
Image.open(infile).save(outfile)
except IOError:
print "Cannot convert", infile

def convert():
newext = 'ext2'
path, file = os.path.split(openfile)
base, ext = os.path.splitext(file)
ls = os.listdir(indir)
filelist = []
for f in ls:
if os.path.splitext(f)[1] == ext:
filelist.append(f)
filelist = [file]
for f in filelist:
infile = os.path.join(indir, f)
ofile = os.path.join(outdir, f)
outfile = os.path.splitext(ofile)[0] + newext
save(infile, outfile)
win = Toplevel(root)
Button(win, text='Done', command=win.destroy).pack()
Reply
#3
this is interesting, but quoting change identation... Can you please add somechars to show indentation ?
Code:
if True:
_print True
else:
_print False
_for a in range(10):
__print a
Reply
#4
#!/usr/bin/env python

#This code will not work as is.. It can be easily modified to work on a single file, or group depending on your needs..
#For that matter it may not be compatible with xbmc although I'm nearly positive I've seen Image imported in other scripts
#Not at my xbox right now to try/test

import os, os.path, string, sys
import Image

openfile = '' # full pathname: dir(abs) + root + ext
indir = ''
outdir = ''

def getinfilename():
_global openfile, indir
_openfile = 'filename.ext' #Or variable
_indir = os.path.dirname(openfile)

def getoutdirname():
_global indir, outdir
_indir = os.path.dirname(openfile)
_outfile = 'filename.ext2' #Or variable
_outdir = os.path.dirname(outfile)

def save(infile, outfile):
_if infile != outfile:
__try:
___Image.open(infile).save(outfile)
__except IOError:
___print "Cannot convert", infile

def convert():
_newext = 'ext2'
_path, file = os.path.split(openfile)
_base, ext = os.path.splitext(file)
_ls = os.listdir(indir)
_filelist = []
_for f in ls:
__if os.path.splitext(f)[1] == ext:
___filelist.append(f)
___filelist = [file]
__for f in filelist:
___infile = os.path.join(indir, f)
___ofile = os.path.join(outdir, f)
___outfile = os.path.splitext(ofile)[0] + newext
___save(infile, outfile)
Reply
#5
a better and more acurate way would be to get all the keys and what time they refer too, if you check the url there is: img_heure.php?key=cb1ed741f1

Think they call an php script that writes the time onto a blank gif using GD library and by the key value they get the time.. then draw a dynamic image..

maybe the key is an encoded timestamp or something..

also if you input a non valid key, the whole script crashes Big Grin
Reply
#6
trignum5 Wrote:#!/usr/bin/env python

#This code will not work as is.. It can be easily modified to work on a single file, or group depending on your needs..
#For that matter it may not be compatible with xbmc although I'm nearly positive I've seen Image imported in other scripts
#Not at my xbox right now to try/test

import os, os.path, string, sys
import Image

openfile = '' # full pathname: dir(abs) + root + ext
indir = ''
outdir = ''

def getinfilename():
_global openfile, indir
_openfile = 'filename.ext' #Or variable
_indir = os.path.dirname(openfile)

def getoutdirname():
_global indir, outdir
_indir = os.path.dirname(openfile)
_outfile = 'filename.ext2' #Or variable
_outdir = os.path.dirname(outfile)

def save(infile, outfile):
_if infile != outfile:
__try:
___Image.open(infile).save(outfile)
__except IOError:
___print "Cannot convert", infile

def convert():
_newext = 'ext2'
_path, file = os.path.split(openfile)
_base, ext = os.path.splitext(file)
_ls = os.listdir(indir)
_filelist = []
_for f in ls:
__if os.path.splitext(f)[1] == ext:
___filelist.append(f)
___filelist = [file]
__for f in filelist:
___infile = os.path.join(indir, f)
___ofile = os.path.join(outdir, f)
___outfile = os.path.splitext(ofile)[0] + newext
___save(infile, outfile)

cheers ! I will try soon

blittan Wrote:a better and more acurate way would be to get all the keys and what time they refer too, if you check the url there is: img_heure.php?key=cb1ed741f1

Think they call an php script that writes the time onto a blank gif using GD library and by the key value they get the time.. then draw a dynamic image..

maybe the key is an encoded timestamp or something..

also if you input a non valid key, the whole script crashes
I found some different code for the same time displayed...

I try to found any link between the value pass to the php script and the time displayed but nothing rised from my tests.
Right now, the Trignum5 solution may be the more appropriate.... Need some test to know.
Reply
#7
Hi
It has been a while since I succeeded, and I forgot to tell you about it !

So I can open gif file showing time and find textual time Smile

First I translate gif to bmp as data in bmp are very easy (1px = 1 color ; only 2 colors used black and white). Then I read the RFC of bmp formats. I seperated header from datas, and replaced hexa codes with a char. I then translated each numbers "ascii" encoded into md5 value and construct a dictionnary for each number from 1 to 9.

OK, not very easy to explain myself... Too poor english for that !

If you need it, just ask me, i'll give you sample code
Reply

Logout Mark Read Team Forum Stats Members Help
gif file to translate into text0