forked from snakeotakon/BubbleOCR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin_BubbleOCR.py
3230 lines (2964 loc) · 137 KB
/
Plugin_BubbleOCR.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from gimpfu import *
from io import BytesIO
from string import Template
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
import codecs
import subprocess
import re
import glob
import inspect
import sys
import os
import traceback
import SimpleHTTPServer
import SocketServer
import HTMLParser
import cgi
import xml.etree.ElementTree as ET
import urllib
import threading
import tempfile
import datetime
import time
import ConfigParser
import multiprocessing
g_limitThreads=multiprocessing.cpu_count()
# s.lower() in ['true', '1', 't', 'y', 'yes', 'yeah', 'yup', 'certainly', 'uh-huh']
#Path Plugin GIMP
g_PathPlugin = os.path.dirname(inspect.getfile(inspect.currentframe()))
g_pathFileINI = os.path.join(g_PathPlugin , r"Config_BubbleOCR.ini")
os.chdir(g_PathPlugin)
g_imageTemp= r"_imgTemp_"
g_prefixName = u"OcrImage"
g_ExtensionOCR = u".png"
g_ExtensionWeb = u".jpg"
TXT=u".txt"
HOCR=u".hocr"
T_TXT=u"-T.txt"
OK = "ok.txt"
BText = "BText"#Tag balloon WHITE/EMPTY
CARRIAGERETURN="\r\n"
TAGPATHSTROKE=u"_PS_"
TAGPREFIXGROUP = u"G_"
g_nameDocument = u"MyDocument"
g_namePageHTML = "EditOCRText.html"
g_nameFileImageOCR = g_prefixName + g_ExtensionOCR
g_nameFileTXTOCR = g_prefixName
g_nameFileTranslation = g_prefixName + T_TXT
g_fileASS = "subtitle.ass"
g_fileAVS= "video.avs"
g_pathProyectWeb=""
g_pathProyectWeb_Images=""
g_typeFont=""
g_sizeFont=""
g_colorFont=""
g_thresholdWhiteBalloon=660 #86% threshold White for detection background
g_pathListImages=[] #listimages /images
g_port = 0
g_ip=""
g_translationweb=""
g_activeLayer = None
g_imageActive = None
g_programOCR=[]
g_pathTessdata=[]
g_navigators={}
g_argsOCR=[]
g_nameEngineOCRs=[]
g_translators=[]
g_Waifu2X=[]
g_scaleWaifu2x=2
g_noiseWaifu2x=3
class parameter:
indexEngineOCR=0
bWaifu2x=False
indexLanguageOCR=0
iOrientation=0
indexFix=0
caseOCR=0
bTranslation=False
caseTranslation=0
indexLanguageTranslation=0
nameProyect=""
pathProyect=""
indexEditor=0
iFilterBorder=0
bColorBalloonAutomatic=False #Detects color textballoon automatically, default white
pC=parameter()
g_bHocr=True #Information position text (HOCR)
g_srcCodeLanguage =""
g_targetCodeLanguage =""
g_srcLanguage =""
g_targetLanguage =""
g_bRepeatOCR=False
g_listWordsSplitImage = [] #["NO","No","no","YES","yes","To","TO","FOR","YOU"]
g_bMessageToConsole=True #message to console
g_notOCR=0
g_notExportedImage=0
g_notRemoveImageDetection = 0
#Divisions Image BETA
g_divisions=0
g_reductionIrregular = 0
g_thresholdBW = 0
g_areaSelection = 0
g_minLengthCharacter = 0
g_lettersOCR=""
g_replaceOCR=[]
g_replaceTarget=[]
g_listReplaceOCR=[]
g_listReplaceTarget=[]
g_aSelectionEditor = ""
aSelectionCase = ("none","lowercase", "UPPERCASE", "Capitalize", "Sentence")
aSelectionMain = ("Process only selection", "Process All layers/Path","Only Repeat OCR","Only Repeat Translation","Only Repeat Fix's","Only Edit Text","Update Text Translated","Load Proyect","Show Files Proyect","Show Files Plugins","Edit Config File INI","Refresh Languages OCR Engine")
defaultINI = r"""
[OCR TESSERACT]
programocr = "C:\Program Files\Tesseract-OCR\tesseract.exe"
pathtessdata= ""
argsocr="${NAMEFILEIMAGEOCR} ${NAMEFILEOUTOCR} --psm ${ORIENTATION} -l ${DESTLANGUAGEOCR} hocr"
[OCR TESSERACT x32]
programocr = "C:\Program Files (x86)\Tesseract-OCR\tesseract.exe"
pathtessdata= ""
argsocr="${NAMEFILEIMAGEOCR} ${NAMEFILEOUTOCR} --psm ${ORIENTATION} -l ${DESTLANGUAGEOCR} hocr"
[OCR TESSERACT PORTABLE]
programocr = "utils\OCR\tesseract4Beta.exe"
pathtessdata= "utils\OCR\tessdata"
argsocr="${NAMEFILEIMAGEOCR} ${NAMEFILEOUTOCR} --psm ${ORIENTATION} --tessdata-dir ${PATHTESSDATA} -l ${DESTLANGUAGEOCR} hocr"
[OCR CAPTURE2TEXT]
programocr = "utils\OCR\Capture2Text_CLI.exe"
pathtessdata= ""
argsocr="-l ${DESTLANGUAGEFULLOCR} -b -i ${NAMEFILEIMAGEOCR} -o ${NAMEFILEOUTOCR}.txt ${ORIENTATIONVERTICAL} "
[WAIFU2X CPP]
programwaifu2x = "utils\waifu2x\converter-cpp\waifu2x-converter-cpp.exe"
pathmodelswaifu2x = ""
argswaifu2x = "--noise-level {} --scale-ratio {}"
[WAIFU2X VULKAN]
programwaifu2x = "utils\waifu2x\ncnn-vulkan\waifu2x-ncnn-vulkan.exe"
pathmodelswaifu2x = ""
argswaifu2x = "-n {} -s {} -t 256"
[TRANSLATOR GOOGLE]
programtranslator = "utils\translator\deep-translator.exe"
[NAVIGATOR EDGE x86]
programweb = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
optionsweb = "-inprivate --start-maximized --user-data-dir="%appdata%\OCREdge""
[NAVIGATOR EDGE]
programweb = "C:\Program Files\Microsoft\Edge\Application\msedge.exe"
optionsweb = "-inprivate --start-maximized --user-data-dir="%appdata%\OCREdge""
[NAVIGATOR CHROME x86]
programweb = "C:\Program Files (x86)\google\chrome\application\chrome.exe"
optionsweb = "--new-window --incognito --start-maximized --user-data-dir="%appdata%\OCRChrome""
[NAVIGATOR CHROME]
programweb = "C:\Program Files\google\chrome\application\chrome.exe"
optionsweb = "--new-window --incognito --start-maximized --user-data-dir="%appdata%\OCRChrome""
[REPLACE OCR ENGLISH]
filetext1 = "utils\list_replace_characters_english.txt"
fileregex1 = "utils\list_Cleanup_All.txt"
[REPLACE OCR SPANISH]
filetext1 = ""
fileregex1 = "utils\list_Cleanup_All.txt"
[REPLACE OCR JAPANESE VERT]
filetext1=
fileregex1 = "utils\list_Cleanup_All.txt"
[REPLACE OCR JAPANESE]
filetext1=
fileregex1 = "utils\list_Cleanup_All.txt"
[REPLACE TRANSLATION SPANISH]
filetext1=""
fileregex1 = "utils\list_Cleanup_All.txt"
[CONFIGURATION]
ip=127.0.0.1
port = 8000
font = Arial
sizefont = 28
translationweb =
noisewaifu2x = 3
scalewaifu2x = 2
[DEBUG]
hocr=1
notexportedimage=0
notocr=0
notremoveimagedetection=0
messageconsole=0
"""
headASS = r"""[Script Info]
; Script generated by Aegisub 3.2.2
; http://www.aegisub.org/
PlayResX: 640
PlayResY: 480
YCbCr Matrix: None
WrapStyle: 0
ScaledBorderAndShadow: no
[Aegisub Project Garbage]
Last Style Storage: Default
Video File: video.avs
Video AR Value: 1
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Translate,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,9,10,10,10,1
Style: OCR,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,3,10,10,10,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
"""
headAVS=r"""
global Width=640
global Height=480
global fps=24
global AspectGlobal = 1.0*Width/Height
function ImageOCR (name)
{
c=ImageReader(name, start=0, end=23, fps=fps)
Global AspectImage=1.0*c.Width/c.Height
Img= ( AspectImage>=AspectGlobal ) ? c.BilinearResize(Width,int(Width/AspectImage)) : c.BilinearResize(int(Height*AspectImage),Height)
BorderLeft=0
BorderTop=Height-Img.Height
BorderRight=Width-Img.Width
BorderBottom=0
return Img.AddBorders(BorderLeft, BorderTop, BorderRight, BorderBottom, color=$000000)
}
"""
sHTA = r"""<!DOCTYPE html>
<HTML>
<meta http-equiv="x-ua-compatible" content="ie=11" content="text/html" charset="UTF-8">
<script type="text/javascript" src="ListFilesImage.js"></script>
<SCRIPT LANGUAGE="javascript">
document.documentElement.lang = languageSource;
//isHTA=(window.location.protocol!="http:")
var isHTA = (window.external == null)
var aOTextAreaOCR = []
//Array textArea OCR
var aOTextAreaTranslated = []
//Array textArea Translated
var aDivTranslated = []
//Array preTranslates
</SCRIPT>
<HEAD>
<link href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABAAQMAAACQp+OdAAAABlBMVEVRvwEKuFF1eVo5AAAAAXRSTlMAQObYZgAAASFJREFUKM9lkbFOAzEMhm1FIhtZGRB5hXZjQHevVLYOkbiNBYkXQDwJw6EOXSpegfQNglgyRGfs2EUVnOTk0zmxf/8BiA0AwgIwckCkc+gphjtAyhAEAjWFkUjh4ZtmAVwgZgFXwRUBnwGrQJgAEsNV5ILDhSzSgoPvcwtOw5bDC1SBmZfC4U6AWeMPvFd/rJx3uxa+msD+8nr9IvDhb/FJ4OBX2P8c3ArbxqBu7Eyxw+teZ/96c/92Kii38MgtpM7/7qown0v9Fd9sHOweSnqxkf2nmRCeZ7Ulnowa2Dov1iUkNbM6IpoCYPHUDXc5PFJl8HMEmhnCNOgzRUj6cEOXwZCw6OPWrlKEdnEC3XSBqDtsB4OUDMZqEItBsDI6LH8/eLeIjMFBtLwAAAAASUVORK5CYII=" rel="icon" type="image/png" />
<HTA:APPLICATION ID="oApp" APPLICATIONNAME="OCR TEXT" BORDER="thick" CAPTION="yes" SHOWINTASKBAR="yes" SINGLEINSTANCE="no" SYSMENU="yes" WINDOWSTATE="normal" SCROLL="yes" SCROLLFLAT="yes" VERSION="1.0" INNERBORDER="yes" SELECTION="yes" MAXIMIZEBUTTON="yes" MINIMIZEBUTTON="yes" NAVIGABLE="yes" CONTEXTMENU="yes" BORDERSTYLE="normal"/>
<style>
html, body {
height: 100%;
}
img {
max-width: 100%;
max-height: 100%;
display: block;
}
th, td {
width: auto;
padding: 5px;
border: 1px solid gray;
}
a:link {
color: #00d900;
background-color: transparent;
text-decoration: none;
}
a:visited {
color: yellow;
background-color: transparent;
text-decoration: none;
}
#idArrow {
position: absolute;
offset-position: 100 300;
top: -100px;
left: 0px;
height: auto;
width: auto;
background-color: white;
font: 36px;
border: 2px solid blue;
display: inline-block;
opacity: 90%;
transform: rotate(0deg);
}
.divleft {
width: 100%;
height: 100%;
float: left;
top: 60px;
}
#idPanelLeft {
width: 60%;
height: 100%;
/*display: inline-block;*/
}
#idPanelRight {
position: fixed ;
right:0px;
top:35px;
width: 35%;
height: 90%;
max-width: 100%;
max-height: 100%;
display: inline-block;
z-index:1;
border: 0px solid yellow;
}
.headers {
width: 100%;
top: 0px;
left: 0px;
height: 15px;
position: fixed;
padding: 10px 5px;
background-color: #5F5F5F;
z-index:2
}
.divLeftUp {
position: fixed;
top: 35px;
left: 5px;
height: 50%;
width: 64%;
max-width: 100%;
max-height: 100%;
background-color: white;
opacity: 100%;
border: 0px solid blue;
}
#idTitlepage{
display: inline-block;
}
.divRight {
position: relative ;
right: 0px;
top: 0px;
width: 100%;
height:100%;
border: 0px solid green;
}
.divElements {
border: 1px solid gray;
display: inline-block;
width: auto;
height: auto;
vertical-align: middle;
padding: 4px;
}
.divElementsSlider {
display: inline-block;
position: absolute;
padding: 0px;
width: 100%;
}
.divElementsSliderPreview {
display:none;
position: absolute;
left: 400px;
top: 10px;
border: 1px solid gray;
}
.areaReplace {
height: 100%;
width: 98%;
overflow-x: scroll;
white-space: pre ;
}
.divTopLeft {
height: 55%;
}
#idTextTranslated {
position: absolute;
display:none;
}
textarea {
width: 100%;
height: 100%;
autocomplete: on;
spellcheck: false;
autocapitalize: sentences;
}
.hidden {
display: none;
}
.cellTranslation {
width: 25%;
height: 150px;
}
.preTranslator {
width: 250px;
height: 100%;
overflow: auto;
background-color: #F4F4F4
}
#myProgress {
width: 10%;
float: right;
right: 40px;
top: 10px;
border: 1px solid black;
}
#myBar {
float: left;
width: 0%;
height: 20px;
background-color: #4CAF50;
text-align: left;
margin: auto;
color: white;
font-size: 100%;
opacity: 50%;
border: 1px white;
}
#idTitleNumberbar {
float: left;
width: 300px
}
#idNameImage {
float: right;
display: inline-block;
width: auto;
display: inline-block;
text-align: center;
color: white;
padding: 0px 4px;
border: 1px solid black;
}
#idNext {
position: absolute;
display: inline-block;
width: auto;
right: 0px;
display: inline-block;
text-align: center;
background-color: white;
padding: 10px 10px;
opacity: 0.6;
border: 1px solid black;
cursor: pointer;
}
#idPrev {
position: absolute;
display: inline-block;
width: auto;
left: 0px;
display: inline-block;
text-align: center;
background-color: white;
padding: 10px 10px;
opacity: 0.6;
border: 1px solid black;
cursor: pointer;
}
#IdpageImage {
position: absolute;
display: inline-block;
width: auto;
left: 80px;
display: inline-block;
text-align: center;
background-color: white;
opacity: 0.8;
border: 1px solid black;
}
input[type="range"] {
}
.titletable {
display: inline-block;
width: 24%;
text-align: center;
color: white;
background-color: #5F5F5F;
}
</style>
</HEAD>
<BODY>
<div class="headers skiptranslate" style="text-align:center ">
<button style="float: left;" type="button" onclick="SaveFiles()">Accept / Save Changes</button>
<div id="myProgress">
<div id="myBar">
<div id="idTitleNumberbar"></div>
</div>
</div>
<div id="idNameImage">Names Images</div>
<button style="float: right;margin: 0px 20px" type="button" onclick="previewImage()">Preview</button>
<div id="idTitlepage">
<strong><a href="https://github.com/snakeotakon/BubbleOCR" target="_blank" title="Homepage" style="color: white"> BubbleOCR 2.2 </a></strong>
<a href="https://lens.google.com/search?p" target="_blank" title="Copy image and in Google Lens Control+v for paste image(side right) "> Google Lens </a> <font color="#FFFFFF">
<a href="https://www.deepl.com/translator" target="_blank"> Deepl -</a>
<a href="https://translate.google.com/" target="_blank"> Google -</a>
<a href="https://www.bing.com/translator" target="_blank"> Bing -</a>
<a href="https://translate.yandex.com/" target="_blank"> Yandex -</a>
<a href="https://mymemory.translated.net/" target="_blank"> Mymemory -</a>
<a href="https://mt.qcri.org/api/" target="_blank"> Qcri -</a>
<a href="https://papago.naver.com/" target="_blank"> Papago -</a>
<a href="https://libretranslate.com/" target="_blank"> LibreTranslate -</a>
</font>
</diV>
</div>
<form enctype="multipart/form-data" method="post" name="formTextOCRTranslations" id="idformTextOCRTranslations" onsubmit=""></form>
<form enctype="multipart/form-data" method="post" name="myFormOK" id="idmyFormOK" onsubmit="">
<input type="hidden" name="ok.txt" value="ok">
</form>
<form enctype="multipart/form-data" method="post" name="myFormSaveSearch" id="idmyFormSaveSearch" onsubmit=""></form>
<div id="idPanelLeft">
<div class="divleft">
<div class="divTopLeft"></div>
<div style="height:auto;">
<table id="idTableImageOCR" border="0" style="width:100%;height:100%"></table>
</div>
</div>
<div class="divLeftUp skiptranslate">
<div style="float: left; width: 45%;height:95%">
<img id="idViewPortImageOCR" src="" alt="Image OCR Selected">
</div>
<div style="float: right; width: 55%;height: 93%; ">
<div style="height: 100%; ">
<div style="height: 100%;width: 65%;display:inline-block;">
<textarea wrap="off" class="areaReplace" id="idAreaTextReplace" title="Perform the replacement based on a list of words, separated by a tab. It allows the use of regular expressions, and the flags are: gimsuy : g - Global search, i - Case-insensitive search, m - Multi-line search, s - Allows . to match newline characters,u - unicode; treat a pattern as a sequence of unicode code points. y - Perform a sticky search that matches starting at the current position in the target string." name="SavedSearch.txt" form="idmyFormSaveSearch"></textarea>
</div>
<div id="some_id" style="position: absolute;display:inline-block;width: 18%;border: 0px solid gray;">
<div class="divElements">
Word(s) Search
<input type="text" id="idWordSearh" style="width:100%">
<br>
Word(s) Replace
<input type="text" id="idWordReplaces" style="width:100%">
<span id="idSpanComments" style="display:none">
Comments
<input type="text" id="idComments">
</span>
<input type="button" value="Add words(s)" onclick="addWordtoReplace()">
RegEx
<input type="checkbox" id="idCheckRegEx" value="0">
<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions" target="_blank">? </a>
</div>
<div class="divElements">
Add
<select id="idHelpRegEx" name="Help RegEx" title="Help for change text" style="height: 100%;width:100%">
<option value="0"></option>
<option value="1">CLEAR ALL</option>
<option value="2">Join line break separated with(-)</option>
<option value="3">Join all lines break</option>
<option value="4">Remove spaces duplicates</option>
<option value="5">Remove all spaces</option>
<option value="6">Remove phrase small</option>
<option value="7">Remove space character special OCR</option>
<option value="8">Remove space begin line</option>
<option value="9">Add a point to the end of the line</option>
</select>
</div>
<div class="divElements">
<input type="radio" checked name="radioSelection" value="Selected">
Selected
<input type="radio" name="radioSelection" value="All">All
</div>
<div class="divElements">
<input type="radio" checked name="radioOCR" value="OCR">
OCR
<input type="radio" name="radioOCR" value="Translations">Translations
</div>
<div class="divElements">
Case
<select id="idChangeCase" name="ChangeCase" title="Change case">
<option value="0">None</option>
<option value="1">lowercase</option>
<option value="2">UPPERCASE</option>
<option value="3">Capitalize</option>
<option value="4" Title="The change text. After point.">Sentence</option>
</select>
</div>
<div class="divElements">
<button type="button" onclick="replaceText()">Replace Text</button>
<button type="button" onclick="saveSearch()">Save</button>
</div>
</div>
</div>
</div>
</div>
<div class="skiptranslate" style="top:50%; position:fixed;width:62%; ">
<div class="divElements" title="Show all lines">
<label>
<input type="checkbox" id="idShowLines" value="0" onclick="saveTextArea();createRowsForImageOCR()">Show all Lines
</label>
</div>
<div class="divElements" id="divUpdateTranslations" title="When activated, it allows automatic translations made by Chrome. You write on the left side and the translation on the right side is updated.">
<label>
<input type="checkbox" id="idUpdateTranslations" value="0">Update 🠊🠊🠊
</label>
</div>
<div class="divElementsSlider">
SizeFont<input type="range" id="idChangeSizeFont" min="0" max="400" value="20">
</div>
<br>
<div class="titletable" id="idTitle1">TEXT OCR </div>
<div class="titletable" id="idTitle2">IMAGE OCR</div>
<div class="titletable" id="idTitle3">TRANSLATIONS</div>
<div class="titletable" id="idTitle4" style="width:auto">Google/Edge</div>
</div>
</div>
<div id="idPanelRight" class="skiptranslate" >
<div class="divRight">
<div id="idTextTranslated"> </div>
<div id="idNext" title="ShortCut Key: Page Down" onclick="nextImage()">NEXT</div>
<div id="IdpageImage">
<input id="idrangePage" type="range" min="0" value="0"><div id="idNumberImages"> </div>
</div>
<div id="idChangeFontPreview" class="divElementsSliderPreview">
Font Size<input type="range" id="idChangeSizeFontPreview" min="1" max="300" value="100">
</div>
<div id="idPrev" title="ShortCut Key: Page Up" onclick="prevImage()">PREV</div>
<div id="idArrow">
<font size="36" color="#0000ff">↠</font>
</div>
<img id="idViewPortImage" src="" alt="Image Page" usemap="#workmap" onload="loadAreas()">
<map id="idMapImageViewport" name="workmap"></map>
</div>
</div>
<SCRIPT language="JavaScript">
var nameImageSelected = "";
var nameImageSelectedOCR = "";
var noFilesOCR = listImageOCR.length
var aTextOCR = new Array(noFilesOCR);
var aTextTranslated = new Array(noFilesOCR);
window.onload = onLoad;
document.body.onkeydown=keyEvent;
function keyEvent(e)
{
if (idPanelLeft.style.position == "fixed")
{
if (e.target.isContentEditable) return;
(e.ctrlKey==false && e.altKey==false && e.shiftKey==false && e.code=="ArrowLeft")&&prevImage();
(e.ctrlKey==false && e.altKey==false && e.shiftKey==false && e.code=="ArrowRight")&&nextImage();
}
(e.ctrlKey==false && e.altKey==false && e.shiftKey==false && e.code=="PageUp")&&prevImage();
(e.ctrlKey==false && e.altKey==false && e.shiftKey==false && e.code=="PageDown")&&nextImage();
}
function previewImage()
{
if (idPanelLeft.style.position != "fixed")
{
idArrow.style.display = "none";
idPanelLeft.style.position = "fixed";
idPanelRight.style.width = "100%";
idPanelRight.style.height = "auto";
idPanelRight.style.position="relative";
idNext.style.position="fixed";
idPrev.style.position="fixed";
IdpageImage.style.position="fixed";
idTextTranslated.style.display="inline-block"
idViewPortImage.style.width="100%"
idChangeFontPreview.style.display = "inline-block";
idTitlepage.style.display = "none";
updateDivText();
loadAreas();
}
else
{
idChangeFontPreview.style.display = "none";
idArrow.style.display = "inline-block";
idTitlepage.style.display = "inline-block";
//idPanelLeft.style.display = "inline-block";
idPanelLeft.style.position =""
idPanelRight.style.width = "35%";
idPanelRight.style.height = "90%";
idPanelRight.style.position="fixed";
idNext.style.position="absolute";
idPrev.style.position="absolute";
IdpageImage.style.position="absolute";
idTextTranslated.style.display="none";
idViewPortImage.style.width="auto";
loadAreas();
}
}
function loadAreas() {
//remove all areas the idMapImageViewport
while (idMapImageViewport.hasChildNodes()) {
idMapImageViewport.removeChild(idMapImageViewport.firstChild);
}
while (idTextTranslated.hasChildNodes()) {
idTextTranslated.removeChild(idTextTranslated.firstChild);
}
//remove http://zzz/images/07.jpg to 07, is name layer webp,png, gif in Gimp
var nameImagenRoot = getNameImageViewPortSRC().replace("images/", "")
for (var i = 0; i < noFilesOCR; i++) {
//regex= RegExp(nameImagenRoot+'.*/BTEXT_.*OCRImage',"i");
regex = RegExp('(.*)/BTEXT_.*OCRImage', "i");
var match = listImageOCR[i].match(regex);
if (match) {
//Remove ext ".jpg" (layers in gimp 01.jpg,02.jpg )
if (removeExtension(match[1]) == removeExtension(nameImagenRoot) || match[1] == removeExtension(nameImagenRoot)) {
var oArea = document.createElement("area");
var oText = document.createElement("div");
var boundBox, sizeFont;
info = readMapFileInfo(match[0] + ".info");
oArea.coords=info.coordXY;
boundBox=info.boundBox;
oArea.shape = "poly";
oArea.name = match[0];
oArea.onclick = focusTextAreaMap;
oArea.style.cursor = "pointer";
oArea.onmouseover = mouseOverTextAreaMap;
oText.setAttribute("name",match[0] );
oText.style.position="absolute";
oText.style.whiteSpace="pre-wrap"
oText.style.width=boundBox[2]-boundBox[0]+"px"
oText.style.height=boundBox[3]-boundBox[1]+"px"
oText.style.left=boundBox[0]+"px";
oText.style.top=boundBox[1]+"px";
oText.style.border="10px solid black";
oText.style.textAlign = "center";
//oText.style.textTransform = "uppercase";
oText.style.background="white"
oText.style.textShadow="-2px -2px 0 white,2px -2px 0 white,-2px 2px 0 white,2px 2px 0 white"
oText.style.fontSize=info.sizeFont * info.ratio*(idChangeSizeFontPreview.value/100) +"px"
oText.contentEditable="true"
oText.onkeyup=function (e){
nameTTxt = e.target.getAttribute("name") + "-T.txt";
document.getElementsByName(nameTTxt)[0].value=e.target.innerText;
}
idMapImageViewport.appendChild(oArea);
idTextTranslated.appendChild(oText);
}
}
}
updateDivText();
document.documentElement.scrollTop=1;
}
function updateWidthTitle() {
if (idTableImageOCR.children[0]) {
textW = "WIDTHpx".replace("WIDTH", idTableImageOCR.children[0].children[0].offsetWidth);
idTitle1.style.width = textW.replace("WIDTH", idTableImageOCR.children[0].children[0].offsetWidth);
idTitle2.style.width = textW.replace("WIDTH", idTableImageOCR.children[0].children[1].offsetWidth);
idTitle3.style.width = textW.replace("WIDTH", idTableImageOCR.children[0].children[2].offsetWidth);
idTitle4.style.width = textW.replace("WIDTH", idTableImageOCR.children[0].children[3].offsetWidth);
}
}
function removeExtension(text) {
return text.replace(/\.[^.$]+$/, '')
}
function mouseOverTextAreaMap(e) {
e.target.title = document.getElementById(e.target.name + ".png").parentElement.parentElement.children[2].children[0].value;
}
function focusTextAreaMap(e) {
//get name, find cellImageOCR->Row->CellTextArea->TextArea
document.getElementById(e.target.name + ".png").parentElement.parentElement.children[2].children[0].focus();
}
function focusOutAreaText(e) {
//Change Color not selected row
e.target.parentElement.parentElement.style.backgroundColor = "transparent"
}
function focusAreaText(e) {
//get name row = name imagen OCR
var oNodeAreaText = e.target;
changeImageSelectionOCR(oNodeAreaText.parentElement.parentElement.name)
//Change Color Selected row
oNodeAreaText.parentElement.parentElement.style.backgroundColor = "#f0f0f0"
document.documentElement.scrollTop = oNodeAreaText.offsetParent.offsetTop;
nameImagen = getNameImageRootChildren(oNodeAreaText.parentElement.parentElement.name)
changeImageViewPort(nameImagen)
//get name ID for extract number row
UpdateTitle(getNumerId(oNodeAreaText.id) + 1, listImageOCR.length)
}
function getNumerId(nameID) {
var myRe = /\d+$/;
var myArray = myRe.exec(nameID);
if (myArray)
return parseInt(myArray[0]);
else
return 0;
}
function updateTranslation(e) {
idNameTextAreaTranslated = e.target.id.replace("idareatextPreTranslator_", "idareatextTranslated_");
document.getElementById(idNameTextAreaTranslated).value = e.target.innerText
}
function UpdateTitle(number, Total) {
var elem = document.getElementById("idTitleNumberbar");
elem.innerHTML = number + "/" + Total;
}
function UpdateBar(number, Total) {
var elem = document.getElementById("myBar");
var width = (number / Total * 100).toFixed(2);
elem.style.width = (width > 100 ? 100 : width) + '%';
width = (number / Total * 100).toFixed(2)
}
function disabledComment() {
if ((document.getElementById("idCheckRegEx").checked))
document.getElementById("idSpanComments").style.display = "block";
else
document.getElementById("idSpanComments").style.display = "none";
}
function onLoad() {
document.getElementById("idHelpRegEx").addEventListener("change", addExamplesTextArea);
idChangeSizeFont.addEventListener("change", changeSizeFontAreaText);
idChangeSizeFontPreview.addEventListener("change", changeSizeFontPreview);
document.getElementById("idCheckRegEx").addEventListener("change", disabledComment);
document.getElementById("idAreaTextReplace").value = readFileText("SavedSearch.txt");
idrangePage.max = listImage.length - 1
idrangePage.addEventListener("change", function() {
changeImageViewPort(listImage[this.value]);
});
idrangePage.oninput = updateRangeText
updateRangeText()
nameImageSelected = listImage[0]
createRowsForImageOCR();
window.addEventListener('resize', resizeWindows);
changeImageViewPort(nameImageSelected)
if (isHTA) {
document.getElementById("divUpdateTranslations").style.display = "none"
document.getElementById("idTitle4").style.display = "none"
}
updateWidthTitle()
}
function changeSizeFontAreaText(e) {
changeSizeFont(e,'.changeFont')
}
function changeSizeFontPreview(e) {
//changeSizeFont(e,'.FontPreview')
loadAreas();
}
function changeSizeFont(e,name) {
changeStyle(name, 'fontSize', e.target.value+"px");
function changeStyle(selector, prop, val) {
var elems = document.querySelectorAll(selector);
Array.prototype.forEach.call(elems, function(ele) {
ele.style[prop] = val;
});
}
}
function addExamplesTextArea(e) {
var lineText = "";
switch (e.target.selectedIndex) {
case 1:
idAreaTextReplace.value = ""
return;
case 2:
lineText = "-[\\r\\n] g #Join line break separated with(-)";
break;
case 3:
lineText = "\\s+ g #Join all lines break and remove spaces";
break;
case 4:
lineText = "[ ]+ g #Remove spaces duplicates";
break;
case 5:
lineText = "[ ]+ g #Remove all spaces";
break;
case 6:
lineText = "^.{1,3}$ g #Remove phrase small (3 letters)";
break;
case 7:
lineText = "^$ g #Remove space character special OCR";
break;
case 8:
//Remove space begin line
lineText = "^[ ] gm #Remove space begin line";
break;
case 9:
//add a point to the end of the line
lineText = "([^.])$ $1. gm #add point end line";
break;
default:
break;
}
addLineTextAreaReplace(lineText);
}
function addWordtoReplace() {
oIdWordSearh = document.getElementById("idWordSearh")
oIdWordReplaces = document.getElementById("idWordReplaces")
oIdComments = document.getElementById("idComments")
oIdCheckRegEx = document.getElementById("idCheckRegEx")
if (oIdCheckRegEx.checked) {
var comments = "";
if (oIdComments.value != comments)
comments = "\t#" + oIdComments.value
lineText = oIdWordSearh.value + "\t" + oIdWordReplaces.value + "\t" + "g" + comments
} else {
lineText = oIdWordSearh.value + "\t" + oIdWordReplaces.value
}
addLineTextAreaReplace(lineText)
oIdWordSearh.focus();
oIdWordSearh.value = "";
oIdWordReplaces.value = "";
}
function addLineTextAreaReplace(lineText) {
var textArea = document.getElementById("idAreaTextReplace").value
if (textArea == "") {
textArea = lineText;
} else {
textArea = textArea + "\r\n" + lineText;
}
document.getElementById("idAreaTextReplace").value = textArea;
}
function selectionRow(e) {
if (e.target.tagName == "TD") {
oNodeCell = e.target
oNodeRow = oNodeCell.parentElement
} else {
oNodeCell = e.target.parentElement
oNodeRow = oNodeCell.parentElement