here is code
Zdenko
po 29. 4. 2019 o 20:44 Zdenko Podobny <[email protected]> napísal(a):
> I did with python ;-)
>
>
> Zdenko
>
>
> po 29. 4. 2019 o 20:11 Philcat <[email protected]> napísal(a):
>
>> By the way, what application are you using to visualize the UZN?
>> Thanks
>>
>> On Sunday, April 28, 2019 at 2:24:41 PM UTC+2, zdenop wrote:
>>>
>>> Which mean if you create correct uzn file you will get what you need...
>>> Zdenko
>>>
>>>
>>> ne 28. 4. 2019 o 14:19 Zdenko Podobny <[email protected]> napísal(a):
>>>
>>>> Your uzn file is wrong. Did you tried to visualize?
>>>> [image: Load_visualize_uzn.png]
>>>> If I tried attached uzn file (tesseract Load.tiff - --psm 4) I got
>>>> this result:
>>>>
>>>> LOAD CONFIRMATION
>>>> Load# 11928
>>>> Date 02042019
>>>> Equipment Reefer
>>>> Equipment Length ~~ 53'
>>>> Temperature 55°F
>>>> Weight 28923 Ibs.
>>>> Commodity Dry Goods (Food)
>>>> Distance 328 miles
>>>>
>>>> 9393 W 110th Street
>>>> 51 Corporate Woods Suite 500 #5093
>>>> Overland Park, KS 66210
>>>> Docket: MC053431
>>>> Phone: 816.463.3060
>>>> Fax: 816.463.3039
>>>>
>>>> COYNE INC
>>>> 32830 IH 10 WEST
>>>> BOERNE, TX 75006
>>>> (3303319959
>>>>
>>>> RECEIVING / TRAFFIC
>>>> Phone: 717-218-5991
>>>> Email: carlsleordermat@metroscg. com
>>>>
>>>> Zdenko
>>>>
>>>>
>>>> ne 28. 4. 2019 o 10:20 Philcat <[email protected]> napísal(a):
>>>>
>>>>> Any suggestion? Provided example in the thread.
>>>>> Thanks
>>>>>
>>>>> On Friday, April 26, 2019 at 12:23:00 PM UTC+2, zdenop wrote:
>>>>>>
>>>>>> Provide testing case (image + uzn) + details about version of
>>>>>> tesseract language data.
>>>>>>
>>>>>> Zdenko
>>>>>>
>>>>>>
>>>>>> pi 26. 4. 2019 o 12:13 Philcat <[email protected]> napísal(a):
>>>>>>
>>>>>>> I am able to create a UZN file from rectangle coordinates drawn
>>>>>>> around text.
>>>>>>> Example (pretend the blue background is a rectangle):
>>>>>>>
>>>>>>> Unwanted text.
>>>>>>> This is the text I want
>>>>>>> It could be an address
>>>>>>> Mr. Smith
>>>>>>> 10 Fake Street
>>>>>>> Fake Town
>>>>>>> Phone: 123456 54545
>>>>>>> Email: [email protected]
>>>>>>> More unwanted text.
>>>>>>>
>>>>>>> The result I get will be something like:
>>>>>>>
>>>>>>> Unwanted text.
>>>>>>> This is the text I want
>>>>>>> It could be an address
>>>>>>> Mr. Smith
>>>>>>> 10 Fake Street
>>>>>>> Fake Town
>>>>>>>
>>>>>>> This would be the same for each line in the UZN file. How do I fix
>>>>>>> this without manually adjusting the UZN coordinates for each text box?
>>>>>>>
>>>>>>> Thanks.
>>>>>>>
>>>>>>> --
>>>>>>> You received this message because you are subscribed to the Google
>>>>>>> Groups "tesseract-ocr" group.
>>>>>>> To unsubscribe from this group and stop receiving emails from it,
>>>>>>> send an email to [email protected].
>>>>>>> To post to this group, send email to [email protected].
>>>>>>> Visit this group at https://groups.google.com/group/tesseract-ocr.
>>>>>>> To view this discussion on the web visit
>>>>>>> https://groups.google.com/d/msgid/tesseract-ocr/1b83b759-6e6b-4f83-b85f-609b8328e9be%40googlegroups.com
>>>>>>> <https://groups.google.com/d/msgid/tesseract-ocr/1b83b759-6e6b-4f83-b85f-609b8328e9be%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>> .
>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>
>>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "tesseract-ocr" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> To post to this group, send email to [email protected].
>>>>> Visit this group at https://groups.google.com/group/tesseract-ocr.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/tesseract-ocr/7a3e883c-2cb2-4523-ab0d-b399b468c71a%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/tesseract-ocr/7a3e883c-2cb2-4523-ab0d-b399b468c71a%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>> --
>> You received this message because you are subscribed to the Google Groups
>> "tesseract-ocr" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at https://groups.google.com/group/tesseract-ocr.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/tesseract-ocr/1c010363-77ea-4fee-a77d-a436b0cc067b%40googlegroups.com
>> <https://groups.google.com/d/msgid/tesseract-ocr/1c010363-77ea-4fee-a77d-a436b0cc067b%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
--
You received this message because you are subscribed to the Google Groups
"tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/tesseract-ocr.
To view this discussion on the web visit
https://groups.google.com/d/msgid/tesseract-ocr/CAJbzG8zfuwd0Xwow-H_p918H9%2BgigGtkuMa3Xq1vafxJ3odT0g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
#!/usr/bin/env python3.6
import matplotlib.pyplot as plt
from PIL import Image, ImageDraw, ImageFont
def contrastcolour(colour):
if colour[0] == '#':
colour = colour[1:]
rgb = (colour[0:2], colour[2:4], colour[4:6])
comp = ['%02X' % (255 - int(a, 16)) for a in rgb]
return ''.join(comp)
# get list of colors from matplotlib
prop_cycle = plt.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color']
font_size = 26
text_font = ImageFont.truetype('Roboto-Black.ttf', font_size)
padding = 1
im = Image.open("Load.tiff")
# load uzn
with open('Load.uzn') as f:
uzn_lines = f.read().splitlines()
tmp_uzn = Image.new('RGBA', im.size, (0,0,0,0))
draw = ImageDraw.Draw(tmp_uzn)
for idx, line in enumerate(uzn_lines):
coords = line.split(" ")
left = int(coords[0])
top = int(coords[1])
width = int(coords[2])
height = int(coords[3])
freetext = coords[4]
draw.rectangle(((left, top), (left+width, top+height)),
fill=colors[idx]+'99')
text_color = contrastcolour(colors[idx])
draw.text((left + padding, top + padding),
f"{freetext}{idx}", font=text_font, fill=f'#{text_color}')
uzn_img = Image.alpha_composite(im.convert("RGBA"), tmp_uzn)
uzn_img.save('Load_uzn.png')