├── .gitignore
├── ChineseOCR
├── ChineseOCR.b4j
├── ChineseOCR.b4j.meta
├── ChineseOCRPlugin.bas
├── java
│ ├── .classpath
│ ├── .project
│ └── src
│ │ └── chineseocr
│ │ └── Main.java
└── readme.md
├── DynamsoftOCR
├── DynamsoftOCR.b4j
├── DynamsoftOCR.b4j.meta
└── DynamsoftOCRPlugin.bas
├── ExternalInpaint
├── ExternalInpaint.b4j
├── ExternalInpaint.b4j.meta
├── ExternalInpaintPlugin.bas
└── readme.md
├── ExternalMaskGen
├── ExternalMaskGen.b4j
├── ExternalMaskGen.b4j.meta
├── ExternalMaskGenPlugin.bas
└── readme.md
├── ImageTransOCR
├── ImageTransOCR.b4j
├── ImageTransOCR.b4j.meta
├── ImageTransOCRPlugin.bas
└── README.md
├── InsetRectMaskGen
├── InsetRectMaskGen.b4j
├── InsetRectMaskGenPlugin.bas
└── readme.md
├── LamaInpaint
├── LamaInpaint.b4j
├── LamaInpaintPlugin.bas
└── readme.md
├── PyRapidOCR
├── README.md
├── plugin
│ ├── PyRapidOCR.b4j
│ └── PyRapidOCRPlugin.bas
└── server
│ ├── server.py
│ └── www
│ └── index.html
├── README.md
├── RapidOCR
├── Localizator.bas
├── RapidOCR.b4j
├── RapidOCRPlugin.bas
└── readme.md
├── STTNInpaint
├── STTNInpaint.b4j
├── STTNInpaintPlugin.bas
└── readme.md
├── WinRTOCR
├── WinRTOCR.b4j
├── WinRTOCR.b4j.meta
└── WinRTOCRPlugin.bas
├── abbyycloudOCR
├── Localizator.bas
├── OCR.bas
├── abbyycloudOCR.b4j
├── abbyycloudOCR.b4j.meta
└── abbyycloudOCRPlugin.bas
├── aliMT
├── .classpath
├── .gitignore
├── .project
├── .settings
│ ├── org.eclipse.jdt.core.prefs
│ └── org.eclipse.m2e.core.prefs
├── pom.xml
├── src
│ └── main
│ │ └── java
│ │ └── alimt
│ │ └── Translator.java
└── target
│ └── classes
│ └── META-INF
│ ├── MANIFEST.MF
│ └── maven
│ └── com.xulihang
│ └── alimt
│ ├── pom.properties
│ └── pom.xml
├── chatGPTMT
├── chatGPTMT.b4j
├── chatGPTMTPlugin.bas
└── readme.md
├── chatGPTOCR
├── chatGPTOCR.b4j
└── chatGPTOCRPlugin.bas
├── cloudtranslationMT
├── cloudtranslationMT.b4j
├── cloudtranslationMT.b4j.meta
└── cloudtranslationMTPlugin.bas
├── clovaOCR
├── Localizator.bas
├── clovaOCR.b4j
├── clovaOCR.b4j.meta
└── clovaOCRPlugin.bas
├── copySourceToTargetAction
├── copySourceToTargetAction.b4j
├── copySourceToTargetActionPlugin.bas
└── copySourceToTargetPlugin.bas
├── crnnOCR
├── README.md
├── crnnOCR.b4j
├── crnnOCR.b4j.meta
└── crnnOCRPlugin.bas
├── deeplMT
├── deeplMT.b4j
├── deeplMT.b4j.meta
└── deeplMTPlugin.bas
├── deeplfreeMT
├── README.md
├── deeplfreeMT.b4j
├── deeplfreeMT.b4j.meta
└── deeplfreeMTPlugin.bas
├── deepseekMT
├── deepseekMT.b4j
└── deepseekMTPlugin.bas
├── doctrOCR
├── plugin
│ ├── doctrOCR.b4j
│ └── doctrOCRPlugin.bas
├── readme.md
└── server
│ ├── server.py
│ └── www
│ └── index.html
├── easyOCR
├── plugin
│ ├── easyOCR.b4j
│ ├── easyOCR.b4j.meta
│ └── easyOCRPlugin.bas
└── server
│ ├── server_easyocr.py
│ └── www
│ └── index.html
├── eztransMT
├── eztransMT.b4j
├── eztransMT.b4j.meta
└── eztransMTPlugin.bas
├── geminiMT
├── geminiMT.b4j
├── geminiMTPlugin.bas
└── readme.md
├── geminiOCR
├── geminiOCR.b4j
└── geminiOCRPlugin.bas
├── googleMT
├── googleMT.b4j
├── googleMT.b4j.meta
└── googleMTPlugin.bas
├── googleOCR
├── Utils.bas
├── googleOCR.b4j
├── googleOCR.b4j.meta
└── googleOCRPlugin.bas
├── googledriveOCR
├── commandline
│ ├── googledriveOCR.b4j
│ ├── googledriveOCR.b4j.meta
│ └── googledriveOCRPlugin.bas
├── readme.md
└── server
│ ├── googledriveOCR.b4j
│ ├── googledriveOCR.b4j.meta
│ └── googledriveOCRPlugin.bas
├── imgBaiduOCR
├── Localizator.bas
├── imgbaiduOCR.b4j
├── imgbaiduOCRPlugin.bas
└── readme.md
├── macOCR
├── macOCR.b4j
├── macOCRPlugin.bas
└── readme.md
├── mangaOCR
├── GPU.md
├── list.jpg
├── long_text.jpg
├── normal.jpg
├── plugin
│ ├── Localizator.bas
│ ├── mangaOCR.b4j
│ ├── mangaOCR.b4j.meta
│ └── mangaOCRPlugin.bas
├── readme.md
├── requirements.txt
└── server
│ ├── server_manga_ocr.py
│ └── www
│ └── index.html
├── mangaTranslatorOCR
├── GPU.md
├── README.md
├── engines.jpg
├── mangaTranslatorOCR.b4j
├── mangaTranslatorOCR.b4j.meta
└── mangaTranslatorOCRPlugin.bas
├── niutransMT
├── niuTransMTPlugin.bas
├── niutransMT.b4j
└── niutransMT.b4j.meta
├── ollamaGPTMT
├── ollamaMT.b4j
└── ollamaMTPlugin.bas
├── opusMT
├── opusMT.b4j
├── opusMT.b4j.meta
├── opusMTPlugin.bas
└── readme.md
├── paddleOCR
├── README.md
├── plugin
│ ├── paddleOCR.b4j
│ ├── paddleOCR.b4j.meta
│ └── paddleOCRPlugin.bas
└── server
│ ├── README.md
│ ├── server_paddleocr.py
│ ├── server_paddleocr3.py
│ └── www
│ ├── detect.html
│ └── index.html
├── pandaOCR
├── pandaOCR.b4j
├── pandaOCRPlugin.bas
└── readme.md
├── pororoOCR
├── plugin
│ ├── Localizator.bas
│ ├── pororoOCR.b4j
│ └── pororoOCRPlugin.bas
├── readme.md
└── server
│ ├── LICENSE
│ ├── main.py
│ ├── pororo
│ ├── __init__.py
│ ├── __version__.py
│ ├── models
│ │ └── brainOCR
│ │ │ ├── __init__.py
│ │ │ ├── _dataset.py
│ │ │ ├── _modules.py
│ │ │ ├── brainocr.py
│ │ │ ├── craft.py
│ │ │ ├── craft_utils.py
│ │ │ ├── detection.py
│ │ │ ├── imgproc.py
│ │ │ ├── model.py
│ │ │ ├── modules
│ │ │ ├── __init__.py
│ │ │ ├── basenet.py
│ │ │ ├── feature_extraction.py
│ │ │ ├── prediction.py
│ │ │ ├── sequence_modeling.py
│ │ │ └── transformation.py
│ │ │ ├── recognition.py
│ │ │ └── utils.py
│ ├── pororo.py
│ ├── tasks
│ │ ├── __init__.py
│ │ ├── optical_character_recognition.py
│ │ └── utils
│ │ │ ├── __init__.py
│ │ │ ├── base.py
│ │ │ ├── config.py
│ │ │ ├── download_utils.py
│ │ │ └── tokenizer.py
│ └── utils.py
│ ├── requirements.txt
│ ├── server_pororo_ocr.py
│ ├── utils
│ ├── __init__.py
│ └── image_util.py
│ └── www
│ └── index.html
├── port_settings.jpg
├── sogouOCR
├── BoxesSort.bas
├── Localizator.bas
├── OCR.bas
├── sogouOCR.b4j
├── sogouOCR.b4j.meta
└── sogouOCRPlugin.bas
├── sugoiMT
├── Readme.md
├── sugoiMT.b4j
├── sugoiMT.b4j.meta
└── sugoiMTPlugin.bas
├── tencentOCR
├── Localizator.bas
├── tencentOCR.b4j
├── tencentOCR.b4j.meta
└── tencentOCRPlugin.bas
├── transliterationMT
├── readme.md
├── transliterationMT.b4j
├── transliterationMT.b4j.meta
└── transliterationMTPlugin.bas
├── tsvMT
├── Readme.md
├── tsvMT.b4j
└── tsvMTPlugin.bas
├── volcanoMT
├── b4j
│ ├── volcanoMT.b4j
│ └── volcanoMTPlugin.bas
├── java
│ ├── .classpath
│ ├── .project
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── xulihang
│ │ │ └── volcmt
│ │ │ └── App.java
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── xulihang
│ │ └── volcmt
│ │ └── AppTest.java
└── readme.md
├── yandexMT
├── readme.md
├── yandexMT.b4j
└── yandexMTPlugin.bas
└── yomikakuOCR
├── readme.md
├── yomikakuOCR.b4j
├── yomikakuOCR.b4j.meta
└── yomikakuOCRPlugin.bas
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | Objects
3 | *.meta
4 | *.pyc
5 | *.zip
6 |
--------------------------------------------------------------------------------
/ChineseOCR/ChineseOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=jshell
6 | Library2=jfx
7 | Library3=json
8 | Library4=jxmlsax
9 | Library5=xmlbuilder
10 | Library6=jxui
11 | Library7=javaobject
12 | Library8=jokhttputils2
13 | Library9=jstringutils
14 | Module1=ChineseOCRPlugin
15 | NumberOfFiles=0
16 | NumberOfLibraries=10
17 | NumberOfModules=1
18 | Version=8.8
19 | @EndOfDesignText@
20 | #Region Project Attributes
21 | #MainFormWidth: 600
22 | #MainFormHeight: 600
23 | #End Region
24 |
25 | Sub Process_Globals
26 | Private fx As JFX
27 | Public MainForm As Form
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim n As ChineseOCRPlugin
35 | n.Initialize
36 | wait for (n.GetText(fx.LoadImage(File.DirApp,"image.jpg"),"chi_sim")) Complete (text As String)
37 | wait for (n.GetTextWithLocation(fx.LoadImage(File.DirApp,"image.jpg"),"chi_sim")) Complete (result As List)
38 | Log(text)
39 | Log(result)
40 | 'wait for (n.translate("Hello","en","zh")) complete (result As String)
41 | 'Log(result)
42 | End Sub
43 |
44 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
45 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
46 | Return True
47 | End Sub
48 |
--------------------------------------------------------------------------------
/ChineseOCR/ChineseOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=ChineseOCRPlugin,getLangs,51,6,Main,Application_Error,28,0,ChineseOCRPlugin,DetectOS,173,0,ChineseOCRPlugin,Run,37,5,ChineseOCRPlugin,GetText,52,0,ChineseOCRPlugin,GetTextWithLocation,68,6,ChineseOCRPlugin,ocr,115,6,ChineseOCRPlugin,readJsonAsMap,184,0,ChineseOCRPlugin,Initialize,11,0,ChineseOCRPlugin,GetNiceName,13,0
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/ChineseOCR/java/.classpath:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/ChineseOCR/java/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | chineseocr
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 |
15 | org.eclipse.jdt.core.javanature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/ChineseOCR/readme.md:
--------------------------------------------------------------------------------
1 | See
--------------------------------------------------------------------------------
/DynamsoftOCR/DynamsoftOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=jshell
6 | Library2=jfx
7 | Library3=json
8 | Library4=jxmlsax
9 | Library5=xmlbuilder
10 | Library6=jxui
11 | Library7=javaobject
12 | Library8=jokhttputils2
13 | Library9=jstringutils
14 | Module1=DynamsoftOCRPlugin
15 | NumberOfFiles=0
16 | NumberOfLibraries=10
17 | NumberOfModules=1
18 | Version=8.8
19 | @EndOfDesignText@
20 | #Region Project Attributes
21 | #MainFormWidth: 600
22 | #MainFormHeight: 600
23 | #End Region
24 |
25 | Sub Process_Globals
26 | Private fx As JFX
27 | Public MainForm As Form
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim n As DynamsoftOCRPlugin
35 | n.Initialize
36 | wait for (n.GetText(fx.LoadImage(File.DirApp,"dlr-sample-retail.png"),"chi_sim")) Complete (text As String)
37 | wait for (n.GetTextWithLocation(fx.LoadImage(File.DirApp,"dlr-sample-retail.png"),"chi_sim")) Complete (result As List)
38 | Log(text)
39 | Log(result)
40 | 'wait for (n.translate("Hello","en","zh")) complete (result As String)
41 | 'Log(result)
42 | End Sub
43 |
44 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
45 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
46 | Return True
47 | End Sub
48 |
--------------------------------------------------------------------------------
/DynamsoftOCR/DynamsoftOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=DynamsoftOCRPlugin,GetText,37,0,DynamsoftOCRPlugin,LangHasSpace,58,0,DynamsoftOCRPlugin,GetTextWithLocation,43,1,DynamsoftOCRPlugin,readJsonAsMap,157,0,DynamsoftOCRPlugin,Run,33,0,DynamsoftOCRPlugin,GetNiceName,13,0,Main,AppStart,18,1,DynamsoftOCRPlugin,ocr,91,6,DynamsoftOCRPlugin,Data2Map,131,6,DynamsoftOCRPlugin,Class_Globals,0,0
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/ExternalInpaint/ExternalInpaint.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library2=jfx
6 | Library3=json
7 | Library4=jxmlsax
8 | Library5=xmlbuilder
9 | Library6=jxui
10 | Library7=javaobject
11 | Library8=jokhttputils2
12 | Library9=jstringutils
13 | Module1=ExternalInpaintPlugin
14 | NumberOfFiles=0
15 | NumberOfLibraries=9
16 | NumberOfModules=1
17 | Version=8.9
18 | @EndOfDesignText@
19 | #Region Project Attributes
20 | #MainFormWidth: 600
21 | #MainFormHeight: 600
22 | #End Region
23 |
24 | Sub Process_Globals
25 | Private fx As JFX
26 | Public MainForm As Form
27 |
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim n As ExternalInpaintPlugin
35 | n.Initialize
36 | Dim origin As Image=fx.LoadImage(File.DirApp,"1.jpg")
37 | Dim mask As Image=fx.LoadImage(File.DirApp,"mask.png")
38 | wait for (n.inpaint(origin,mask)) complete (result As B4XBitmap)
39 | Dim out As OutputStream
40 | out=File.OpenOutput(File.DirApp,"removed.jpg",False)
41 | result.WriteToStream(out,100,"JPEG")
42 | out.Close
43 | End Sub
44 |
45 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
46 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
47 | Return True
48 | End Sub
49 |
--------------------------------------------------------------------------------
/ExternalInpaint/ExternalInpaint.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=ExternalInpaintPlugin,GetNiceName,13,0,Main,AppStart,15,1,ExternalInpaintPlugin,Class_Globals,0,0,ExternalInpaintPlugin,getDefaultSettings,36,0,ExternalInpaintPlugin,inpaint,65,6,ExternalInpaintPlugin,Run,28,6
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/ExternalInpaint/ExternalInpaintPlugin.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=Class
5 | Version=4.2
6 | @EndOfDesignText@
7 | Sub Class_Globals
8 | Private fx As JFX
9 | End Sub
10 |
11 | 'Initializes the object. You can NOT add parameters to this method!
12 | Public Sub Initialize() As String
13 | Log("Initializing plugin " & GetNiceName)
14 | ' Here return a key to prevent running unauthorized plugins
15 | Return "MyKey"
16 | End Sub
17 |
18 | ' must be available
19 | public Sub GetNiceName() As String
20 | Return "ExternalInpaint"
21 | End Sub
22 |
23 | ' must be available
24 | public Sub Run(Tag As String, Params As Map) As ResumableSub
25 | Log("run"&Params)
26 | Select Tag
27 | Case "getParams"
28 | Dim paramsList As List
29 | paramsList.Initialize
30 | paramsList.Add("url")
31 | Return paramsList
32 | Case "inpaint"
33 | wait for (inpaint(Params.Get("origin"),Params.Get("mask"),Params.GetDefault("settings",getDefaultSettings))) complete (result As B4XBitmap)
34 | Return result
35 | Case "getDefaultParamValues"
36 | Return getDefaultSettings
37 | End Select
38 | Return ""
39 | End Sub
40 |
41 |
42 | Private Sub getDefaultSettings As Map
43 | Return CreateMap("url":"http://127.0.0.1:8080/gettxtremoved")
44 | End Sub
45 |
46 |
47 | Sub inpaint(origin As B4XBitmap,mask As B4XBitmap,settings As Map) As ResumableSub
48 | Dim out As OutputStream
49 | out=File.OpenOutput(File.DirApp,"origin.jpg",False)
50 | origin.WriteToStream(out,"100","JPEG")
51 | out.Close
52 | Dim out As OutputStream
53 | out=File.OpenOutput(File.DirApp,"mask.png",False)
54 | mask.WriteToStream(out,"100","PNG")
55 | out.Close
56 |
57 | Dim job As HttpJob
58 | job.Initialize("",Me)
59 |
60 | Dim originFd As MultipartFileData
61 | originFd.Initialize
62 | originFd.KeyName = "origin"
63 | originFd.Dir = File.DirApp
64 | originFd.FileName = "origin.jpg"
65 | originFd.ContentType = "image/jpg"
66 |
67 | Dim maskFd As MultipartFileData
68 | maskFd.Initialize
69 | maskFd.KeyName = "mask"
70 | maskFd.Dir = File.DirApp
71 | maskFd.FileName = "mask.png"
72 | maskFd.ContentType = "image/png"
73 |
74 | job.PostMultipart(settings.GetDefault("url","http://127.0.0.1:8080/gettxtremoved"),Null, Array(originFd,maskFd))
75 | job.GetRequest.Timeout=240*1000
76 | Wait For (job) JobDone(job As HttpJob)
77 | If job.Success Then
78 | Try
79 | Dim result As B4XBitmap=job.GetBitmap
80 | Return result
81 | Catch
82 | Log(LastException)
83 | End Try
84 | End If
85 | job.Release
86 | Return origin
87 | End Sub
88 |
--------------------------------------------------------------------------------
/ExternalInpaint/readme.md:
--------------------------------------------------------------------------------
1 | Use this plugin to use external inpainters like Sickzil-Machine and manga translator.
--------------------------------------------------------------------------------
/ExternalMaskGen/ExternalMaskGen.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=javaobject
5 | Library10=jbitmapcreator
6 | Library2=jcore
7 | Library3=jfx
8 | Library4=jokhttputils2
9 | Library5=json
10 | Library6=jstringutils
11 | Library7=jxmlsax
12 | Library8=jxui
13 | Library9=xmlbuilder
14 | Module1=ExternalMaskGenPlugin
15 | NumberOfFiles=0
16 | NumberOfLibraries=10
17 | NumberOfModules=1
18 | Version=8.9
19 | @EndOfDesignText@
20 | #Region Project Attributes
21 | #MainFormWidth: 600
22 | #MainFormHeight: 600
23 | #End Region
24 |
25 | Sub Process_Globals
26 | Private fx As JFX
27 | Public MainForm As Form
28 |
29 | End Sub
30 |
31 | Sub AppStart (Form1 As Form, Args() As String)
32 | MainForm = Form1
33 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
34 | MainForm.Show
35 | Dim settings As Map
36 | settings.Initialize
37 | Dim n As ExternalMaskGenPlugin
38 | n.Initialize
39 | Dim img As Image=fx.LoadImage(File.DirApp,"1.jpg")
40 | wait for (n.genMask(img,settings)) complete (result As B4XBitmap)
41 | Dim out As OutputStream
42 | out=File.OpenOutput(File.DirApp,"mask.png",False)
43 | result.WriteToStream(out,100,"PNG")
44 | out.Close
45 | End Sub
46 |
47 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
48 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
49 | Return True
50 | End Sub
51 |
--------------------------------------------------------------------------------
/ExternalMaskGen/ExternalMaskGen.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=ExternalMaskGenPlugin,Initialize,6,0,ExternalMaskGenPlugin,GetNiceName,13,0,Main,AppStart,11,0,Main,Process_Globals,6,0,ExternalMaskGenPlugin,Class_Globals,0,0,ExternalMaskGenPlugin,emptyMask,60,6,ExternalMaskGenPlugin,genMask,50,5
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/ExternalMaskGen/ExternalMaskGenPlugin.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=Class
5 | Version=4.2
6 | @EndOfDesignText@
7 | Sub Class_Globals
8 | Private fx As JFX
9 | End Sub
10 |
11 | 'Initializes the object. You can NOT add parameters to this method!
12 | Public Sub Initialize() As String
13 | Log("Initializing plugin " & GetNiceName)
14 | ' Here return a key to prevent running unauthorized plugins
15 | Return "MyKey"
16 | End Sub
17 |
18 | ' must be available
19 | public Sub GetNiceName() As String
20 | Return "ExternalMaskGen"
21 | End Sub
22 |
23 | ' must be available
24 | public Sub Run(Tag As String, Params As Map) As ResumableSub
25 | Log("run"&Params)
26 | Select Tag
27 | Case "getParams"
28 | Dim paramsList As List
29 | paramsList.Initialize
30 | paramsList.Add("url")
31 | Return paramsList
32 | Case "getDefaultParamValues"
33 | Return getDefaultSettings
34 | Case "genMask"
35 | wait for (genMask(Params.Get("img"),Params.GetDefault("settings",getDefaultSettings))) complete (result As B4XBitmap)
36 | Return result
37 | End Select
38 | Return ""
39 | End Sub
40 |
41 | Private Sub getDefaultSettings As Map
42 | Return CreateMap("url":"http://127.0.0.1:8080/getmask")
43 | End Sub
44 |
45 | Sub genMask(img As B4XBitmap,settings As Map) As ResumableSub
46 | Dim out As OutputStream
47 | out=File.OpenOutput(File.DirApp,"image.jpg",False)
48 | img.WriteToStream(out,"100","JPEG")
49 | out.Close
50 | Dim job As HttpJob
51 | job.Initialize("",Me)
52 | Dim fd As MultipartFileData
53 | fd.Initialize
54 | fd.KeyName = "upload"
55 | fd.Dir = File.DirApp
56 | fd.FileName = "image.jpg"
57 | fd.ContentType = "image/jpg"
58 | job.PostMultipart(settings.GetDefault("url","http://127.0.0.1:8080/getmask"),Null, Array(fd))
59 | job.GetRequest.Timeout=240*1000
60 | Wait For (job) JobDone(job As HttpJob)
61 | If job.Success Then
62 | Try
63 | Dim result As B4XBitmap=job.GetBitmap
64 | Return result
65 | Catch
66 | Log(LastException)
67 | End Try
68 | Else
69 | Log(job.ErrorMessage)
70 | End If
71 | job.Release
72 | Return emptyMask(img)
73 | End Sub
74 |
75 | Private Sub emptyMask(img As B4XBitmap) As B4XBitmap
76 | Dim bc As BitmapCreator
77 | bc.Initialize(img.Width,img.Height)
78 | Return bc.Bitmap
79 | End Sub
80 |
--------------------------------------------------------------------------------
/ExternalMaskGen/readme.md:
--------------------------------------------------------------------------------
1 | Use this plugin to use external mask generators like Sickzil-Machine and manga translator.
--------------------------------------------------------------------------------
/ImageTransOCR/ImageTransOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library2=jfx
6 | Library3=json
7 | Library4=jxmlsax
8 | Library5=xmlbuilder
9 | Library6=jxui
10 | Library7=javaobject
11 | Library8=jokhttputils2
12 | Library9=jstringutils
13 | Module1=ImageTransOCRPlugin
14 | NumberOfFiles=0
15 | NumberOfLibraries=9
16 | NumberOfModules=1
17 | Version=8.8
18 | @EndOfDesignText@
19 | #Region Project Attributes
20 | #MainFormWidth: 600
21 | #MainFormHeight: 600
22 | #End Region
23 |
24 | Sub Process_Globals
25 | Private fx As JFX
26 | Public MainForm As Form
27 |
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim n As ImageTransOCRPlugin
35 | n.Initialize
36 | Dim img As B4XBitmap=fx.LoadImage(File.DirApp,"ddd.jpg")
37 | wait for (n.GetText(img,"en")) complete (result As Object)
38 | Log(result)
39 | End Sub
40 |
41 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
42 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
43 | Return True
44 | End Sub
45 |
--------------------------------------------------------------------------------
/ImageTransOCR/ImageTransOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=ImageTransOCRPlugin,getUrl,126,0,Main,AppStart,15,0,ImageTransOCRPlugin,GetNiceName,17,0,ImageTransOCRPlugin,Initialize,16,6,ImageTransOCRPlugin,GetTextWithLocation,106,2,ImageTransOCRPlugin,GetText,87,6,ImageTransOCRPlugin,BuildCombinations,79,6,ImageTransOCRPlugin,ocr,137,6,ImageTransOCRPlugin,Class_Globals,9,6,ImageTransOCRPlugin,Run,46,6
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/ImageTransOCR/README.md:
--------------------------------------------------------------------------------
1 | See
--------------------------------------------------------------------------------
/InsetRectMaskGen/InsetRectMaskGen.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=javaobject
5 | Library10=jbitmapcreator
6 | Library2=jcore
7 | Library3=jfx
8 | Library4=jokhttputils2
9 | Library5=json
10 | Library6=jstringutils
11 | Library7=jxmlsax
12 | Library8=jxui
13 | Library9=xmlbuilder
14 | Module1=InsetRectMaskGenPlugin
15 | NumberOfFiles=0
16 | NumberOfLibraries=10
17 | NumberOfModules=1
18 | Version=8.9
19 | @EndOfDesignText@
20 | #Region Project Attributes
21 | #MainFormWidth: 600
22 | #MainFormHeight: 600
23 | #End Region
24 |
25 | Sub Process_Globals
26 | Private fx As JFX
27 | Public MainForm As Form
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim n As InsetRectMaskGenPlugin
35 | n.Initialize
36 | Dim box As Map
37 | box.Initialize
38 | Dim img As Image=fx.LoadImage(File.DirApp,"1.jpg")
39 | wait for (n.genMask(img,box,5)) complete (result As B4XBitmap)
40 | Dim out As OutputStream
41 | out=File.OpenOutput(File.DirApp,"mask.png",False)
42 | result.WriteToStream(out,100,"PNG")
43 | out.Close
44 | End Sub
45 |
46 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
47 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
48 | Return True
49 | End Sub
50 |
--------------------------------------------------------------------------------
/InsetRectMaskGen/readme.md:
--------------------------------------------------------------------------------
1 | See https://github.com/xulihang/ImageTrans-docs/issues/413
--------------------------------------------------------------------------------
/LamaInpaint/LamaInpaint.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=javaobject
5 | Library10=jbitmapcreator
6 | Library2=jcore
7 | Library3=jfx
8 | Library4=jokhttputils2
9 | Library5=json
10 | Library6=jstringutils
11 | Library7=jxmlsax
12 | Library8=jxui
13 | Library9=xmlbuilder
14 | Module1=LamaInpaintPlugin
15 | NumberOfFiles=0
16 | NumberOfLibraries=10
17 | NumberOfModules=1
18 | Version=8.9
19 | @EndOfDesignText@
20 | #Region Project Attributes
21 | #MainFormWidth: 600
22 | #MainFormHeight: 600
23 | #End Region
24 |
25 | Sub Process_Globals
26 | Private fx As JFX
27 | Public MainForm As Form
28 |
29 | End Sub
30 |
31 | Sub AppStart (Form1 As Form, Args() As String)
32 | MainForm = Form1
33 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
34 | MainForm.Show
35 | Dim settings As Map
36 | settings.Initialize
37 | Dim n As LamaInpaintPlugin
38 | n.Initialize
39 | Dim origin As Image=fx.LoadImage(File.DirApp,"origin.jpg")
40 | Dim mask As Image=fx.LoadImage(File.DirApp,"mask1.png")
41 | wait for (n.inpaint(origin,mask,settings)) complete (result As B4XBitmap)
42 | Dim out As OutputStream
43 | out=File.OpenOutput(File.DirApp,"removed.jpg",False)
44 | result.WriteToStream(out,100,"JPEG")
45 | out.Close
46 | End Sub
47 |
48 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
49 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
50 | Return True
51 | End Sub
52 |
--------------------------------------------------------------------------------
/LamaInpaint/readme.md:
--------------------------------------------------------------------------------
1 | ## Lama inpainting plugin for ImageTrans
2 |
3 | You can download the plugin files here: [lamainpaint_plugins.zip](https://github.com/xulihang/ImageTrans-docs/files/13327436/lamainpaint_plugins.zip)
4 |
5 | You need to run [lama-cleaner](https://github.com/Sanster/lama-cleaner) as the backend of the plugin.
6 |
7 | ### How to use
8 |
9 | 1. Install Python
10 | 2. Put the plugin files in ImageTrans's `plugins` folder
11 | 3. Install lama-cleaner: `pip install lama-cleaner==0.12.0`
12 | 4. Start the server at port 8087: `lama-cleaner --device=cpu --port=8087`
13 | 5. In ImageTrans, set the default inpainter to lama or use it in TextRemover.
14 |
15 |
16 | For convenience, you can also use the Windows package of lama-cleaner. Download and unzip it and then start `run.bat` to keep the server running. [Download link](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/LamaInpaint.zip).
17 |
18 |
19 | Related issue: https://github.com/xulihang/ImageTrans-docs/issues/216
20 |
21 | PS: lama will resize images too large so it is recommended to process by text areas. You can enable this in the project settings.
22 |
23 | ### Model
24 |
25 | If the program fails to download the model, you can download the model file manually.
26 |
27 | Download link: .
28 |
29 | For Windows, you need to unzip it to the following path: `C:\Users\\.cache\torch\hub\checkpoints\big-lama.pt`.
30 |
31 |
32 | ### GPU
33 |
34 | If you need to use CUDA GPU, you have to install the cuda version of pytorch:
35 |
36 | ```
37 | pip uninstall torch torchvision torchaudio
38 | pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
39 | ```
40 |
41 | Then launch it with this command: `lama-cleaner --device=cuda --port=8087`
42 |
43 | If you are using the Windows package, you have to use notepad to edit `Scripts\pip.exe` to replace `e:\python3810\python.exe` with `.\python.exe` and run the following command:
44 |
45 | ```
46 | .\Scripts\pip.exe uninstall torch torchvision torchaudio
47 | .\Scripts\pip.exe install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
48 | ```
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/PyRapidOCR/README.md:
--------------------------------------------------------------------------------
1 | ## RapidOCR Python
2 |
3 | This OCR can detect text in word level.
4 |
5 | 1. Install Python.
6 | 2. Install rapidocr, bottle and Paste: `pip install rapidocr_onnxruntime bottle Paste`
7 | 3. Run the following to start the server: `python server.py`
8 | 4. Download the plugins and copy the PyRapidOCR plugin's jar and xml files into ImageTrans's `plugins` folder: [link](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/ImageTrans_plugins.zip)
9 |
10 | For convenience, you can directly use the Windows package: [link](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/PyRapidOCR.zip).
11 |
12 | Unzip the file and start `run.bat` to run the server. You need to keep the server running in the background.
--------------------------------------------------------------------------------
/PyRapidOCR/plugin/PyRapidOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library2=jfx
6 | Library3=json
7 | Library4=jxmlsax
8 | Library5=xmlbuilder
9 | Library6=jxui
10 | Library7=javaobject
11 | Library8=jokhttputils2
12 | Library9=jstringutils
13 | Module1=PyRapidOCRPlugin
14 | NumberOfFiles=0
15 | NumberOfLibraries=9
16 | NumberOfModules=1
17 | Version=8.8
18 | @EndOfDesignText@
19 | #Region Project Attributes
20 | #MainFormWidth: 600
21 | #MainFormHeight: 600
22 | #End Region
23 |
24 | Sub Process_Globals
25 | Private fx As JFX
26 | Public MainForm As Form
27 |
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim n As PyRapidOCRPlugin
35 | n.Initialize
36 | wait for (n.GetTextWithLocation(fx.LoadImage(File.DirApp,"image.jpg"),"ch")) complete (result As List)
37 | Log(result)
38 | 'wait for (n.translate("Hello","en","zh")) complete (result As String)
39 | 'Log(result)
40 | End Sub
41 |
42 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
43 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
44 | Return True
45 | End Sub
46 |
--------------------------------------------------------------------------------
/PyRapidOCR/server/server.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | from rapidocr_onnxruntime import RapidOCR
3 | import os
4 | import time
5 | import datetime
6 | from bottle import route, run, template, request, static_file
7 | import json
8 |
9 | @route('/ocr', method='POST')
10 | def ocr():
11 | upload = request.files.get('upload')
12 | lang = request.forms.get('lang')
13 | return_word_box_param = request.forms.get('return_word_box')
14 | return_word_box = False
15 | if return_word_box_param == "true":
16 | return_word_box = True
17 | name, ext = os.path.splitext(upload.filename)
18 | print(ext.lower())
19 | if ext.lower() not in ('.png','.jpg','.jpeg'):
20 | return "File extension not allowed."
21 | timestamp=str(int(time.time()*1000))
22 | savedName=timestamp+ext
23 | save_path = "./uploaded/"
24 | if not os.path.exists(save_path):
25 | os.makedirs(save_path)
26 | file_path = "{path}/{file}".format(path=save_path, file=savedName)
27 | if os.path.exists(file_path)==True:
28 | os.remove(file_path)
29 | upload.save(file_path)
30 | ret = {}
31 | result = engine(file_path, return_word_box=return_word_box)
32 | print(result)
33 | text_lines=[]
34 | for line in result[0]:
35 | text_line={}
36 | index=0
37 | line_text = line[1]
38 | for coord in line[0]:
39 | text_line["x"+str(index)]=int(coord[0])
40 | text_line["y"+str(index)]=int(coord[1])
41 | index=index+1
42 | text_line["text"]=line_text
43 |
44 | if return_word_box:
45 | boxes_coords = line[3]
46 |
47 | box_index = 0
48 | boxes = []
49 | for coords in boxes_coords:
50 | box = {}
51 | index = 0
52 | for coord in coords:
53 | box["x"+str(index)]=int(coord[0])
54 | box["y"+str(index)]=int(coord[1])
55 | index = index + 1
56 | box["text"] = line[4][box_index]
57 | boxes.append(box)
58 | box_index = box_index + 1
59 | text_line["boxes"] = boxes
60 | text_lines.append(text_line)
61 | os.remove(file_path)
62 | ret["text_lines"]=text_lines
63 | return ret
64 |
65 |
66 | @route('/')
67 | def server_static(filepath):
68 | return static_file(filepath, root='www')
69 |
70 | engine = RapidOCR()
71 | run(server="paste",host='127.0.0.1', port=8078)
72 |
73 |
--------------------------------------------------------------------------------
/PyRapidOCR/server/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Upload
6 |
7 |
8 |
14 |
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ImageTrans_plugins
2 |
3 | This is the repo for ImageTrans plugins.
4 |
5 | Go to the sub folders for details.
6 |
7 | You can download all the plugins here:
8 |
9 | ## Featured Plugins List
10 |
11 | These plugins can work offline.
12 |
13 | ### OCR
14 |
15 | * [PaddleOCR](paddleOCR)
16 | * [RapidOCR](RapidOCR). It is based on PaddleOCR's models. It works for Chinese, Korean, English and Japanese.
17 | * [mangaOCR](mangaOCR)
18 | * [PororoOCR for Korean](pororoOCR)
19 | * [ChineseOCR](ChineseOCR)
20 |
21 |
22 | ### Machine Translation
23 |
24 | * [opusMT](opusMT)
25 | * [sugoiMT](sugoiMT)
26 | * [ChatGPT](chatGPTMT)
27 |
28 | ### Mask Generation
29 |
30 | * [ExternalMaskGen](ExternalMaskGen)
31 | * [InsetRectMaskGen](InsetRectMaskGen)
32 |
33 | ### Inpainting
34 |
35 | * [ExternalInpaint](ExternalInpaint)
36 | * [LamaInpaint](LamaInpaint)
37 |
38 | ### All-in-One
39 |
40 | [mangaTranslator](mangaTranslatorOCR)
41 |
42 | ## How to use Sickzil-Machine
43 |
44 | 1. Download the Windows build of Sickzil-Machine server from [here](https://github.com/xulihang/SickZil-Machine/releases/download/server/dist.zip).
45 | 2. Unzip it and double-click server.exe to run Sickzil-Machine
46 | 3. Use External Inpaint and External MaskGen to call it.
47 |
48 | ## Notes Using Local Servers
49 |
50 | The default port of local severs is usually 8080. If you are using multiple local servers like mangaOCR and mangaTranslator, they may have a port conflict.
51 |
52 | You can modify the Python script to update the port and update the URL in ImageTrans' preferences.
53 |
54 | For example, to modify the port of mangaOCR, edit `server_manga_ocr.py` to change to following line:
55 |
56 | ```py
57 | run(server="paste",host='0.0.0.0', port=8080)
58 | ```
59 |
60 | Then, open ImageTrans to update its perferences:
61 |
62 | 
63 |
64 |
--------------------------------------------------------------------------------
/RapidOCR/RapidOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=javaobject
5 | Library10=xmlbuilder
6 | Library11=jsql
7 | Library2=jcore
8 | Library3=jfx
9 | Library4=jokhttputils2
10 | Library5=jshell
11 | Library6=json
12 | Library7=jstringutils
13 | Library8=jxmlsax
14 | Library9=jxui
15 | Module1=Localizator
16 | Module2=RapidOCRPlugin
17 | NumberOfFiles=0
18 | NumberOfLibraries=11
19 | NumberOfModules=2
20 | Version=8.9
21 | @EndOfDesignText@
22 | #Region Project Attributes
23 | #MainFormWidth: 600
24 | #MainFormHeight: 600
25 | #End Region
26 |
27 | Sub Process_Globals
28 | Private fx As JFX
29 | Public MainForm As Form
30 | End Sub
31 |
32 | Sub AppStart (Form1 As Form, Args() As String)
33 | MainForm = Form1
34 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
35 | MainForm.Show
36 | Dim n As RapidOCRPlugin
37 | n.Initialize
38 | wait for (n.GetText(fx.LoadImage(File.DirApp,"capture001.jpg"),"ko","")) Complete (text As String)
39 | wait for (n.GetTextWithLocation(fx.LoadImage(File.DirApp,"capture001.jpg"),"ko","")) Complete (result As List)
40 | Log(text)
41 | Log(result)
42 | 'wait for (n.translate("Hello","en","zh")) complete (result As String)
43 | 'Log(result)
44 | End Sub
45 |
46 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
47 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
48 | Return True
49 | End Sub
50 |
--------------------------------------------------------------------------------
/RapidOCR/readme.md:
--------------------------------------------------------------------------------
1 | See https://github.com/xulihang/RapidOcrOnnxJvm
2 |
3 | Installation:
4 |
5 | 1. Install the rapidOCR plugin (not neccessary as it is already bundled with ImageTrans).
6 | 2. Unzip [rapidocr.zip](https://github.com/xulihang/RapidOcrOnnxJvm/releases/download/builds/rapidocr.zip) into ImageTrans's folder. (you can also do this using the plugin helper in ImageTrans).
7 |
--------------------------------------------------------------------------------
/STTNInpaint/STTNInpaint.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library2=jfx
6 | Library3=json
7 | Library4=jxmlsax
8 | Library5=xmlbuilder
9 | Library6=jxui
10 | Library7=javaobject
11 | Library8=jokhttputils2
12 | Library9=jstringutils
13 | Module1=STTNInpaintPlugin
14 | NumberOfFiles=0
15 | NumberOfLibraries=9
16 | NumberOfModules=1
17 | Version=8.9
18 | @EndOfDesignText@
19 | #Region Project Attributes
20 | #MainFormWidth: 600
21 | #MainFormHeight: 600
22 | #End Region
23 |
24 | Sub Process_Globals
25 | Private fx As JFX
26 | Public MainForm As Form
27 |
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim settings As Map
35 | settings.Initialize
36 | Dim n As STTNInpaintPlugin
37 | n.Initialize
38 | Dim origin As Image=fx.LoadImage(File.DirApp,"frame1.png")
39 | Dim mask As Image=fx.LoadImage(File.DirApp,"test.png")
40 | 'wait for (n.inpaint(origin,mask,settings)) complete (result As B4XBitmap)
41 | 'Dim out As OutputStream
42 | 'out=File.OpenOutput(File.DirApp,"removed.jpg",False)
43 | 'result.WriteToStream(out,100,"JPEG")
44 | 'out.Close
45 | Dim folder As String = File.Combine(File.DirApp,"folder")
46 | wait for (n.inpaintFolder(folder,mask,settings)) complete (done As Object)
47 | End Sub
48 |
49 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
50 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
51 | Return True
52 | End Sub
53 |
--------------------------------------------------------------------------------
/STTNInpaint/readme.md:
--------------------------------------------------------------------------------
1 | https://github.com/xulihang/STTNInpainter
--------------------------------------------------------------------------------
/WinRTOCR/WinRTOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=jshell
6 | Library2=jfx
7 | Library3=json
8 | Library4=jxmlsax
9 | Library5=xmlbuilder
10 | Library6=jxui
11 | Library7=javaobject
12 | Library8=jokhttputils2
13 | Library9=jstringutils
14 | Module1=WinRTOCRPlugin
15 | NumberOfFiles=0
16 | NumberOfLibraries=10
17 | NumberOfModules=1
18 | Version=8.9
19 | @EndOfDesignText@
20 | #Region Project Attributes
21 | #MainFormWidth: 600
22 | #MainFormHeight: 600
23 | #End Region
24 |
25 | Sub Process_Globals
26 | Private fx As JFX
27 | Public MainForm As Form
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim n As WinRTOCRPlugin
35 | n.Initialize
36 | wait for (n.Langs) Complete (langs As Object)
37 | Log(langs)
38 | 'wait for (n.GetText(fx.LoadImage(File.DirApp,"image.jpg"),"chi_sim")) Complete (text As String)
39 | 'wait for (n.GetTextWithLocation(fx.LoadImage(File.DirApp,"image.jpg"),"chi_sim")) Complete (result As List)
40 | 'Log(text)
41 | 'Log(result)
42 | 'wait for (n.translate("Hello","en","zh")) complete (result As String)
43 | 'Log(result)
44 | End Sub
45 |
46 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
47 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
48 | Return True
49 | End Sub
50 |
--------------------------------------------------------------------------------
/WinRTOCR/WinRTOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=WinRTOCRPlugin,GetTextWithLocation,57,6,WinRTOCRPlugin,GetText,94,0,WinRTOCRPlugin,ocr,182,6,WinRTOCRPlugin,LangHasSpace,149,6,WinRTOCRPlugin,LinesToBoxes,116,6,WinRTOCRPlugin,convertLang,83,0,WinRTOCRPlugin,getLangs,64,6,WinRTOCRPlugin,Run,38,4,Main,AppStart,20,6,WinRTOCRPlugin,getEncoding,53,6
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/abbyycloudOCR/OCR.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=StaticCode
5 | Version=7.8
6 | @EndOfDesignText@
7 | 'Static code module
8 | Sub Process_Globals
9 | Private fx As JFX
10 | End Sub
11 |
12 | Sub rightToLeft As Boolean
13 | Return True
14 | End Sub
--------------------------------------------------------------------------------
/abbyycloudOCR/abbyycloudOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=encryption
6 | Library11=byteconverter
7 | Library12=jsql
8 | Library13=xml2map
9 | Library2=jfx
10 | Library3=json
11 | Library4=jxmlsax
12 | Library5=xmlbuilder
13 | Library6=jxui
14 | Library7=javaobject
15 | Library8=jokhttputils2
16 | Library9=jstringutils
17 | Module1=abbyycloudOCRPlugin
18 | Module2=Localizator
19 | Module3=OCR
20 | NumberOfFiles=0
21 | NumberOfLibraries=13
22 | NumberOfModules=3
23 | Version=8.9
24 | @EndOfDesignText@
25 | #Region Project Attributes
26 | #MainFormWidth: 600
27 | #MainFormHeight: 600
28 | #End Region
29 |
30 |
31 | Sub Process_Globals
32 | Private fx As JFX
33 | Public MainForm As Form
34 |
35 | End Sub
36 |
37 | Sub AppStart (Form1 As Form, Args() As String)
38 | MainForm = Form1
39 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
40 | MainForm.Show
41 | Log(DateTime.Now)
42 | Dim t As abbyycloudOCRPlugin
43 | t.Initialize
44 | wait for (t.GetTextWithLocation(fx.LoadImage(File.DirApp,"imageen.jpg"),"English")) Complete (done As Object)
45 | Log(done)
46 | End Sub
47 |
48 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
49 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
50 | Return True
51 | End Sub
52 |
--------------------------------------------------------------------------------
/abbyycloudOCR/abbyycloudOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBookmarks2=
4 | ModuleBookmarks3=
5 | ModuleBreakpoints0=
6 | ModuleBreakpoints1=
7 | ModuleBreakpoints2=
8 | ModuleBreakpoints3=
9 | ModuleClosedNodes0=
10 | ModuleClosedNodes1=
11 | ModuleClosedNodes2=
12 | ModuleClosedNodes3=
13 | NavigationStack=abbyycloudOCRPlugin,Class_Globals,1,0,abbyycloudOCRPlugin,getLangs,266,0,Main,AppStart,19,0,abbyycloudOCRPlugin,AddBoxesFromXML,570,0,abbyycloudOCRPlugin,MergedCharacters,586,3,abbyycloudOCRPlugin,DoOCR,506,0
14 | SelectedBuild=0
15 | VisibleModules=2,3,1
16 |
--------------------------------------------------------------------------------
/aliMT/.classpath:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/aliMT/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 | *.class
--------------------------------------------------------------------------------
/aliMT/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | alimt
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/aliMT/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7 | org.eclipse.jdt.core.compiler.release=disabled
8 | org.eclipse.jdt.core.compiler.source=1.8
9 |
--------------------------------------------------------------------------------
/aliMT/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/aliMT/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 | com.xulihang
4 | alimt
5 | 0.0.1-SNAPSHOT
6 |
7 |
8 | com.aliyun
9 | alimt20181012
10 | 1.3.1
11 |
12 |
13 |
--------------------------------------------------------------------------------
/aliMT/src/main/java/alimt/Translator.java:
--------------------------------------------------------------------------------
1 | package alimt;
2 |
3 | import com.aliyun.alimt20181012.models.TranslateResponse;
4 | import com.aliyun.tea.TeaException;
5 |
6 | public class Translator {
7 | public static String translate(String formatType, String sourceLang,String targetLang,String text, String scene, String keyID, String keySecret) throws Exception {
8 |
9 | // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
10 | // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html。
11 | com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
12 | // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
13 | .setAccessKeyId(keyID)
14 | // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
15 | .setAccessKeySecret(keySecret);
16 | // Endpoint 请参考 https://api.aliyun.com/product/alimt
17 | config.endpoint = "mt.cn-hangzhou.aliyuncs.com";
18 | com.aliyun.alimt20181012.Client client = new com.aliyun.alimt20181012.Client(config);
19 | com.aliyun.alimt20181012.models.TranslateRequest translateRequest = new com.aliyun.alimt20181012.models.TranslateRequest()
20 | .setFormatType(formatType)
21 | .setTargetLanguage(targetLang)
22 | .setSourceLanguage(sourceLang)
23 | .setSourceText(text)
24 | .setScene(scene);
25 | com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
26 | try {
27 | // 复制代码运行请自行打印 API 的返回值
28 | TranslateResponse response = client.translateWithOptions(translateRequest, runtime);
29 | System.out.println(response.body.getData().translated);
30 | return response.body.getData().translated;
31 | } catch (TeaException error) {
32 | // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
33 | // 错误 message
34 | System.out.println(error.getMessage());
35 | // 诊断地址
36 | System.out.println(error.getData().get("Recommend"));
37 | com.aliyun.teautil.Common.assertAsString(error.message);
38 | } catch (Exception _error) {
39 | TeaException error = new TeaException(_error.getMessage(), _error);
40 | // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
41 | // 错误 message
42 | System.out.println(error.getMessage());
43 | // 诊断地址
44 | System.out.println(error.getData().get("Recommend"));
45 | com.aliyun.teautil.Common.assertAsString(error.message);
46 | }
47 | return "";
48 |
49 | }
50 |
51 | public static void main(String[] args) throws Exception {
52 | // TODO Auto-generated method stub
53 | translate("text","en","zh","I love you","title","","");
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/aliMT/target/classes/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Build-Jdk-Spec: 23
3 | Created-By: Maven Integration for Eclipse
4 |
5 |
--------------------------------------------------------------------------------
/aliMT/target/classes/META-INF/maven/com.xulihang/alimt/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven Integration for Eclipse
2 | #Sat Nov 16 12:03:13 CST 2024
3 | artifactId=alimt
4 | groupId=com.xulihang
5 | m2e.projectLocation=C\:\\Users\\HP\\eclipse-workspace\\alimt
6 | m2e.projectName=alimt
7 | version=0.0.1-SNAPSHOT
8 |
--------------------------------------------------------------------------------
/aliMT/target/classes/META-INF/maven/com.xulihang/alimt/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 | com.xulihang
4 | alimt
5 | 0.0.1-SNAPSHOT
6 |
7 |
8 | com.aliyun
9 | alimt20181012
10 | 1.3.1
11 |
12 |
13 |
--------------------------------------------------------------------------------
/chatGPTMT/chatGPTMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans,HU2_ACCEPTALL
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=byteconverter
6 | Library11=encryption
7 | Library2=jfx
8 | Library3=json
9 | Library4=jxmlsax
10 | Library5=xmlbuilder
11 | Library6=jxui
12 | Library7=javaobject
13 | Library8=jokhttputils2
14 | Library9=jstringutils
15 | Module1=chatGPTMTPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=11
18 | NumberOfModules=1
19 | Version=8.8
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 |
30 | End Sub
31 |
32 | Sub AppStart (Form1 As Form, Args() As String)
33 | MainForm = Form1
34 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
35 | MainForm.Show
36 | Dim n As chatGPTMTPlugin
37 | n.Initialize
38 | Dim map1 As Map
39 | map1.Initialize
40 | map1.Put("key","your key")
41 |
42 | map1.Put("host","https://37cb-35-243-195-191.ngrok-free.app")
43 | 'map1.Put("model","gpt-4")
44 | 'map1.Put("prompt",$"翻译下述内容至中文: {source}"$)
45 | 'wait for (n.translate("Do you want to have more cake, Jenny?","en","zh",CreateMap("mt":CreateMap("chatGPT":map1)),CreateMap("Jenny":"珍妮"))) complete (result As String)
46 | 'wait for (n.batchTranslate(Array("Do you want to have more cake, Jenny?"),"en","zh",CreateMap("mt":CreateMap("chatGPT":map1)),CreateMap("Jenny":"珍妮"))) complete (result As Object)
47 | 'wait for (n.translate("BasicCAT Documentation."&CRLF&"Sentence2.","en","zh",CreateMap("mt":CreateMap("chatGPT":map1)))) complete (result As String)
48 | Dim terms As Map
49 | terms.Initialize
50 | Dim textToTranslate As List = Array("お前には夏休みの間","我が天文部手伝いをしてもらう","いつか必ず","地に落ちるのだから","失敗です!!","有人ロケット「あさがお」が爆発!","日本初の有人宇宙飛行は失敗しました!!")
51 | 'wait for (n.batchTranslate(Array("BasicCAT Documentation."&CRLF&"Sentence2.","Paragraph2"),"en","zh",CreateMap("mt":CreateMap("chatGPT":map1)))) complete (result As Object)
52 | wait for (n.batchTranslate(textToTranslate,"ja","zh",CreateMap("mt":CreateMap("chatGPT":map1)),terms)) complete (result As Object)
53 | Log(result)
54 | End Sub
55 |
56 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
57 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
58 | Return True
59 | End Sub
60 |
--------------------------------------------------------------------------------
/chatGPTMT/readme.md:
--------------------------------------------------------------------------------
1 |
2 | ## Plugin to Use ChatGPT for Machine Translation
3 |
4 | Related issue:
5 |
6 | Usage:
7 |
8 | 1. Enter your key in the API preference settings.
9 | 2. You can customize the prompt in the settings as well. The default prompt is `Translate the following into {langcode}: {source}`. `{langcode}` and `{source}` will be replaced with the name of the target language and the source text. An example after replacing is like this: `Translate the following into Chinese: Hello world!`.
10 | 3. You can use third-party ChatGPT hosts by setting the host parameter.
11 |
12 | ### Blog
13 |
14 | https://www.basiccat.org/ChatGPT-image-translator/
15 |
--------------------------------------------------------------------------------
/chatGPTOCR/chatGPTOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans,HU2_ACCEPTALL
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=byteconverter
6 | Library11=encryption
7 | Library2=jfx
8 | Library3=json
9 | Library4=jxmlsax
10 | Library5=xmlbuilder
11 | Library6=jxui
12 | Library7=javaobject
13 | Library8=jokhttputils2
14 | Library9=jstringutils
15 | Module1=chatGPTOCRPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=11
18 | NumberOfModules=1
19 | Version=8.9
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 | End Sub
30 |
31 | Sub AppStart (Form1 As Form, Args() As String)
32 | MainForm = Form1
33 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
34 | MainForm.Show
35 | Dim n As chatGPTOCRPlugin
36 | n.Initialize
37 | Dim img As B4XBitmap = fx.LoadImage(File.DirApp,"test.jpg")
38 | wait for (n.GetTextWithLocation(img)) complete (result As Object)
39 | 'wait for (n.batchTranslate(Array("BasicCAT Documentation.","Sentence2."),"en","zh",CreateMap("mt":CreateMap("gemini":map1)))) complete (result As List)
40 | Log(result)
41 | End Sub
42 |
43 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
44 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
45 | Return True
46 | End Sub
47 |
--------------------------------------------------------------------------------
/cloudtranslationMT/cloudtranslationMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=byteconverter
6 | Library11=encryption
7 | Library2=jfx
8 | Library3=json
9 | Library4=jxmlsax
10 | Library5=xmlbuilder
11 | Library6=jxui
12 | Library7=javaobject
13 | Library8=jokhttputils2
14 | Library9=jstringutils
15 | Module1=cloudtranslationMTPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=11
18 | NumberOfModules=1
19 | Version=7.8
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 |
30 | End Sub
31 |
32 | Sub AppStart (Form1 As Form, Args() As String)
33 | MainForm = Form1
34 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
35 | MainForm.Show
36 | Dim n As cloudtranslationMTPlugin
37 | n.Initialize
38 | wait for (n.translate("BasicCAT Documentation","en","zh")) complete (result As String)
39 | 'Log(result)
40 | End Sub
41 |
42 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
43 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
44 | Return True
45 | End Sub
46 |
--------------------------------------------------------------------------------
/cloudtranslationMT/cloudtranslationMT.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=Main,AppStart,13,0,cloudtranslationMTPlugin,Class_Globals,0,0,cloudtranslationMTPlugin,getMap,57,0,cloudtranslationMTPlugin,Run,26,0,cloudtranslationMTPlugin,GetNiceName,13,0,cloudtranslationMTPlugin,translate,42,6,Main,Process_Globals,10,0
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/cloudtranslationMT/cloudtranslationMTPlugin.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=Class
5 | Version=4.2
6 | @EndOfDesignText@
7 | Sub Class_Globals
8 | Private fx As JFX
9 | End Sub
10 |
11 | 'Initializes the object. You can NOT add parameters to this method!
12 | Public Sub Initialize() As String
13 | Log("Initializing plugin " & GetNiceName)
14 | ' Here return a key to prevent running unauthorized plugins
15 | Return "MyKey"
16 | End Sub
17 |
18 | ' must be available
19 | public Sub GetNiceName() As String
20 | Return "cloudtranslationMT"
21 | End Sub
22 |
23 | ' must be available
24 | public Sub Run(Tag As String, Params As Map) As ResumableSub
25 | Log("run"&Params)
26 | Select Tag
27 | Case "getParams"
28 | Dim paramsList As List
29 | paramsList.Initialize
30 | paramsList.Add("url")
31 | Return paramsList
32 | Case "translate"
33 | wait for (translate(Params.Get("source"),Params.Get("sourceLang"),Params.Get("targetLang"),Params.Get("preferencesMap"))) complete (result As String)
34 | Return result
35 | End Select
36 | Return ""
37 | End Sub
38 |
39 |
40 | Sub translate(source As String, sourceLang As String, targetLang As String,preferencesMap As Map) As ResumableSub
41 | Dim target As String
42 | Dim params As String
43 | Dim su As StringUtils
44 | source=su.EncodeUrl(source,"UTF-8")
45 | params="lang="&sourceLang&"_"&targetLang&"&src="&source
46 | Dim url As String=getMap("cloudtranslation",getMap("mt",preferencesMap)).GetDefault("url","https://sz-nmt-1.cloudtranslation.com/nmt")
47 | Dim job As HttpJob
48 | job.Initialize("job",Me)
49 | job.Download(url&"?"¶ms)
50 | wait For (job) JobDone(job As HttpJob)
51 | If job.Success Then
52 | Log(job.GetString)
53 | target=job.GetString
54 | Else
55 | target=""
56 | End If
57 | job.Release
58 | Return target
59 | End Sub
60 |
61 | Sub getMap(key As String,parentmap As Map) As Map
62 | Return parentmap.Get(key)
63 | End Sub
64 |
--------------------------------------------------------------------------------
/clovaOCR/clovaOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=encryption
6 | Library11=byteconverter
7 | Library12=jsql
8 | Library2=jfx
9 | Library3=json
10 | Library4=jxmlsax
11 | Library5=xmlbuilder
12 | Library6=jxui
13 | Library7=javaobject
14 | Library8=jokhttputils2
15 | Library9=jstringutils
16 | Module1=clovaOCRPlugin
17 | Module2=Localizator
18 | NumberOfFiles=0
19 | NumberOfLibraries=12
20 | NumberOfModules=2
21 | Version=8.9
22 | @EndOfDesignText@
23 | #Region Project Attributes
24 | #MainFormWidth: 600
25 | #MainFormHeight: 600
26 | #End Region
27 |
28 | Sub Process_Globals
29 | Private fx As JFX
30 | Public MainForm As Form
31 |
32 | End Sub
33 |
34 | Sub AppStart (Form1 As Form, Args() As String)
35 | MainForm = Form1
36 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
37 | MainForm.Show
38 | Dim t As clovaOCRPlugin
39 | t.Initialize
40 | wait for (t.GetTextWithLocation(fx.LoadImage(File.DirApp,"18_094.jpg"),"auto")) Complete (done As Object)
41 | Log(done)
42 | End Sub
43 |
44 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
45 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
46 | Return True
47 | End Sub
48 |
--------------------------------------------------------------------------------
/clovaOCR/clovaOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBookmarks2=
4 | ModuleBreakpoints0=
5 | ModuleBreakpoints1=
6 | ModuleBreakpoints2=
7 | ModuleClosedNodes0=
8 | ModuleClosedNodes1=
9 | ModuleClosedNodes2=
10 | NavigationStack=clovaOCRPlugin,GetNiceName,14,0,clovaOCRPlugin,UUID,173,0,Main,AppStart,17,1,clovaOCRPlugin,getLangs,49,0,clovaOCRPlugin,Run,27,1,clovaOCRPlugin,Class_Globals,4,0,clovaOCRPlugin,GetTextWithLocation,75,0,clovaOCRPlugin,ocr,162,6
11 | SelectedBuild=0
12 | VisibleModules=1,2
13 |
--------------------------------------------------------------------------------
/copySourceToTargetAction/copySourceToTargetAction.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=byteconverter
6 | Library11=encryption
7 | Library2=jfx
8 | Library3=json
9 | Library4=jxmlsax
10 | Library5=xmlbuilder
11 | Library6=jxui
12 | Library7=javaobject
13 | Library8=jokhttputils2
14 | Library9=jstringutils
15 | Module1=copySourceToTargetActionPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=11
18 | NumberOfModules=1
19 | Version=8.9
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 | End Sub
30 |
31 | Sub AppStart (Form1 As Form, Args() As String)
32 | MainForm = Form1
33 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
34 | MainForm.Show
35 | End Sub
36 |
37 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
38 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
39 | Return True
40 | End Sub
41 |
--------------------------------------------------------------------------------
/copySourceToTargetAction/copySourceToTargetActionPlugin.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=Class
5 | Version=4.2
6 | @EndOfDesignText@
7 | Sub Class_Globals
8 | Private fx As JFX
9 | End Sub
10 |
11 | 'Initializes the object. You can NOT add parameters to this method!
12 | Public Sub Initialize() As String
13 | Log("Initializing plugin " & GetNiceName)
14 | ' Here return a key to prevent running unauthorized plugins
15 | Return "MyKey"
16 | End Sub
17 |
18 | ' must be available
19 | public Sub GetNiceName() As String
20 | Return "copySourceToTargetAction"
21 | End Sub
22 |
23 | ' must be available
24 | public Sub Run(Tag As String, Params As Map) As ResumableSub
25 | Select Tag
26 | Case "process"
27 | Process(Params.Get("sourceTextArea"),Params.Get("targetTextArea"))
28 | End Select
29 | Return ""
30 | End Sub
31 |
32 | private Sub Process(sourceTextArea As TextArea,targetTextArea As TextArea)
33 | targetTextArea.Text = targetTextArea.Text & CRLF & CRLF & sourceTextArea.Text
34 | End Sub
--------------------------------------------------------------------------------
/crnnOCR/README.md:
--------------------------------------------------------------------------------
1 | See
--------------------------------------------------------------------------------
/crnnOCR/crnnOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library2=jfx
6 | Library3=json
7 | Library4=jxmlsax
8 | Library5=xmlbuilder
9 | Library6=jxui
10 | Library7=javaobject
11 | Library8=jokhttputils2
12 | Library9=jstringutils
13 | Module1=crnnOCRPlugin
14 | NumberOfFiles=0
15 | NumberOfLibraries=9
16 | NumberOfModules=1
17 | Version=8.9
18 | @EndOfDesignText@
19 | #Region Project Attributes
20 | #MainFormWidth: 600
21 | #MainFormHeight: 600
22 | #End Region
23 |
24 | Sub Process_Globals
25 | Private fx As JFX
26 | Public MainForm As Form
27 |
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim n As crnnOCRPlugin
35 | n.Initialize
36 | Dim img As B4XBitmap=fx.LoadImage(File.DirApp,"sandwich.png")
37 | wait for (n.GetText(img,"en")) complete (result As Object)
38 | Log(result)
39 | End Sub
40 |
41 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
42 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
43 | Return True
44 | End Sub
45 |
--------------------------------------------------------------------------------
/crnnOCR/crnnOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=crnnOCRPlugin,ocr,54,0,Main,AppStart,12,0,crnnOCRPlugin,Initialize,7,0,crnnOCRPlugin,Run,33,6
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/crnnOCR/crnnOCRPlugin.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=Class
5 | Version=4.2
6 | @EndOfDesignText@
7 | Sub Class_Globals
8 | Private fx As JFX
9 | End Sub
10 |
11 | 'Initializes the object. You can NOT add parameters to this method!
12 | Public Sub Initialize() As String
13 | Log("Initializing plugin " & GetNiceName)
14 | ' Here return a key to prevent running unauthorized plugins
15 | Return "MyKey"
16 | End Sub
17 |
18 | ' must be available
19 | public Sub GetNiceName() As String
20 | Return "crnnOCR"
21 | End Sub
22 |
23 | ' must be available
24 | public Sub Run(Tag As String, Params As Map) As ResumableSub
25 | Log("run"&Params)
26 | Select Tag
27 | Case "getParams"
28 | Dim paramsList As List
29 | paramsList.Initialize
30 | paramsList.Add("url")
31 | Return paramsList
32 | Case "getText"
33 | wait for (GetText(Params.Get("img"),Params.Get("lang"))) complete (result As String)
34 | Return result
35 | Case "getTextWithLocation"
36 | Dim regions As List
37 | regions.Initialize
38 | Return regions
39 | Case "RecognizeOnly"
40 | return True
41 | End Select
42 | Return ""
43 | End Sub
44 |
45 | Sub GetText(img As B4XBitmap, lang As String) As ResumableSub
46 | wait for (ocr(img,lang)) complete (text As String)
47 | Return text
48 | End Sub
49 |
50 | Sub ocr(img As B4XBitmap, lang As String) As ResumableSub
51 | Dim out As OutputStream
52 | out=File.OpenOutput(File.DirApp,"image.jpg",False)
53 | img.WriteToStream(out,"100","JPEG")
54 | out.Close
55 | Dim job As HttpJob
56 | job.Initialize("",Me)
57 | Dim fd As MultipartFileData
58 | fd.Initialize
59 | fd.KeyName = "upload"
60 | fd.Dir = File.DirApp
61 | fd.FileName = "image.jpg"
62 | fd.ContentType = "image/jpg"
63 | job.PostMultipart(getUrl,CreateMap("lang":lang,"recognize_entire_image":"true"), Array(fd))
64 | job.GetRequest.Timeout=240*1000
65 | Wait For (job) JobDone(job As HttpJob)
66 | If job.Success Then
67 | Try
68 | Return job.GetString
69 | Catch
70 | Log(LastException)
71 | End Try
72 | End If
73 | Return ""
74 | End Sub
75 |
76 | Sub getMap(key As String,parentmap As Map) As Map
77 | Return parentmap.Get(key)
78 | End Sub
79 |
80 | Sub getUrl As String
81 | Dim url As String = "http://127.0.0.1:8080/ocr"
82 | If File.Exists(File.DirApp,"preferences.conf") Then
83 | Try
84 | Dim preferencesMap As Map = readJsonAsMap(File.ReadString(File.DirApp,"preferences.conf"))
85 | url=getMap("crnn",getMap("api",preferencesMap)).GetDefault("url",url)
86 | Catch
87 | Log(LastException)
88 | End Try
89 | End If
90 | Return url
91 | End Sub
92 |
93 | Sub readJsonAsMap(s As String) As Map
94 | Dim json As JSONParser
95 | json.Initialize(s)
96 | Return json.NextObject
97 | End Sub
98 |
--------------------------------------------------------------------------------
/deeplMT/deeplMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=byteconverter
6 | Library11=encryption
7 | Library2=jfx
8 | Library3=json
9 | Library4=jxmlsax
10 | Library5=xmlbuilder
11 | Library6=jxui
12 | Library7=javaobject
13 | Library8=jokhttputils2
14 | Library9=jstringutils
15 | Module1=deeplMTPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=11
18 | NumberOfModules=1
19 | Version=8.8
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 |
30 | End Sub
31 |
32 | Sub AppStart (Form1 As Form, Args() As String)
33 | MainForm = Form1
34 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
35 | MainForm.Show
36 | Dim n As deeplMTPlugin
37 | n.Initialize
38 | Dim map1 As Map
39 | map1.Initialize
40 | 'wait for (n.translate("BasicCAT Documentation."&CRLF&"Sentence2.","en","zh",CreateMap("api":CreateMap("deepl":map1)))) complete (result As String)
41 | wait for (n.batchTranslate(Array("BasicCAT Documentation."&CRLF&"Sentence2.","Paragraph2"),"en","zh",CreateMap("api":CreateMap("deepl":map1)))) complete (result As Object)
42 | Log(result)
43 | End Sub
44 |
45 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
46 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
47 | Return True
48 | End Sub
49 |
--------------------------------------------------------------------------------
/deeplMT/deeplMT.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=deeplMTPlugin,ConvertLang,44,0,Main,Process_Globals,7,0,Main,AppStart,21,6,deeplMTPlugin,Initialize,6,0,deeplMTPlugin,batchTranslate,60,6,deeplMTPlugin,Run,23,1,deeplMTPlugin,translate,94,6
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/deeplfreeMT/README.md:
--------------------------------------------------------------------------------
1 | Free DeepL API using this docker repo: https://hub.docker.com/repository/docker/zu1k/deepl
--------------------------------------------------------------------------------
/deeplfreeMT/deeplfreeMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=byteconverter
6 | Library11=encryption
7 | Library2=jfx
8 | Library3=json
9 | Library4=jxmlsax
10 | Library5=xmlbuilder
11 | Library6=jxui
12 | Library7=javaobject
13 | Library8=jokhttputils2
14 | Library9=jstringutils
15 | Module1=deeplfreeMTPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=11
18 | NumberOfModules=1
19 | Version=8.9
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 |
30 | End Sub
31 |
32 | Sub AppStart (Form1 As Form, Args() As String)
33 | MainForm = Form1
34 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
35 | MainForm.Show
36 | Dim n As deeplfreeMTPlugin
37 | n.Initialize
38 | Dim map1 As Map
39 | map1.Initialize
40 | wait for (n.translate("BasicCAT Documentation."&CRLF&"Sentence2.","en","zh",CreateMap("api":CreateMap("deepl":map1)))) complete (result As String)
41 | 'wait for (n.batchTranslate(Array("BasicCAT Documentation."&CRLF&"Sentence2.","Paragraph2"),"en","zh",CreateMap("api":CreateMap("deepl":map1)))) complete (result As Object)
42 | Log(result)
43 | End Sub
44 |
45 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
46 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
47 | Return True
48 | End Sub
49 |
--------------------------------------------------------------------------------
/deeplfreeMT/deeplfreeMT.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=deeplfreeMTPlugin,Initialize,8,0,deeplfreeMTPlugin,translate,91,6,deeplfreeMTPlugin,Run,26,3,deeplfreeMTPlugin,ConvertLang,38,0,Main,AppStart,19,1
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/deeplfreeMT/deeplfreeMTPlugin.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=Class
5 | Version=4.2
6 | @EndOfDesignText@
7 | Sub Class_Globals
8 | Private fx As JFX
9 | End Sub
10 |
11 | 'Initializes the object. You can NOT add parameters to this method!
12 | Public Sub Initialize() As String
13 | Log("Initializing plugin " & GetNiceName)
14 | ' Here return a key to prevent running unauthorized plugins
15 | Return "MyKey"
16 | End Sub
17 |
18 | ' must be available
19 | public Sub GetNiceName() As String
20 | Return "deeplfreeMT"
21 | End Sub
22 |
23 | ' must be available
24 | public Sub Run(Tag As String, Params As Map) As ResumableSub
25 | Select Tag
26 | Case "getParams"
27 | Dim paramsList As List
28 | paramsList.Initialize
29 | paramsList.Add("url")
30 | Return paramsList
31 | Case "translate"
32 | wait for (translate(Params.Get("source"),Params.Get("sourceLang"),Params.Get("targetLang"),Params.Get("preferencesMap"))) complete (result As String)
33 | Return result
34 | Case "supportBatchTranslation"
35 | Return False
36 | Case "getDefaultParamValues"
37 | Return CreateMap("url":"http://service.basiccat.org:8080/")
38 | End Select
39 | Return ""
40 | End Sub
41 |
42 |
43 | Sub ConvertLang(lang As String) As String
44 | Return lang.ToUpperCase
45 | End Sub
46 |
47 | Sub translate(source As String,sourceLang As String,targetLang As String,preferencesMap As Map) As ResumableSub
48 | sourceLang=ConvertLang(sourceLang)
49 | targetLang=ConvertLang(targetLang)
50 |
51 | Dim target As String
52 | Dim job As HttpJob
53 | job.Initialize("job",Me)
54 | Dim url As String = "http://service.basiccat.org:8080/"
55 | Try
56 | url=getMap("deepl",getMap("mt",preferencesMap)).GetDefault("url","http://service.basiccat.org:8080/")
57 | Catch
58 | Log(LastException)
59 | End Try
60 |
61 | '{"text": "have a try", "source_lang": "auto", "target_lang": "ZH"}
62 | Dim params As Map
63 | params.Initialize
64 | params.Put("text",source)
65 | params.Put("source_lang",sourceLang)
66 | params.Put("target_lang",targetLang)
67 |
68 | Dim jsonG As JSONGenerator
69 | jsonG.Initialize(params)
70 |
71 | job.PostString(url&"translate",jsonG.ToString)
72 | wait For (job) JobDone(job As HttpJob)
73 | If job.Success Then
74 | Try
75 | Log(job.GetString)
76 | Dim json As JSONParser
77 | json.Initialize(job.GetString)
78 | target = json.NextObject.Get("data")
79 | Catch
80 | target=""
81 | Log(LastException)
82 | End Try
83 | Else
84 | target=""
85 | End If
86 | job.Release
87 | Return target
88 | End Sub
89 |
90 |
91 | Sub getMap(key As String,parentmap As Map) As Map
92 | Return parentmap.Get(key)
93 | End Sub
94 |
--------------------------------------------------------------------------------
/deepseekMT/deepseekMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans,HU2_ACCEPTALL
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=byteconverter
6 | Library11=encryption
7 | Library2=jfx
8 | Library3=json
9 | Library4=jxmlsax
10 | Library5=xmlbuilder
11 | Library6=jxui
12 | Library7=javaobject
13 | Library8=jokhttputils2
14 | Library9=jstringutils
15 | Module1=deepseekMTPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=11
18 | NumberOfModules=1
19 | Version=8.9
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 |
30 | End Sub
31 |
32 | Sub AppStart (Form1 As Form, Args() As String)
33 | MainForm = Form1
34 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
35 | MainForm.Show
36 | Dim n As deepseekMTPlugin
37 | n.Initialize
38 | Dim map1 As Map
39 | map1.Initialize
40 | map1.Put("key","key")
41 |
42 | Dim terms As Map
43 | terms.Initialize
44 | 'map1.Put("host","https://37cb-35-243-195-191.ngrok-free.app")
45 | 'map1.Put("model","gpt-4")
46 | 'map1.Put("prompt",$"翻译下述内容至中文: {source}"$)
47 | 'wait for (n.translate("Do you want to have more cake, Jenny?","en","zh",CreateMap("mt":CreateMap("deepseek":map1)),CreateMap("Jenny":"珍妮"))) complete (result As String)
48 | 'wait for (n.batchTranslate(Array("Do you want to have more cake, Jenny?"),"en","zh",CreateMap("mt":CreateMap("chatGPT":map1)),CreateMap("Jenny":"珍妮"))) complete (result As Object)
49 | wait for (n.translate("BasicCAT Documentation."&CRLF&"Sentence2.","en","zh",CreateMap("mt":CreateMap("deepseek":map1)),terms)) complete (result As String)
50 | 'Dim terms As Map
51 | 'terms.Initialize
52 | 'Dim textToTranslate As List = Array("お前には夏休みの間","我が天文部手伝いをしてもらう","いつか必ず","地に落ちるのだから","失敗です!!","有人ロケット「あさがお」が爆発!","日本初の有人宇宙飛行は失敗しました!!")
53 | 'wait for (n.batchTranslate(Array("BasicCAT Documentation."&CRLF&"Sentence2.","Paragraph2"),"en","zh",CreateMap("mt":CreateMap("chatGPT":map1)))) complete (result As Object)
54 | 'wait for (n.batchTranslate(textToTranslate,"ja","zh",CreateMap("mt":CreateMap("deepseek":map1)),terms)) complete (result As Object)
55 | Log(result)
56 | End Sub
57 |
58 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
59 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
60 | Return True
61 | End Sub
62 |
--------------------------------------------------------------------------------
/doctrOCR/plugin/doctrOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=javaobject
5 | Library10=jbitmapcreator
6 | Library2=jcore
7 | Library3=jfx
8 | Library4=jokhttputils2
9 | Library5=json
10 | Library6=jstringutils
11 | Library7=jxmlsax
12 | Library8=jxui
13 | Library9=xmlbuilder
14 | Module1=doctrOCRPlugin
15 | NumberOfFiles=0
16 | NumberOfLibraries=10
17 | NumberOfModules=1
18 | Version=8.9
19 | @EndOfDesignText@
20 | #Region Project Attributes
21 | #MainFormWidth: 600
22 | #MainFormHeight: 600
23 | #End Region
24 |
25 | Sub Process_Globals
26 | Private fx As JFX
27 | Public MainForm As Form
28 |
29 | End Sub
30 |
31 | Sub AppStart (Form1 As Form, Args() As String)
32 | MainForm = Form1
33 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
34 | MainForm.Show
35 | Dim n As doctrOCRPlugin
36 | n.Initialize
37 | 'wait for (n.Run("SetCombination",CreateMap("combination":"detect only"))) complete (done As Object)
38 | wait for (n.GetTextWithLocation(fx.LoadImage(File.DirApp,"image.jpg"),"ch")) complete (result As List)
39 | Log(result)
40 | 'wait for (n.translate("Hello","en","zh")) complete (result As String)
41 | 'Log(result)
42 | End Sub
43 |
44 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
45 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
46 | Return True
47 | End Sub
48 |
--------------------------------------------------------------------------------
/doctrOCR/readme.md:
--------------------------------------------------------------------------------
1 | # doctrOCR
2 |
3 |
4 | 1. Install Python and DocTROCR.
5 | 2. Install bottle and Paste: `pip install bottle Paste`
6 | 3. Run the following to start the server: `python server.py`
7 | 4. [Download the plugin files](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/ImageTrans_plugins.zip) and put `doctrOCRPlugin.jar` and `doctrOCRPlugin.xml` into the plugins folder of ImageTrans.
8 |
9 | For convenience, you can directly use the Windows package: [link](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/DocTROCR.zip).
10 |
11 | Unzip the file and start `run.bat` to run the server. You need to keep the server running in the background.
12 |
13 | If you failed to download the model, you can [download the models](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/doctr-models.zip) and unzip them to `C:\Users\\.cache\doctr\models\`.
14 |
15 |
16 |
--------------------------------------------------------------------------------
/doctrOCR/server/server.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import os
4 | import time
5 | import datetime
6 | from bottle import route, run, template, request, static_file
7 | import json
8 | from doctr.io import DocumentFile
9 | from doctr.models import ocr_predictor
10 |
11 | @route('/ocr', method='POST')
12 | def ocr():
13 | upload = request.files.get('upload')
14 | name, ext = os.path.splitext(upload.filename)
15 | if ext.lower() not in ('.png','.jpg','.jpeg'):
16 | return "File extension not allowed."
17 | timestamp=str(int(time.time()*1000))
18 | savedName=timestamp+ext
19 | save_path = "./uploaded/"
20 | if not os.path.exists(save_path):
21 | os.makedirs(save_path)
22 | file_path = "{path}/{file}".format(path=save_path, file=savedName)
23 | if os.path.exists(file_path)==True:
24 | os.remove(file_path)
25 | upload.save(file_path)
26 | f = open(file_path,"rb")
27 | image = f.read()
28 | f.close()
29 | doc = DocumentFile.from_images([image])
30 | ret = {}
31 | result = predictor(doc)
32 | text_lines=[]
33 | for page in result.pages:
34 | h, w = page.dimensions
35 | for block in page.blocks:
36 | for line in block.lines:
37 | top_left_x = line.geometry[0][0] * w
38 | top_left_y = line.geometry[0][1] * h
39 | bottom_right_x = line.geometry[1][0] * w
40 | bottom_right_y = line.geometry[1][1] * h
41 | text_line = {}
42 | text_line["x0"] = top_left_x
43 | text_line["y0"] = top_left_y
44 | text_line["x1"] = bottom_right_x
45 | text_line["y1"] = top_left_y
46 | text_line["x2"] = bottom_right_x
47 | text_line["y2"] = bottom_right_y
48 | text_line["x3"] = top_left_x
49 | text_line["y3"] = bottom_right_y
50 | text_line["text"]= " ".join(word.value for word in line.words)
51 | text_lines.append(text_line)
52 | os.remove(file_path)
53 | ret["text_lines"]=text_lines
54 | return ret
55 |
56 | @route('/')
57 | def server_static(filepath):
58 | return static_file(filepath, root='www')
59 |
60 | predictor = ocr_predictor(
61 | det_arch='db_resnet34',
62 | reco_arch='parseq',
63 | pretrained=True,
64 | )
65 | run(server="paste",host='127.0.0.1', port=8189)
66 |
67 |
--------------------------------------------------------------------------------
/doctrOCR/server/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Upload
6 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/easyOCR/plugin/easyOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library2=jfx
6 | Library3=json
7 | Library4=jxmlsax
8 | Library5=xmlbuilder
9 | Library6=jxui
10 | Library7=javaobject
11 | Library8=jokhttputils2
12 | Library9=jstringutils
13 | Module1=easyOCRPlugin
14 | NumberOfFiles=0
15 | NumberOfLibraries=9
16 | NumberOfModules=1
17 | Version=7.8
18 | @EndOfDesignText@
19 | #Region Project Attributes
20 | #MainFormWidth: 600
21 | #MainFormHeight: 600
22 | #End Region
23 |
24 | Sub Process_Globals
25 | Private fx As JFX
26 | Public MainForm As Form
27 |
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | 'Dim n As niuTransMTPlugin
35 | 'n.Initialize
36 | 'wait for (n.translate("Hello","en","zh")) complete (result As String)
37 | 'Log(result)
38 | End Sub
39 |
40 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
41 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
42 | Return True
43 | End Sub
44 |
--------------------------------------------------------------------------------
/easyOCR/plugin/easyOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=easyOCRPlugin,getLangs,38,6,easyOCRPlugin,Run,23,0,easyOCRPlugin,GetTextWithLocation,223,0,easyOCRPlugin,ocr,262,0,easyOCRPlugin,textLinesToBoxes,284,0,easyOCRPlugin,GetNiceName,13,0,easyOCRPlugin,readJsonAsMap,307,0,easyOCRPlugin,getUrl,294,0
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/easyOCR/server/server_easyocr.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import os
4 | import time
5 | import datetime
6 | from bottle import route, run, template, request, static_file
7 | import json
8 | import easyocr
9 |
10 | @route('/ocr', method='POST')
11 | def ocr():
12 | upload = request.files.get('upload')
13 | lang = request.forms.get('lang')
14 | print(lang)
15 | global current_lang
16 | global reader
17 | if current_lang!=lang:
18 | current_lang=lang
19 | reader = easyocr.Reader([current_lang],model_storage_directory="./")
20 |
21 | name, ext = os.path.splitext(upload.filename)
22 | print(ext.lower())
23 | if ext.lower() not in ('.png','.jpg','.jpeg'):
24 | return "File extension not allowed."
25 | timestamp=str(int(time.time()*1000))
26 | savedName=timestamp+ext
27 | save_path = "./uploaded/"
28 | if not os.path.exists(save_path):
29 | os.makedirs(save_path)
30 | file_path = "{path}/{file}".format(path=save_path, file=savedName)
31 | if os.path.exists(file_path)==True:
32 | os.remove(file_path)
33 | upload.save(file_path)
34 | ret = {}
35 | result = reader.readtext(file_path)
36 | text_lines=[]
37 | for line in result:
38 | text_line={}
39 | index=0
40 | for coord in line[0]:
41 | text_line["x"+str(index)]=int(coord[0])
42 | text_line["y"+str(index)]=int(coord[1])
43 | index=index+1
44 | text_line["text"]=line[1]
45 | text_lines.append(text_line)
46 | os.remove(file_path)
47 | ret["text_lines"]=text_lines
48 | return ret
49 |
50 |
51 | @route('/')
52 | def server_static(filepath):
53 | return static_file(filepath, root='www')
54 |
55 | current_lang="en"
56 | reader = easyocr.Reader([current_lang],model_storage_directory="./")
57 | run(server="paste",host='127.0.0.1', port=8080)
58 |
59 |
--------------------------------------------------------------------------------
/easyOCR/server/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Upload
6 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/eztransMT/eztransMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=byteconverter
6 | Library11=encryption
7 | Library2=jfx
8 | Library3=json
9 | Library4=jxmlsax
10 | Library5=xmlbuilder
11 | Library6=jxui
12 | Library7=javaobject
13 | Library8=jokhttputils2
14 | Library9=jstringutils
15 | Module1=eztransMTPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=11
18 | NumberOfModules=1
19 | Version=8.9
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 |
30 | End Sub
31 |
32 | Sub AppStart (Form1 As Form, Args() As String)
33 | MainForm = Form1
34 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
35 | MainForm.Show
36 | Dim n As eztransMTPlugin
37 | n.Initialize
38 | wait for (n.translate("おはよう!?","en","zh",null)) complete (result As String)
39 | Log(result)
40 | End Sub
41 |
42 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
43 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
44 | Return True
45 | End Sub
46 |
--------------------------------------------------------------------------------
/eztransMT/eztransMT.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=eztransMTPlugin,translate,41,0,Main,Process_Globals,9,0,eztransMTPlugin,Run,24,0,Main,AppStart,17,2
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/eztransMT/eztransMTPlugin.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=Class
5 | Version=4.2
6 | @EndOfDesignText@
7 | Sub Class_Globals
8 | Private fx As JFX
9 | End Sub
10 |
11 | 'Initializes the object. You can NOT add parameters to this method!
12 | Public Sub Initialize() As String
13 | Log("Initializing plugin " & GetNiceName)
14 | ' Here return a key to prevent running unauthorized plugins
15 | Return "MyKey"
16 | End Sub
17 |
18 | ' must be available
19 | public Sub GetNiceName() As String
20 | Return "eztransMT"
21 | End Sub
22 |
23 | ' must be available
24 | public Sub Run(Tag As String, Params As Map) As ResumableSub
25 | Log("run"&Params)
26 | Select Tag
27 | Case "getParams"
28 | Dim paramsList As List
29 | paramsList.Initialize
30 | paramsList.Add("path")
31 | Return paramsList
32 | Case "translate"
33 | wait for (translate(Params.Get("source"),Params.Get("sourceLang"),Params.Get("targetLang"),Params.Get("preferencesMap"))) complete (result As String)
34 | Return result
35 | End Select
36 | Return ""
37 | End Sub
38 |
39 |
40 | Sub translate(source As String, sourceLang As String, targetLang As String,preferencesMap As Map) As ResumableSub
41 | Dim target As String
42 | Dim params As String
43 | Dim su As StringUtils
44 | source=su.EncodeUrl(source,"UTF-8")
45 | params="text="&source
46 | Dim job As HttpJob
47 | job.Initialize("job",Me)
48 | job.Download("http://127.0.0.1:8080/translate?"¶ms)
49 | wait For (job) JobDone(job As HttpJob)
50 | If job.Success Then
51 | Log(job.GetString)
52 | target=job.GetString
53 | Else
54 | target=""
55 | End If
56 | job.Release
57 | Return target
58 | End Sub
59 |
60 | Sub getMap(key As String,parentmap As Map) As Map
61 | Return parentmap.Get(key)
62 | End Sub
63 |
--------------------------------------------------------------------------------
/geminiMT/geminiMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans,HU2_ACCEPTALL
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=byteconverter
6 | Library11=encryption
7 | Library2=jfx
8 | Library3=json
9 | Library4=jxmlsax
10 | Library5=xmlbuilder
11 | Library6=jxui
12 | Library7=javaobject
13 | Library8=jokhttputils2
14 | Library9=jstringutils
15 | Module1=geminiMTPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=11
18 | NumberOfModules=1
19 | Version=8.8
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 | End Sub
30 |
31 | Sub AppStart (Form1 As Form, Args() As String)
32 | MainForm = Form1
33 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
34 | MainForm.Show
35 | Dim n As geminiMTPlugin
36 | n.Initialize
37 | Dim map1 As Map
38 | map1.Initialize
39 | map1.Put("key","your key")
40 | map1.Put("endpoint","https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent")
41 | 'map1.Put("prompt","Translate the following into {langcode}: {source}")
42 | wait for (n.translate("Do you want to have more cake, Jenny?","en","zh",CreateMap("mt":CreateMap("gemini":map1)),CreateMap("JENNY":"詹尼"))) complete (result As String)
43 | 'wait for (n.batchTranslate(Array("BasicCAT Documentation.","Sentence2."),"en","zh",CreateMap("mt":CreateMap("gemini":map1)))) complete (result As List)
44 | Log(result)
45 | End Sub
46 |
47 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
48 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
49 | Return True
50 | End Sub
51 |
--------------------------------------------------------------------------------
/geminiMT/readme.md:
--------------------------------------------------------------------------------
1 | See
--------------------------------------------------------------------------------
/geminiOCR/geminiOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans,HU2_ACCEPTALL
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=byteconverter
6 | Library11=encryption
7 | Library2=jfx
8 | Library3=json
9 | Library4=jxmlsax
10 | Library5=xmlbuilder
11 | Library6=jxui
12 | Library7=javaobject
13 | Library8=jokhttputils2
14 | Library9=jstringutils
15 | Module1=geminiOCRPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=11
18 | NumberOfModules=1
19 | Version=8.8
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 | End Sub
30 |
31 | Sub AppStart (Form1 As Form, Args() As String)
32 | MainForm = Form1
33 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
34 | MainForm.Show
35 | Dim n As geminiOCRPlugin
36 | n.Initialize
37 | Dim img As B4XBitmap = fx.LoadImage(File.DirApp,"test.jpg")
38 | wait for (n.GetTextWithLocation(img)) complete (result As Object)
39 | 'wait for (n.batchTranslate(Array("BasicCAT Documentation.","Sentence2."),"en","zh",CreateMap("mt":CreateMap("gemini":map1)))) complete (result As List)
40 | Log(result)
41 | End Sub
42 |
43 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
44 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
45 | Return True
46 | End Sub
47 |
--------------------------------------------------------------------------------
/googleMT/googleMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=byteconverter
6 | Library11=encryption
7 | Library2=jfx
8 | Library3=json
9 | Library4=jxmlsax
10 | Library5=xmlbuilder
11 | Library6=jxui
12 | Library7=javaobject
13 | Library8=jokhttputils2
14 | Library9=jstringutils
15 | Module1=googleMTPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=11
18 | NumberOfModules=1
19 | Version=8.9
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 |
30 | End Sub
31 |
32 | Sub AppStart (Form1 As Form, Args() As String)
33 | MainForm = Form1
34 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
35 | MainForm.Show
36 | Dim map1 As Map
37 | map1.Initialize
38 | map1.Put("api",CreateMap("google":CreateMap("key":"")))
39 | Dim n As googleMTPlugin
40 | n.Initialize
41 | 'wait for (n.translate("BasicCAT Documentation","en","zh",map1)) complete (result As String)
42 | 'Log(result)
43 | 'wait for (n.batchTranslate(Array("Sentence 1","Sentence 2"),"en","zh",map1)) complete (targetList As List)
44 | 'Log(targetList)
45 | wait for (n.batchTranslate(Array("今日からみんなと勉強する事になった、灰原哀さんです!","みんな仲よく してあげてね"),"ja","zh",map1)) complete (targetList As List)
46 | Log(targetList)
47 | End Sub
48 |
49 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
50 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
51 | Return True
52 | End Sub
53 |
--------------------------------------------------------------------------------
/googleMT/googleMT.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=googleMTPlugin,GetNiceName,13,0,googleMTPlugin,Class_Globals,0,0,googleMTPlugin,Initialize,11,0,Main,Process_Globals,9,0,googleMTPlugin,Run,29,1,googleMTPlugin,translate,112,6,googleMTPlugin,batchTranslate,69,6,Main,AppStart,17,6
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/googleOCR/Utils.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=StaticCode
5 | Version=7.8
6 | @EndOfDesignText@
7 | 'Static code module
8 | Sub Process_Globals
9 | Private fx As JFX
10 | End Sub
11 |
12 |
13 | Sub OverlappingPercent(boxGeometry1 As Map,boxGeometry2 As Map) As Double
14 | 'Log("boxGeometry1"&boxGeometry1)
15 | 'Log("boxGeometry2"&boxGeometry2)
16 | Dim X1,Y1,W1,H1 As Int
17 | X1=boxGeometry1.Get("X")
18 | Y1=boxGeometry1.Get("Y")
19 | W1=boxGeometry1.Get("width")
20 | H1=boxGeometry1.Get("height")
21 | Dim X2,Y2,W2,H2 As Int
22 | X2=boxGeometry2.Get("X")
23 | Y2=boxGeometry2.Get("Y")
24 | W2=boxGeometry2.Get("width")
25 | H2=boxGeometry2.Get("height")
26 | Dim theSmallerX,theBiggerX,theSmallerXWidth,theBiggerXWidth As Int
27 | If theSmallerOneIndex(X1,X2)=0 Then
28 | theSmallerX=X1
29 | theBiggerX=X2
30 | theSmallerXWidth=W1
31 | theBiggerXWidth=W2
32 | Else
33 | theSmallerX=X2
34 | theBiggerX=X1
35 | theSmallerXWidth=W2
36 | theBiggerXWidth=W1
37 | End If
38 | Dim theSmallerY,theBiggerY,theSmallerYHeight,theBiggerYHeight As Int
39 | If theSmallerOneIndex(Y1,Y2)=0 Then
40 | theSmallerY=Y1
41 | theBiggerY=Y2
42 | theSmallerYHeight=H1
43 | theBiggerYHeight=H2
44 | Else
45 | theSmallerY=Y2
46 | theBiggerY=Y1
47 | theSmallerYHeight=H2
48 | theBiggerYHeight=H1
49 | End If
50 |
51 | If theSmallerX+theSmallerXWidth>=theBiggerX And theSmallerY+theSmallerYHeight>=theBiggerY Then
52 | 'overlapping
53 | Dim overlappingArea As Double = (theSmallerOne(X1+W1,X2+W2)-theBiggerX)*(theSmallerOne(Y1+H1,Y2+H2)-theBiggerY)
54 | Dim area1,area2 As Double
55 | area1=W1*H1
56 | area2=W2*H2
57 | Dim theSmallArea As Int=theSmallerOne(area1,area2)
58 | 'Log("overlappingArea:"&overlappingArea)
59 | 'Log("theSmallArea:"&theSmallArea)
60 | 'Log("overlapping percent:")
61 | 'Log(overlappingArea/theSmallArea)
62 | Return overlappingArea/theSmallArea
63 | Else
64 | Return 0
65 | End If
66 | End Sub
67 |
68 | Sub theSmallerOneIndex(X1 As Int,X2 As Int) As Int
69 | If X1
2 |
3 | Detailed guide: https://www.basiccat.org/how-to-use-google-cloud-in-imagetrans/#enable-ocr-via-google-drive
4 |
--------------------------------------------------------------------------------
/googledriveOCR/server/googledriveOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=jshell
6 | Library2=jfx
7 | Library3=json
8 | Library4=jxmlsax
9 | Library5=xmlbuilder
10 | Library6=jxui
11 | Library7=javaobject
12 | Library8=jokhttputils2
13 | Library9=jstringutils
14 | Module1=googledriveOCRPlugin
15 | NumberOfFiles=0
16 | NumberOfLibraries=10
17 | NumberOfModules=1
18 | Version=8.9
19 | @EndOfDesignText@
20 | #Region Project Attributes
21 | #MainFormWidth: 600
22 | #MainFormHeight: 600
23 | #End Region
24 |
25 | Sub Process_Globals
26 | Private fx As JFX
27 | Public MainForm As Form
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim n As googledriveOCRPlugin
35 | n.Initialize
36 | wait for (n.GetText(fx.LoadImage(File.DirApp,"image.jpg"))) Complete (text As String)
37 | Log(text)
38 | 'wait for (n.translate("Hello","en","zh")) complete (result As String)
39 | 'Log(result)
40 | End Sub
41 |
42 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
43 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
44 | Return True
45 | End Sub
46 |
--------------------------------------------------------------------------------
/googledriveOCR/server/googledriveOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=Main,Process_Globals,9,0,Main,AppStart,17,1,googledriveOCRPlugin,getMap,86,0,googledriveOCRPlugin,readJsonAsMap,95,0,googledriveOCRPlugin,getUrl,74,1,googledriveOCRPlugin,ImageToBytes,71,0,googledriveOCRPlugin,GetNiceName,12,0,googledriveOCRPlugin,Run,36,6,googledriveOCRPlugin,getLangs,48,6,googledriveOCRPlugin,GetText,60,6
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/googledriveOCR/server/googledriveOCRPlugin.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=Class
5 | Version=4.2
6 | @EndOfDesignText@
7 | Sub Class_Globals
8 | Private fx As JFX
9 | End Sub
10 |
11 | 'Initializes the object. You can NOT add parameters to this method!
12 | Public Sub Initialize() As String
13 | Log("Initializing plugin " & GetNiceName)
14 | ' Here return a key to prevent running unauthorized plugins
15 | Return "MyKey"
16 | End Sub
17 |
18 | ' must be available
19 | public Sub GetNiceName() As String
20 | Return "google_driveOCR"
21 | End Sub
22 |
23 | ' must be available
24 | public Sub Run(Tag As String, Params As Map) As ResumableSub
25 | Log("run"&Params)
26 | Select Tag
27 | Case "getParams"
28 | Dim paramsList As List
29 | paramsList.Initialize
30 | paramsList.Add("url")
31 | Return paramsList
32 | Case "getText"
33 | wait for (GetText(Params.Get("img"))) complete (result As String)
34 | Return result
35 | Case "getTextWithLocation"
36 | Dim list1 As List
37 | list1.Initialize
38 | Return list1
39 | Case "getLangs"
40 | Return getLangs
41 | End Select
42 | Return ""
43 | End Sub
44 |
45 | Sub getLangs As Map
46 | Dim result As Map
47 | result.Initialize
48 | Dim names,codes As List
49 | names.Initialize
50 | codes.Initialize
51 | names.Add("Auto detect")
52 | codes.Add("auto")
53 | result.Put("names",names)
54 | result.Put("codes",codes)
55 | Return result
56 | End Sub
57 |
58 | Sub GetText(img As B4XBitmap) As ResumableSub
59 | Dim result As String
60 | Dim job As HttpJob
61 | job.Initialize("",Me)
62 | job.PostBytes(getUrl,ImageToBytes(img))
63 | wait For (job) JobDone(job As HttpJob)
64 | If job.Success Then
65 | result=job.GetString
66 | Else
67 | result=job.ErrorMessage
68 | End If
69 | job.Release
70 | Return result
71 | End Sub
72 |
73 | private Sub ImageToBytes(Image As B4XBitmap) As Byte()
74 | Dim out As OutputStream
75 | out.InitializeToBytesArray(0)
76 | Image.WriteToStream(out, 100, "JPEG")
77 | out.Close
78 | Return out.ToBytesArray
79 | End Sub
80 |
81 | Sub getUrl As String
82 | Dim url As String = "http://127.0.0.1:8090/ocr"
83 | If File.Exists(File.DirApp,"preferences.conf") Then
84 | Try
85 | Dim preferencesMap As Map = readJsonAsMap(File.ReadString(File.DirApp,"preferences.conf"))
86 | url=getMap("google_drive",getMap("api",preferencesMap)).GetDefault("url",url)
87 | Catch
88 | Log(LastException)
89 | End Try
90 | End If
91 | Return url
92 | End Sub
93 |
94 | Sub getMap(key As String,parentmap As Map) As Map
95 | Return parentmap.Get(key)
96 | End Sub
97 |
98 | Sub readJsonAsMap(s As String) As Map
99 | Dim json As JSONParser
100 | json.Initialize(s)
101 | Return json.NextObject
102 | End Sub
103 |
--------------------------------------------------------------------------------
/imgBaiduOCR/imgbaiduOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=byteconverter
5 | Library10=javaobject
6 | Library2=encryption
7 | Library3=jcore
8 | Library4=jfx
9 | Library5=jokhttputils2
10 | Library6=json
11 | Library7=jsql
12 | Library8=jstringutils
13 | Library9=jxui
14 | Module1=imgbaiduOCRPlugin
15 | Module2=Localizator
16 | NumberOfFiles=0
17 | NumberOfLibraries=10
18 | NumberOfModules=2
19 | Version=8.9
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 | End Sub
30 |
31 | Sub AppStart (Form1 As Form, Args() As String)
32 | MainForm = Form1
33 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
34 | MainForm.Show
35 | 'Dim Params As Map
36 | 'Params.Initialize
37 | 'Params.Put("img",fx.LoadImage(File.DirApp,"test.jpg"))
38 | 'Params.Put("lang","auto")
39 | 'Params.Put("targetLang","en")
40 | 'Dim t As imgbaiduPlugin
41 | 't.Initialize
42 | 'wait for (t.Run("getTextWithLocation",Params)) Complete (result As Object)
43 | 'Log(result)
44 | End Sub
45 |
46 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
47 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
48 | Return True
49 | End Sub
50 |
--------------------------------------------------------------------------------
/imgBaiduOCR/readme.md:
--------------------------------------------------------------------------------
1 | See https://github.com/xulihang/ImageTrans-docs/issues/470
--------------------------------------------------------------------------------
/macOCR/macOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=jshell
6 | Library2=jfx
7 | Library3=json
8 | Library4=jxmlsax
9 | Library5=xmlbuilder
10 | Library6=jxui
11 | Library7=javaobject
12 | Library8=jokhttputils2
13 | Library9=jstringutils
14 | Module1=macOCRPlugin
15 | NumberOfFiles=0
16 | NumberOfLibraries=10
17 | NumberOfModules=1
18 | Version=8.9
19 | @EndOfDesignText@
20 | #Region Project Attributes
21 | #MainFormWidth: 600
22 | #MainFormHeight: 600
23 | #End Region
24 |
25 | Sub Process_Globals
26 | Private fx As JFX
27 | Public MainForm As Form
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim n As macOCRPlugin
35 | n.Initialize
36 | wait for (n.GetText(fx.LoadImage(File.DirApp,"image.jpg"),"chi_sim","")) Complete (text As String)
37 | wait for (n.GetTextWithLocation(fx.LoadImage(File.DirApp,"image.jpg"),"chi_sim","")) Complete (result As List)
38 | Log(text)
39 | Log(result)
40 | 'wait for (n.translate("Hello","en","zh")) complete (result As String)
41 | 'Log(result)
42 | End Sub
43 |
44 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
45 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
46 | Return True
47 | End Sub
48 |
--------------------------------------------------------------------------------
/macOCR/readme.md:
--------------------------------------------------------------------------------
1 | macOS's built-in OCR service.
2 |
3 |
4 | See
--------------------------------------------------------------------------------
/mangaOCR/GPU.md:
--------------------------------------------------------------------------------
1 | You have to install a Pytorch version with GPU support according to [this](https://pytorch.org/get-started/locally/#start-locally).
2 |
3 | If you are using the packaged version for Windows, you can try the following to install Pytorch.
4 |
5 | ## Option 1: Install with the Prepacked Packages
6 |
7 | 1. Download [torch_cu118_2.7z.001](https://github.com/xulihang/manga-image-translator/releases/download/packages/torch_cu118_2.7z.001) and [torch_cu118_2.7z.002](https://github.com/xulihang/manga-image-translator/releases/download/packages/torch_cu118_2.7z.002).
8 | 2. Use 7-zip to open `torch_cu118_2.7z.001`. Unzip the inner zip and unzip it to `Python3810\Lib\site-packages`. Remember to delete the folders in the `site-packages` folder starting with `torch` beforehand.
9 |
10 | ## Option 2: Install with Pip
11 |
12 | 1. Edit `Python3810\Scripts\pip.exe` and replace `D:\python3810\python.exe` to `python.exe`.
13 | 2. Go to the `Python3810` folder, and run the following command (you may have to update the command following the guide above):
14 |
15 | ```
16 | .\Scripts\pip.exe uninstall torch torchvision torchaudio
17 | .\Scripts\pip.exe install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
18 | ```
19 |
--------------------------------------------------------------------------------
/mangaOCR/list.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xulihang/ImageTrans_plugins/87a0b5937263fa14f5fcd1abe53446c2b87ef1b0/mangaOCR/list.jpg
--------------------------------------------------------------------------------
/mangaOCR/long_text.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xulihang/ImageTrans_plugins/87a0b5937263fa14f5fcd1abe53446c2b87ef1b0/mangaOCR/long_text.jpg
--------------------------------------------------------------------------------
/mangaOCR/normal.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xulihang/ImageTrans_plugins/87a0b5937263fa14f5fcd1abe53446c2b87ef1b0/mangaOCR/normal.jpg
--------------------------------------------------------------------------------
/mangaOCR/plugin/mangaOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=javaobject
5 | Library10=jsql
6 | Library2=jcore
7 | Library3=jfx
8 | Library4=jokhttputils2
9 | Library5=json
10 | Library6=jstringutils
11 | Library7=jxmlsax
12 | Library8=jxui
13 | Library9=xmlbuilder
14 | Module1=Localizator
15 | Module2=mangaOCRPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=10
18 | NumberOfModules=2
19 | Version=8.9
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 |
30 | End Sub
31 |
32 | Sub AppStart (Form1 As Form, Args() As String)
33 | MainForm = Form1
34 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
35 | MainForm.Show
36 | Dim p As mangaOCRPlugin
37 | p.Initialize
38 | 'wait for (p.CheckIsRunning) Complete (result As Object)
39 | 'Log(result)
40 | 'p.Run("SetCombination",CreateMap("combination":"long text (manga-ocr)"))
41 | 'wait for (p.GetTextLongTextMode(fx.LoadImage(File.DirApp,"test.jpg"))) Complete (result As String)
42 | 'Log(result)
43 | End Sub
44 |
45 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
46 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
47 | Return True
48 | End Sub
49 |
--------------------------------------------------------------------------------
/mangaOCR/plugin/mangaOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBookmarks2=
4 | ModuleBreakpoints0=
5 | ModuleBreakpoints1=
6 | ModuleBreakpoints2=
7 | ModuleClosedNodes0=
8 | ModuleClosedNodes1=
9 | ModuleClosedNodes2=
10 | NavigationStack=mangaOCRPlugin,Class_Globals,2,3,mangaOCRPlugin,getLangs,65,0,mangaOCRPlugin,GetTextLongTextMode,115,6,mangaOCRPlugin,BuildCombinations,61,6,mangaOCRPlugin,GetText,97,6,Main,AppStart,19,6,mangaOCRPlugin,Initialize,8,0,mangaOCRPlugin,Run,47,6,mangaOCRPlugin,CheckIsRunning,161,6,mangaOCRPlugin,getUrl,139,0
11 | SelectedBuild=0
12 | VisibleModules=2,1
13 |
--------------------------------------------------------------------------------
/mangaOCR/readme.md:
--------------------------------------------------------------------------------
1 | See:
2 |
3 | 1.
4 | 2.
5 |
6 | Install:
7 |
8 | 1. Install Python3 if it is not installed.
9 | 2. Install required packages: `pip3 install bottle==0.12.19 manga_ocr==0.1.4 Paste`. (Use terminal to run the commands.)
10 | 3. Download the [model](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/manga-ocr-model.zip) and unzip it into a folder.
11 | 4. Run the server: `python3 server_manga_ocr.py`.
12 | 5. Unzip the [plugin files](https://github.com/xulihang/ImageTrans-docs/files/10887754/manga-ocr-plugin.zip) in ImageTrans's `plugins` folder and restart ImageTrans. (optional for v1.9.0+)
13 |
14 | **For convenience**, you can also use the Windows package:
15 |
16 | 1. Download and unzip [manga-ocr](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/manga-ocr.zip).
17 | 2. Download the [model](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/manga-ocr-model.zip) and unzip it to manga-ocr's folder in the previous step. (if you do not download the model file, the program will download the model from the Internet.)
18 | 3. Run `run.bat` and wait for the server to get ready.
19 |
20 | If you need to enable GPU, please follow [this guide](GPU.md).
21 |
22 | ## Usage Note
23 |
24 | The mangaOCR works great for speech bubbles like the following one:
25 |
26 | 
27 |
28 | But it may not work well for the following long text line image by default:
29 |
30 | 
31 |
32 | For such a case, you can select the long text mode of the plugin which will crop the long text line images into segments for the OCR engine to extract the text. It should better be used in combination with a scene text detector which detects the text lines accurately like this one:
33 |
34 | 
35 |
36 | ## Text Detection Combination
37 |
38 | mangaOCR does not detect text. It can be used together with other text detection methods like the following ones:
39 |
40 | 1. Speech bubble detection models:
41 | 2. manga image translator (detect text lines):
42 |
43 | ## Port Settings
44 |
45 | You may need to update the port if you also need to run other local OCR engines:
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/mangaOCR/requirements.txt:
--------------------------------------------------------------------------------
1 | bottle==0.12.19
2 | manga_ocr==0.1.4
3 | Paste
4 |
--------------------------------------------------------------------------------
/mangaOCR/server/server_manga_ocr.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | from manga_ocr import MangaOcr
3 | import os
4 | import time
5 | import datetime
6 | from bottle import route, run, template, request, static_file
7 | import json
8 |
9 | @route('/ocr', method='POST')
10 | def ocr():
11 | upload = request.files.get('upload')
12 | name, ext = os.path.splitext(upload.filename)
13 | print(ext.lower())
14 | if ext.lower() not in ('.png','.jpg','.jpeg'):
15 | return "File extension not allowed."
16 | timestamp=str(int(time.time()*1000))
17 | savedName=timestamp+ext
18 | save_path = "./uploaded/"
19 | if not os.path.exists(save_path):
20 | os.makedirs(save_path)
21 | file_path = "{path}/{file}".format(path=save_path, file=savedName)
22 | if os.path.exists(file_path)==True:
23 | os.remove(file_path)
24 | upload.save(file_path)
25 | text = mocr(file_path)
26 | os.remove(file_path)
27 | return text
28 |
29 |
30 | @route('/')
31 | def server_static(filepath):
32 | return static_file(filepath, root='www')
33 |
34 | mocr = MangaOcr()
35 | run(server="paste",host='0.0.0.0', port=8080)
36 |
37 |
--------------------------------------------------------------------------------
/mangaOCR/server/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Upload
6 |
7 |
8 |
12 |
13 |
--------------------------------------------------------------------------------
/mangaTranslatorOCR/GPU.md:
--------------------------------------------------------------------------------
1 | Follow the link to enable GPU.
2 |
3 |
4 |
5 |
6 | If you are using the packaged version for Windows, you can try the following to install Pytorch.
7 |
8 | ## Option 1: Install with the Prepacked Packages
9 |
10 | 1. Download [torch_cu118_2.7z.001](https://github.com/xulihang/manga-image-translator/releases/download/packages/torch_cu118_2.7z.001) and [torch_cu118_2.7z.002](https://github.com/xulihang/manga-image-translator/releases/download/packages/torch_cu118_2.7z.002).
11 | 2. Use 7-zip to open `torch_cu118_2.7z.001`. Unzip the inner zip and unzip it to `Python3810\Lib\site-packages`. Remember to delete the folders in the `site-packages` folder starting with `torch` beforehand.
12 |
13 | Then create a file named `use_cuda` under the root of the project to enable GPU.
14 |
15 | ## Option 2: Install with Pip
16 |
17 | Go to the `Python` folder, and run the following command (you may have to update the command following the guide above):
18 |
19 | ```
20 | .\Scripts\pip.exe uninstall torch torchvision torchaudio
21 | .\Scripts\pip.exe install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
22 | ```
23 |
24 | Then create a file named `use_cuda` under the root of the project to enable GPU.
25 |
--------------------------------------------------------------------------------
/mangaTranslatorOCR/README.md:
--------------------------------------------------------------------------------
1 | See
2 |
3 | What does the plugin do:
4 |
5 | 1. Detect the text lines as a scene text detector.
6 | 2. Detect the text lines and recognize the text as an OCR engine.
7 | 3. Detect the color of the text. [#issue478](https://github.com/xulihang/ImageTrans-docs/issues/478)
8 | 4. Create the text mask and remove the text using inpainting. (You need to have the [ExternalInpaint](https://github.com/xulihang/ImageTrans_plugins/tree/master/ExternalInpaint) and [ExternalMaskGen](https://github.com/xulihang/ImageTrans_plugins/tree/master/ExternalMaskGen) plugins as well. They are included in ImageTrans by default.)
9 |
10 |
11 | Installation:
12 |
13 | 1. Download the Windows package of manga-image-translator: [manga-image-translator.zip](https://github.com/xulihang/manga-image-translator/releases/download/packages/manga-image-translator.zip) and unzip it into a folder.
14 | 2. Download the model files into the folder in the previous step: [detect.ckpt
15 | ](https://github.com/zyddnys/manga-image-translator/releases/download/beta-0.2.1/detect.ckpt), [ocr.ckpt](https://github.com/zyddnys/manga-image-translator/releases/download/beta-0.2.1/ocr.ckpt), [inpainting.ckpt](https://github.com/zyddnys/manga-image-translator/releases/download/beta-0.2.1/inpainting.ckpt)
16 | 3. Download and unzip the OCR CTC model into the same folder: [ocr-ctc.zip](https://github.com/zyddnys/manga-image-translator/releases/download/beta-0.3/ocr-ctc.zip). This OCR model supports Korean while the OCR model in the previous step only supports English, Chinese and Japanese. Its speed is also higher.
17 | 4. Download the [OCR 48px model](https://github.com/zyddnys/manga-image-translator/releases/download/beta-0.3/ocr_ar_48px.ckpt) and its [dictionary](https://github.com/zyddnys/manga-image-translator/releases/download/beta-0.3/alphabet-all-v7.txt) into the same folder. This OCR model has a higher accuracy but requires GPU.
18 | 5. Start the server by running `run.bat`.
19 | 6. Put the `mangaTranslatorOCR` plugin files into the `plugins` folder. Get the plugins files: [mangaTranslatorOCRPlugin.zip](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/mangaTranslatorOCRPlugin.zip).
20 |
21 | If you are using macOS or Linux, please configure the environment by yourself.
22 |
23 | If you need to enable GPU, please follow [this guide](GPU.md).
24 |
25 | Usage:
26 |
27 | 1. It can work as an OCR engine.
28 |
29 | Select `db_detector` to detect text lines only and select `db+OCR` to detect text lines and recognize the text as well. If you need to detect the text color, select the one with `colordetection`. If you need to detect the rotation, select the one with `rotationdetection`.
30 |
31 | 
32 |
33 | 2. It can work as a scene text detector.
34 | 3. It can be used to generate the text mask and the text-removed image through the external mask generation and inpainting plugins.
35 | 4. If you enable text mask generation through OCR and scene text detection in the project settings, it will automatically save the text mask if there has not been a text mask image.
36 |
37 |
--------------------------------------------------------------------------------
/mangaTranslatorOCR/engines.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xulihang/ImageTrans_plugins/87a0b5937263fa14f5fcd1abe53446c2b87ef1b0/mangaTranslatorOCR/engines.jpg
--------------------------------------------------------------------------------
/mangaTranslatorOCR/mangaTranslatorOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=javaobject
5 | Library10=jbitmapcreator
6 | Library2=jcore
7 | Library3=jfx
8 | Library4=jokhttputils2
9 | Library5=json
10 | Library6=jstringutils
11 | Library7=jxmlsax
12 | Library8=jxui
13 | Library9=xmlbuilder
14 | Module1=mangaTranslatorOCRPlugin
15 | NumberOfFiles=0
16 | NumberOfLibraries=10
17 | NumberOfModules=1
18 | Version=8.9
19 | @EndOfDesignText@
20 | #Region Project Attributes
21 | #MainFormWidth: 600
22 | #MainFormHeight: 600
23 | #End Region
24 |
25 | Sub Process_Globals
26 | Private fx As JFX
27 | Public MainForm As Form
28 |
29 | End Sub
30 |
31 | Sub AppStart (Form1 As Form, Args() As String)
32 | MainForm = Form1
33 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
34 | MainForm.Show
35 | Dim n As mangaTranslatorOCRPlugin
36 | n.Initialize
37 | Dim img As B4XBitmap=fx.LoadImage(File.DirApp,"2.jpg")
38 | wait for (n.GetText(img,"en")) complete (result As Object)
39 | Log(result)
40 | End Sub
41 |
42 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
43 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
44 | Return True
45 | End Sub
46 |
--------------------------------------------------------------------------------
/mangaTranslatorOCR/mangaTranslatorOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=mangaTranslatorOCRPlugin,addBoxes,207,6,mangaTranslatorOCRPlugin,GetTextWithLocation,114,6,mangaTranslatorOCRPlugin,GetNiceName,29,0,mangaTranslatorOCRPlugin,Class_Globals,8,4,mangaTranslatorOCRPlugin,Initialize,21,2,mangaTranslatorOCRPlugin,ocr,167,6,mangaTranslatorOCRPlugin,getUrl,237,0,mangaTranslatorOCRPlugin,Run,48,6,mangaTranslatorOCRPlugin,BuildCombinations,118,3,mangaTranslatorOCRPlugin,GetText,127,6
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/niutransMT/niuTransMTPlugin.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=Class
5 | Version=4.2
6 | @EndOfDesignText@
7 | Sub Class_Globals
8 | Private fx As JFX
9 | End Sub
10 |
11 | 'Initializes the object. You can NOT add parameters to this method!
12 | Public Sub Initialize() As String
13 | Log("Initializing plugin " & GetNiceName)
14 | ' Here return a key to prevent running unauthorized plugins
15 | Return "MyKey"
16 | End Sub
17 |
18 | ' must be available
19 | public Sub GetNiceName() As String
20 | Return "niutransMT"
21 | End Sub
22 |
23 | ' must be available
24 | public Sub Run(Tag As String, Params As Map) As ResumableSub
25 | 'Log("run"&Params)
26 | Select Tag
27 | Case "getParams"
28 | Dim paramsList As List
29 | paramsList.Initialize
30 | paramsList.Add("key")
31 | Return paramsList
32 | Case "translate"
33 | wait for (translate(Params.Get("source"),Params.Get("sourceLang"),Params.Get("targetLang"),Params.Get("preferencesMap"))) complete (result As String)
34 | Return result
35 | End Select
36 | Return ""
37 | End Sub
38 |
39 |
40 | Sub translate(source As String, sourceLang As String, targetLang As String,preferencesMap As Map) As ResumableSub
41 | Dim target As String
42 | Dim su As StringUtils
43 | Dim job As HttpJob
44 | job.Initialize("job",Me)
45 | Dim params As String
46 | params="?apikey="&getMap("niutrans",getMap("mt",preferencesMap)).Get("key")&"&src_text="&su.EncodeUrl(source,"UTF-8")&"&from="&sourceLang&"&to="&targetLang
47 | Dim URL As String
48 | URL="https://api.niutrans.com/NiuTransServer/translation"
49 | job.Download(URL¶ms)
50 | wait For (job) JobDone(job As HttpJob)
51 | If job.Success Then
52 | Log(job.GetString)
53 | Try
54 | Dim json As JSONParser
55 | json.Initialize(job.GetString)
56 | target=json.NextObject.Get("tgt_text")
57 | Catch
58 | Log(LastException)
59 | End Try
60 | Else
61 | target=""
62 | End If
63 | job.Release
64 | Return target
65 | End Sub
66 |
67 |
68 | Sub getMap(key As String,parentmap As Map) As Map
69 | Return parentmap.Get(key)
70 | End Sub
71 |
--------------------------------------------------------------------------------
/niutransMT/niutransMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library2=jfx
6 | Library3=json
7 | Library4=jxmlsax
8 | Library5=xmlbuilder
9 | Library6=jxui
10 | Library7=javaobject
11 | Library8=jokhttputils2
12 | Library9=jstringutils
13 | Module1=niutransMTPlugin
14 | NumberOfFiles=0
15 | NumberOfLibraries=9
16 | NumberOfModules=1
17 | Version=7.8
18 | @EndOfDesignText@
19 | #Region Project Attributes
20 | #MainFormWidth: 600
21 | #MainFormHeight: 600
22 | #End Region
23 |
24 | Sub Process_Globals
25 | Private fx As JFX
26 | Public MainForm As Form
27 |
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | 'Dim n As niuTransMTPlugin
35 | 'n.Initialize
36 | 'wait for (n.translate("Hello","en","zh")) complete (result As String)
37 | 'Log(result)
38 | End Sub
39 |
40 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
41 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
42 | Return True
43 | End Sub
44 |
--------------------------------------------------------------------------------
/niutransMT/niutransMT.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=niutransMTPlugin,Initialize,6,0,niutransMTPlugin,translate,41,6,Main,AppStart,11,0,niutransMTPlugin,Class_Globals,0,0,niutransMTPlugin,Run,18,6,niutransMTPlugin,GetNiceName,15,0
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/ollamaGPTMT/ollamaMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans,HU2_ACCEPTALL
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=byteconverter
6 | Library11=encryption
7 | Library2=jfx
8 | Library3=json
9 | Library4=jxmlsax
10 | Library5=xmlbuilder
11 | Library6=jxui
12 | Library7=javaobject
13 | Library8=jokhttputils2
14 | Library9=jstringutils
15 | Module1=ollamaMTPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=11
18 | NumberOfModules=1
19 | Version=8.9
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 |
30 | End Sub
31 |
32 | Sub AppStart (Form1 As Form, Args() As String)
33 | MainForm = Form1
34 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
35 | MainForm.Show
36 | Dim n As ollamaMTPlugin
37 | n.Initialize
38 | Dim map1 As Map
39 | map1.Initialize
40 | 'map1.Put("key","your key")
41 |
42 | 'map1.Put("host","https://37cb-35-243-195-191.ngrok-free.app")
43 | 'map1.Put("model","gpt-4")
44 | 'map1.Put("prompt",$"翻译下述内容至中文: {source}"$)
45 | 'wait for (n.translate("Do you want to have more cake, Jenny?","en","zh",CreateMap("mt":CreateMap("chatGPT":map1)),CreateMap("Jenny":"珍妮"))) complete (result As String)
46 | 'wait for (n.batchTranslate(Array("Do you want to have more cake, Jenny?"),"en","zh",CreateMap("mt":CreateMap("chatGPT":map1)),CreateMap("Jenny":"珍妮"))) complete (result As Object)
47 | 'wait for (n.translate("BasicCAT Documentation."&CRLF&"Sentence2.","en","zh",CreateMap("mt":CreateMap("chatGPT":map1)))) complete (result As String)
48 | Dim terms As Map
49 | terms.Initialize
50 | Dim textToTranslate As List = Array("お前には夏休みの間","我が天文部手伝いをしてもらう","いつか必ず","地に落ちるのだから","失敗です!!","有人ロケット「あさがお」が爆発!","日本初の有人宇宙飛行は失敗しました!!")
51 | 'wait for (n.batchTranslate(Array("BasicCAT Documentation."&CRLF&"Sentence2.","Paragraph2"),"en","zh",CreateMap("mt":CreateMap("chatGPT":map1)))) complete (result As Object)
52 | wait for (n.batchTranslate(textToTranslate,"ja","zh",CreateMap("mt":CreateMap("ollama":map1)),terms)) complete (result As Object)
53 | Log(result)
54 | End Sub
55 |
56 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
57 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
58 | Return True
59 | End Sub
60 |
--------------------------------------------------------------------------------
/opusMT/opusMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=xml2map
6 | Library2=jfx
7 | Library3=json
8 | Library4=jxmlsax
9 | Library5=xmlbuilder
10 | Library6=jxui
11 | Library7=javaobject
12 | Library8=jokhttputils2
13 | Library9=jstringutils
14 | Module1=opusMTPlugin
15 | NumberOfFiles=0
16 | NumberOfLibraries=10
17 | NumberOfModules=1
18 | Version=8.9
19 | @EndOfDesignText@
20 | #Region Project Attributes
21 | #MainFormWidth: 600
22 | #MainFormHeight: 600
23 | #End Region
24 |
25 | Sub Process_Globals
26 | Private fx As JFX
27 | Public MainForm As Form
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim map1 As Map
35 | map1.Initialize
36 | Dim map2 As Map
37 | map2.Initialize
38 | map1.Put("mt",CreateMap("opus":map2))
39 | Dim n As opusMTPlugin
40 | n.Initialize
41 | wait for (n.translate("Hello","en","zh",map1)) complete (result As String)
42 | Log(result)
43 | End Sub
44 |
45 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
46 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
47 | Return True
48 | End Sub
49 |
--------------------------------------------------------------------------------
/opusMT/opusMT.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=opusMTPlugin,Initialize,11,0,opusMTPlugin,GetNiceName,13,0,Main,Process_Globals,5,0,opusMTPlugin,Class_Globals,0,0,Main,AppStart,18,0,opusMTPlugin,convertLang,37,6,opusMTPlugin,Run,24,1,opusMTPlugin,translate,61,6
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/opusMT/opusMTPlugin.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=Class
5 | Version=4.2
6 | @EndOfDesignText@
7 | Sub Class_Globals
8 | Private fx As JFX
9 | End Sub
10 |
11 | 'Initializes the object. You can NOT add parameters to this method!
12 | Public Sub Initialize() As String
13 | Log("Initializing plugin " & GetNiceName)
14 | ' Here return a key to prevent running unauthorized plugins
15 | Return "MyKey"
16 | End Sub
17 |
18 | ' must be available
19 | public Sub GetNiceName() As String
20 | Return "opusMT"
21 | End Sub
22 |
23 | ' must be available
24 | public Sub Run(Tag As String, Params As Map) As ResumableSub
25 | Log("run"&Params)
26 | Select Tag
27 | Case "getParams"
28 | Dim paramsList As List
29 | paramsList.Initialize
30 | paramsList.Add("url")
31 | paramsList.Add("model")
32 | Return paramsList
33 | Case "translate"
34 | wait for (translate(Params.Get("source"),Params.Get("sourceLang"),Params.Get("targetLang"),Params.Get("preferencesMap"))) complete (result As String)
35 | Return result
36 | Case "getDefaultParamValues"
37 | Return CreateMap("url":"http://localhost:8500/MTRestService/Translate")
38 | End Select
39 | Return ""
40 | End Sub
41 |
42 | Private Sub convertLang(lang As String) As String
43 | If lang.StartsWith("zh") Then
44 | Return "cmn"
45 | End If
46 | Return lang
47 | End Sub
48 |
49 |
50 | Sub translate(source As String, sourceLang As String, targetLang As String,preferencesMap As Map) As ResumableSub
51 | sourceLang = convertLang(sourceLang)
52 | targetLang = convertLang(targetLang)
53 | Dim target As String
54 | Dim su As StringUtils
55 | Dim job As HttpJob
56 | job.Initialize("job",Me)
57 | Dim model As String
58 | Dim url As String = "http://localhost:8500/MTRestService/Translate"
59 | Try
60 | url=getMap("opus",getMap("mt",preferencesMap)).GetDefault("url","http://localhost:8500/MTRestService/Translate")
61 | model=getMap("opus",getMap("mt",preferencesMap)).GetDefault("model","")
62 | Catch
63 | Log(LastException)
64 | End Try
65 | Dim params As String
66 | params="?input="&su.EncodeUrl(source,"UTF8")&"&srcLangCode="&sourceLang&"&trgLangCode="&targetLang&"&modelTag="&model
67 | job.Download(url¶ms)
68 | wait For (job) JobDone(job As HttpJob)
69 | If job.Success Then
70 | target = job.GetString
71 | Log(target)
72 | Else
73 | target=""
74 | End If
75 | job.Release
76 | Return target
77 | End Sub
78 |
79 |
80 | Sub getMap(key As String,parentmap As Map) As Map
81 | Return parentmap.Get(key)
82 | End Sub
83 |
--------------------------------------------------------------------------------
/opusMT/readme.md:
--------------------------------------------------------------------------------
1 | [OPUS-CAT](https://helsinki-nlp.github.io/OPUS-CAT/) is an offline machine translation engine.
2 |
3 |
4 | ## How to Use
5 |
6 |
7 | 1. [Download the plugin](https://github.com/xulihang/ImageTrans-docs/files/8281319/opusMTplugin.zip) and unzip the files into ImageTrans's plugins folder.
8 | 2. Download and run [OPUS-CAT](https://helsinki-nlp.github.io/OPUS-CAT/).
9 | 3. In ImageTrans, enable OPUS-CAT in Preferences so that it is called in Transation Assist. You can also select OPUS-CAT to run batch translation.
--------------------------------------------------------------------------------
/paddleOCR/README.md:
--------------------------------------------------------------------------------
1 | ## PaddleOCR
2 |
3 | The plugin is bundled with ImageTrans. You just need to start the PaddleOCR server.
4 |
5 | 1. Install Python.
6 | 2. Install PaddleOCR: `pip install paddleocr==2.6`
7 | 3. Install bottle and Paste: `pip install bottle Paste`
8 | 4. Run the following to start the server: `python server_paddleocr.py`
9 |
10 | For convenience, you can directly use the Windows package: [link](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/PaddleOCR.zip).
11 |
12 | Unzip the file and start `run.bat` to run the server. You need to keep the server running in the background.
13 |
--------------------------------------------------------------------------------
/paddleOCR/plugin/paddleOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library2=jfx
6 | Library3=json
7 | Library4=jxmlsax
8 | Library5=xmlbuilder
9 | Library6=jxui
10 | Library7=javaobject
11 | Library8=jokhttputils2
12 | Library9=jstringutils
13 | Module1=paddleOCRPlugin
14 | NumberOfFiles=0
15 | NumberOfLibraries=9
16 | NumberOfModules=1
17 | Version=8.8
18 | @EndOfDesignText@
19 | #Region Project Attributes
20 | #MainFormWidth: 600
21 | #MainFormHeight: 600
22 | #End Region
23 |
24 | Sub Process_Globals
25 | Private fx As JFX
26 | Public MainForm As Form
27 |
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim n As paddleOCRPlugin
35 | n.Initialize
36 | wait for (n.Run("SetCombination",CreateMap("combination":"detect only"))) complete (done As Object)
37 | wait for (n.GetTextWithLocation(fx.LoadImage(File.DirApp,"image.jpg"),"ch")) complete (result As List)
38 | Log(result)
39 | 'wait for (n.translate("Hello","en","zh")) complete (result As String)
40 | 'Log(result)
41 | End Sub
42 |
43 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
44 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
45 | Return True
46 | End Sub
47 |
--------------------------------------------------------------------------------
/paddleOCR/plugin/paddleOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=paddleOCRPlugin,getUrl,155,4,paddleOCRPlugin,textLinesToBoxes,143,0,paddleOCRPlugin,BuildCombinations,43,3,paddleOCRPlugin,GenerateUniqueName,141,0,Main,Process_Globals,10,0,paddleOCRPlugin,convertLang,53,6,paddleOCRPlugin,Run,35,6,Main,AppStart,18,6,paddleOCRPlugin,GetTextWithLocation,78,0,paddleOCRPlugin,ocr,120,6
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/paddleOCR/server/README.md:
--------------------------------------------------------------------------------
1 | See .
--------------------------------------------------------------------------------
/paddleOCR/server/server_paddleocr.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import os
4 | import time
5 | import datetime
6 | from bottle import route, run, template, request, static_file
7 | import json
8 | from paddleocr import PaddleOCR
9 |
10 | @route('/ocr', method='POST')
11 | def ocr():
12 | upload = request.files.get('upload')
13 | lang = request.forms.get('lang')
14 | print(lang)
15 | global current_lang
16 | global ocr
17 | if current_lang!=lang:
18 | current_lang=lang
19 | ocr = PaddleOCR(lang=current_lang)
20 |
21 | name, ext = os.path.splitext(upload.filename)
22 | print(ext.lower())
23 | if ext.lower() not in ('.png','.jpg','.jpeg'):
24 | return "File extension not allowed."
25 | timestamp=str(int(time.time()*1000))
26 | savedName=timestamp+ext
27 | save_path = "./uploaded/"
28 | if not os.path.exists(save_path):
29 | os.makedirs(save_path)
30 | file_path = "{path}/{file}".format(path=save_path, file=savedName)
31 | if os.path.exists(file_path)==True:
32 | os.remove(file_path)
33 | upload.save(file_path)
34 | ret = {}
35 | result = ocr.ocr(file_path)[0]
36 | print(result)
37 | text_lines=[]
38 | for line in result:
39 | text_line={}
40 | index=0
41 | for coord in line[0]:
42 | text_line["x"+str(index)]=int(coord[0])
43 | text_line["y"+str(index)]=int(coord[1])
44 | index=index+1
45 | text_line["text"]=line[1][0]
46 | text_lines.append(text_line)
47 | os.remove(file_path)
48 | ret["text_lines"]=text_lines
49 | return ret
50 |
51 | @route('/detect', method='POST')
52 | def detect():
53 | upload = request.files.get('upload')
54 | lang = request.forms.get('lang')
55 | path = request.forms.get('path')
56 |
57 | global current_lang
58 | global ocr
59 | if current_lang!=lang:
60 | current_lang=lang
61 | ocr = PaddleOCR(lang=current_lang)
62 | file_path = ""
63 | if path != None:
64 | if os.path.exists(path):
65 | print(path)
66 | file_path = path
67 | if file_path == "":
68 | name, ext = os.path.splitext(upload.filename)
69 | print(ext.lower())
70 | if ext.lower() not in ('.png','.jpg','.jpeg'):
71 | return "File extension not allowed."
72 | timestamp=str(int(time.time()*1000))
73 | savedName=timestamp+ext
74 | save_path = "./uploaded/"
75 | if not os.path.exists(save_path):
76 | os.makedirs(save_path)
77 | file_path = "{path}/{file}".format(path=save_path, file=savedName)
78 | if os.path.exists(file_path)==True:
79 | os.remove(file_path)
80 | upload.save(file_path)
81 | ret = {}
82 | result = ocr.ocr(file_path,rec=False,cls=True)[0]
83 | print(result)
84 | text_lines=[]
85 | for line in result:
86 | text_line={}
87 | index=0
88 | for coord in line:
89 | text_line["x"+str(index)]=int(coord[0])
90 | text_line["y"+str(index)]=int(coord[1])
91 | index=index+1
92 | text_line["text"]=""
93 | text_lines.append(text_line)
94 | os.remove(file_path)
95 | ret["text_lines"]=text_lines
96 | return ret
97 |
98 |
99 | @route('/')
100 | def server_static(filepath):
101 | return static_file(filepath, root='www')
102 |
103 | current_lang="ch"
104 | ocr = PaddleOCR(lang=current_lang,det_db_thresh=0.9,det_db_box_thresh=0.6)
105 | run(server="paste",host='127.0.0.1', port=8080)
106 |
107 |
--------------------------------------------------------------------------------
/paddleOCR/server/server_paddleocr3.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import os
4 | import time
5 | import datetime
6 | from bottle import route, run, template, request, static_file
7 | import json
8 | from paddleocr import PaddleOCR, TextDetection
9 |
10 | @route('/ocr', method='POST')
11 | def ocr():
12 | upload = request.files.get('upload')
13 | lang = request.forms.get('lang')
14 | print(lang)
15 | name, ext = os.path.splitext(upload.filename)
16 | print(ext.lower())
17 | if ext.lower() not in ('.png','.jpg','.jpeg'):
18 | return "File extension not allowed."
19 | timestamp=str(int(time.time()*1000))
20 | savedName=timestamp+ext
21 | save_path = "./uploaded/"
22 | if not os.path.exists(save_path):
23 | os.makedirs(save_path)
24 | file_path = "{path}/{file}".format(path=save_path, file=savedName)
25 | if os.path.exists(file_path)==True:
26 | os.remove(file_path)
27 | upload.save(file_path)
28 | ret = {}
29 | ocr = PaddleOCR(
30 | use_doc_orientation_classify=False,
31 | use_doc_unwarping=False,
32 | use_textline_orientation=False)
33 | result = ocr.predict(file_path)[0]
34 | print(result)
35 | text_lines=[]
36 | index = 0
37 | for text in result["rec_texts"]:
38 | text_line={}
39 | coord_index = 0
40 | for coord in result["rec_polys"][index]:
41 | text_line["x"+str(coord_index)]=int(coord[0])
42 | text_line["y"+str(coord_index)]=int(coord[1])
43 | coord_index=coord_index+1
44 | text_line["text"]=text
45 | text_lines.append(text_line)
46 | index=index+1
47 | os.remove(file_path)
48 | ret["text_lines"]=text_lines
49 | return ret
50 |
51 | @route('/detect', method='POST')
52 | def detect():
53 | upload = request.files.get('upload')
54 | path = request.forms.get('path')
55 | file_path = ""
56 | if path != None:
57 | if os.path.exists(path):
58 | print(path)
59 | file_path = path
60 | if file_path == "":
61 | name, ext = os.path.splitext(upload.filename)
62 | print(ext.lower())
63 | if ext.lower() not in ('.png','.jpg','.jpeg'):
64 | return "File extension not allowed."
65 | timestamp=str(int(time.time()*1000))
66 | savedName=timestamp+ext
67 | save_path = "./uploaded/"
68 | if not os.path.exists(save_path):
69 | os.makedirs(save_path)
70 | file_path = "{path}/{file}".format(path=save_path, file=savedName)
71 | if os.path.exists(file_path)==True:
72 | os.remove(file_path)
73 | upload.save(file_path)
74 | ret = {}
75 | model = TextDetection()
76 | result = model.predict(file_path)[0]
77 | text_lines=[]
78 | polys = result["dt_polys"]
79 | for poly in polys:
80 | text_line={}
81 | coord_index = 0
82 | for coord in poly:
83 | text_line["x"+str(coord_index)]=int(coord[0])
84 | text_line["y"+str(coord_index)]=int(coord[1])
85 | coord_index=coord_index+1
86 | text_line["text"]=""
87 | text_lines.append(text_line)
88 | os.remove(file_path)
89 | ret["text_lines"]=text_lines
90 | return ret
91 |
92 |
93 | @route('/')
94 | def server_static(filepath):
95 | return static_file(filepath, root='www')
96 |
97 |
98 | run(server="paste",host='127.0.0.1', port=8080)
99 |
100 |
--------------------------------------------------------------------------------
/paddleOCR/server/www/detect.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Upload
6 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/paddleOCR/server/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Upload
6 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/pandaOCR/pandaOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=encryption
6 | Library11=byteconverter
7 | Library12=jsql
8 | Library2=jfx
9 | Library3=json
10 | Library4=jxmlsax
11 | Library5=xmlbuilder
12 | Library6=jxui
13 | Library7=javaobject
14 | Library8=jokhttputils2
15 | Library9=jstringutils
16 | Module1=pandaOCRPlugin
17 | NumberOfFiles=0
18 | NumberOfLibraries=12
19 | NumberOfModules=1
20 | Version=8.9
21 | @EndOfDesignText@
22 | #Region Project Attributes
23 | #MainFormWidth: 600
24 | #MainFormHeight: 600
25 | #End Region
26 |
27 | Sub Process_Globals
28 | Private fx As JFX
29 | Public MainForm As Form
30 |
31 | End Sub
32 |
33 | Sub AppStart (Form1 As Form, Args() As String)
34 | MainForm = Form1
35 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
36 | MainForm.Show
37 | Dim t As pandaOCRPlugin
38 | t.Initialize
39 | wait for (t.GetText(fx.LoadImage(File.DirApp,"ttt.png"),"auto")) Complete (done As Object)
40 | Log(done)
41 | End Sub
42 |
43 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
44 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
45 | Return True
46 | End Sub
47 |
--------------------------------------------------------------------------------
/pandaOCR/pandaOCRPlugin.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=Class
5 | Version=4.2
6 | @EndOfDesignText@
7 | Sub Class_Globals
8 | Private fx As JFX
9 | End Sub
10 |
11 | 'Initializes the object. You can NOT add parameters to this method!
12 | Public Sub Initialize() As String
13 | Log("Initializing plugin " & GetNiceName)
14 | ' Here return a key to prevent running unauthorized plugins
15 | Return "MyKey"
16 | End Sub
17 |
18 | ' must be available
19 | public Sub GetNiceName() As String
20 | Return "pandaOCR"
21 | End Sub
22 |
23 | ' must be available
24 | public Sub Run(Tag As String, Params As Map) As ResumableSub
25 | Log("run"&Params)
26 | Select Tag
27 | Case "getParams"
28 | Dim paramsList As List
29 | paramsList.Initialize
30 | paramsList.Add("port")
31 | Return paramsList
32 | Case "getText"
33 | wait for (GetText(Params.Get("img"),Params.Get("lang"))) complete (result As String)
34 | Return result
35 | Case "getTextWithLocation"
36 | Return Array()
37 | End Select
38 | Return ""
39 | End Sub
40 |
41 | private Sub ConvertLang(lang As String) As String
42 | If lang.StartsWith("jpn") Then
43 | Return "jp"
44 | else if lang.StartsWith("chi_sim") Then
45 | Return "zh"
46 | else if lang.StartsWith("chi_tra") Then
47 | Return "zht"
48 | else if lang.StartsWith("en") Then
49 | Return "en"
50 | Else
51 | Return "auto"
52 | End If
53 | End Sub
54 |
55 |
56 | Sub GetText(img As B4XBitmap,lang As String) As ResumableSub
57 | Dim text As String
58 | Dim port As String = "5678"
59 | Try
60 | If File.Exists(File.DirApp,"preferences.conf") Then
61 | Dim preferencesMap As Map = readJsonAsMap(File.ReadString(File.DirApp,"preferences.conf"))
62 | port=getMap("panda",getMap("api",preferencesMap)).GetDefault("port",port)
63 | End If
64 | Catch
65 | Log(LastException)
66 | End Try
67 |
68 |
69 | saveImgToDisk(img)
70 |
71 | Dim job As HttpJob
72 | job.Initialize("",Me)
73 | Dim su As StringUtils
74 | Dim base64 As String=su.EncodeBase64(File.ReadBytes(File.DirApp,"image.jpg"))
75 | lang = ConvertLang(lang)
76 | Dim params As Map
77 | params.Initialize
78 | params.Put("lang",lang)
79 | params.Put("type","1")
80 | params.Put("pic",base64)
81 | Dim jsonG As JSONGenerator
82 | jsonG.Initialize(params)
83 | job.PostString("http://127.0.0.1:"&port,jsonG.ToString)
84 | wait for (job) JobDone(job As HttpJob)
85 | If job.Success Then
86 | Try
87 | Log(job.GetString)
88 | Dim json As JSONParser
89 | json.Initialize(job.GetString)
90 | Dim Response As Map=json.NextObject
91 | text = Response.Get("text")
92 | Catch
93 | Log(LastException)
94 | End Try
95 | End If
96 | job.Release
97 | Return text
98 | End Sub
99 |
100 |
101 |
102 |
103 | Sub getMap(key As String,parentmap As Map) As Map
104 | Return parentmap.Get(key)
105 | End Sub
106 |
107 | Sub readJsonAsMap(s As String) As Map
108 | Dim json As JSONParser
109 | json.Initialize(s)
110 | Return json.NextObject
111 | End Sub
112 |
113 | Sub saveImgToDisk(img As B4XBitmap)
114 | Dim imgPath As String=File.Combine(File.DirApp,"image.jpg")
115 | Dim out As OutputStream=File.OpenOutput(imgPath,"",False)
116 | img.WriteToStream(out,100,"JPEG")
117 | out.Close
118 | End Sub
119 |
120 |
--------------------------------------------------------------------------------
/pandaOCR/readme.md:
--------------------------------------------------------------------------------
1 | https://github.com/xulihang/ImageTrans-docs/issues/607
--------------------------------------------------------------------------------
/pororoOCR/plugin/pororoOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=javaobject
5 | Library10=jsql
6 | Library2=jcore
7 | Library3=jfx
8 | Library4=jokhttputils2
9 | Library5=json
10 | Library6=jstringutils
11 | Library7=jxmlsax
12 | Library8=jxui
13 | Library9=xmlbuilder
14 | Module1=Localizator
15 | Module2=pororoOCRPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=10
18 | NumberOfModules=2
19 | Version=8.9
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 |
30 | End Sub
31 |
32 | Sub AppStart (Form1 As Form, Args() As String)
33 | MainForm = Form1
34 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
35 | MainForm.Show
36 | 'Dim n As niuTransMTPlugin
37 | 'n.Initialize
38 | 'wait for (n.translate("Hello","en","zh")) complete (result As String)
39 | 'Log(result)
40 | End Sub
41 |
42 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
43 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
44 | Return True
45 | End Sub
46 |
--------------------------------------------------------------------------------
/pororoOCR/readme.md:
--------------------------------------------------------------------------------
1 | ## Pororo Korean OCR
2 |
3 | See: https://github.com/yunwoong7/korean_ocr_using_pororo
4 |
5 | ### How to Install
6 |
7 | For Windows users:
8 |
9 | 1. Download [pororo.zip](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/pororo.zip) and unzip it into a folder.
10 | 2. Download [pororo-models.zip](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/pororo-models.zip) and unzip it to `C:\`.
11 | 3. Download the [plugin](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/pororoPlugin.zip) and unzip the files into ImageTrans's plugins folder.
12 | 4. Execute `run.bat` and keep the window open so that we can use it in ImageTrans.
13 |
14 | For macOS and Linux users, please follow the following steps to start pororo:
15 |
16 | 1. Clone the project and change the directory to `server`.
17 | 2. Install dependencies: `pip3 install -r requirements.txt`
18 | 3. Download [pororo-models.zip](https://github.com/xulihang/ImageTrans_plugins/releases/download/plugins/pororo-models.zip) and unzip it to `~/.pororo` (or let the script download it).
19 | 4. Start the server: `python3 server_pororo_ocr.py`
20 |
--------------------------------------------------------------------------------
/pororoOCR/server/main.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | from pororo import Pororo
3 | from pororo.pororo import SUPPORTED_TASKS
4 | from utils.image_util import plt_imshow, put_text
5 | import warnings
6 |
7 | warnings.filterwarnings('ignore')
8 |
9 |
10 | class PororoOcr:
11 | def __init__(self, model: str = "brainocr", lang: str = "ko", **kwargs):
12 | self.model = model
13 | self.lang = lang
14 | self._ocr = Pororo(task="ocr", lang=lang, model=model, **kwargs)
15 | self.img_path = None
16 | self.ocr_result = {}
17 |
18 | def run_ocr(self, img_path: str, debug: bool = False):
19 | self.img_path = img_path
20 | self.ocr_result = self._ocr(img_path, detail=True)
21 |
22 | if self.ocr_result['description']:
23 | ocr_text = self.ocr_result["description"]
24 | else:
25 | ocr_text = "No text detected."
26 |
27 | if debug:
28 | self.show_img_with_ocr()
29 |
30 | return ocr_text
31 |
32 | @staticmethod
33 | def get_available_langs():
34 | return SUPPORTED_TASKS["ocr"].get_available_langs()
35 |
36 | @staticmethod
37 | def get_available_models():
38 | return SUPPORTED_TASKS["ocr"].get_available_models()
39 |
40 | def get_ocr_result(self):
41 | return self.ocr_result
42 |
43 | def get_img_path(self):
44 | return self.img_path
45 |
46 | def show_img(self):
47 | plt_imshow(img=self.img_path)
48 |
49 | def show_img_with_ocr(self):
50 | img = cv2.imread(self.img_path)
51 | roi_img = img.copy()
52 |
53 | for text_result in self.ocr_result['bounding_poly']:
54 | text = text_result['description']
55 | tlX = text_result['vertices'][0]['x']
56 | tlY = text_result['vertices'][0]['y']
57 | trX = text_result['vertices'][1]['x']
58 | trY = text_result['vertices'][1]['y']
59 | brX = text_result['vertices'][2]['x']
60 | brY = text_result['vertices'][2]['y']
61 | blX = text_result['vertices'][3]['x']
62 | blY = text_result['vertices'][3]['y']
63 |
64 | pts = ((tlX, tlY), (trX, trY), (brX, brY), (blX, blY))
65 |
66 | topLeft = pts[0]
67 | topRight = pts[1]
68 | bottomRight = pts[2]
69 | bottomLeft = pts[3]
70 |
71 | cv2.line(roi_img, topLeft, topRight, (0, 255, 0), 2)
72 | cv2.line(roi_img, topRight, bottomRight, (0, 255, 0), 2)
73 | cv2.line(roi_img, bottomRight, bottomLeft, (0, 255, 0), 2)
74 | cv2.line(roi_img, bottomLeft, topLeft, (0, 255, 0), 2)
75 | roi_img = put_text(roi_img, text, topLeft[0], topLeft[1] - 20, font_size=15)
76 |
77 | # print(text)
78 |
79 | plt_imshow(["Original", "ROI"], [img, roi_img], figsize=(16, 10))
80 |
81 |
82 | if __name__ == "__main__":
83 | ocr = PororoOcr()
84 | image_path = input("Enter image path: ")
85 | text = ocr.run_ocr(image_path, debug=True)
86 | print('Result :', text)
87 |
--------------------------------------------------------------------------------
/pororoOCR/server/pororo/__init__.py:
--------------------------------------------------------------------------------
1 | from pororo.__version__ import version as __version__ # noqa
2 | from pororo.pororo import Pororo # noqa
3 |
--------------------------------------------------------------------------------
/pororoOCR/server/pororo/__version__.py:
--------------------------------------------------------------------------------
1 | version = "0.4.1"
2 |
--------------------------------------------------------------------------------
/pororoOCR/server/pororo/models/brainOCR/__init__.py:
--------------------------------------------------------------------------------
1 | from .brainocr import Reader # noqa
2 |
--------------------------------------------------------------------------------
/pororoOCR/server/pororo/models/brainOCR/_dataset.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | from natsort import natsorted
4 | from PIL import Image
5 | from torch.utils.data import Dataset
6 |
7 |
8 | class RawDataset(Dataset):
9 |
10 | def __init__(self, root, imgW, imgH):
11 | self.imgW = imgW
12 | self.imgH = imgH
13 | self.image_path_list = []
14 | for dirpath, _, filenames in os.walk(root):
15 | for name in filenames:
16 | _, ext = os.path.splitext(name)
17 | ext = ext.lower()
18 | if ext in (".jpg", ".jpeg", ".png"):
19 | self.image_path_list.append(os.path.join(dirpath, name))
20 |
21 | self.image_path_list = natsorted(self.image_path_list)
22 | self.nSamples = len(self.image_path_list)
23 |
24 | def __len__(self):
25 | return self.nSamples
26 |
27 | def __getitem__(self, index):
28 | try:
29 | img = Image.open(self.image_path_list[index]).convert("L")
30 |
31 | except IOError:
32 | print(f"Corrupted image for {index}")
33 | img = Image.new("L", (self.imgW, self.imgH))
34 |
35 | return img, self.image_path_list[index]
36 |
--------------------------------------------------------------------------------
/pororoOCR/server/pororo/models/brainOCR/craft.py:
--------------------------------------------------------------------------------
1 | """
2 | This code is adapted from https://github.com/clovaai/CRAFT-pytorch/blob/master/craft.py.
3 | Copyright (c) 2019-present NAVER Corp.
4 | MIT License
5 | """
6 |
7 | import torch
8 | import torch.nn as nn
9 | import torch.nn.functional as F
10 | from torch import Tensor
11 |
12 | from ._modules import Vgg16BN, init_weights
13 |
14 |
15 | class DoubleConv(nn.Module):
16 |
17 | def __init__(self, in_ch: int, mid_ch: int, out_ch: int) -> None:
18 | super(DoubleConv, self).__init__()
19 | self.conv = nn.Sequential(
20 | nn.Conv2d(in_ch + mid_ch, mid_ch, kernel_size=1),
21 | nn.BatchNorm2d(mid_ch),
22 | nn.ReLU(inplace=True),
23 | nn.Conv2d(mid_ch, out_ch, kernel_size=3, padding=1),
24 | nn.BatchNorm2d(out_ch),
25 | nn.ReLU(inplace=True),
26 | )
27 |
28 | def forward(self, x: Tensor):
29 | x = self.conv(x)
30 | return x
31 |
32 |
33 | class CRAFT(nn.Module):
34 |
35 | def __init__(self, pretrained: bool = False, freeze: bool = False) -> None:
36 | super(CRAFT, self).__init__()
37 |
38 | # Base network
39 | self.basenet = Vgg16BN(pretrained, freeze)
40 |
41 | # U network
42 | self.upconv1 = DoubleConv(1024, 512, 256)
43 | self.upconv2 = DoubleConv(512, 256, 128)
44 | self.upconv3 = DoubleConv(256, 128, 64)
45 | self.upconv4 = DoubleConv(128, 64, 32)
46 |
47 | num_class = 2
48 | self.conv_cls = nn.Sequential(
49 | nn.Conv2d(32, 32, kernel_size=3, padding=1),
50 | nn.ReLU(inplace=True),
51 | nn.Conv2d(32, 32, kernel_size=3, padding=1),
52 | nn.ReLU(inplace=True),
53 | nn.Conv2d(32, 16, kernel_size=3, padding=1),
54 | nn.ReLU(inplace=True),
55 | nn.Conv2d(16, 16, kernel_size=1),
56 | nn.ReLU(inplace=True),
57 | nn.Conv2d(16, num_class, kernel_size=1),
58 | )
59 |
60 | init_weights(self.upconv1.modules())
61 | init_weights(self.upconv2.modules())
62 | init_weights(self.upconv3.modules())
63 | init_weights(self.upconv4.modules())
64 | init_weights(self.conv_cls.modules())
65 |
66 | def forward(self, x: Tensor):
67 | # Base network
68 | sources = self.basenet(x)
69 |
70 | # U network
71 | y = torch.cat([sources[0], sources[1]], dim=1)
72 | y = self.upconv1(y)
73 |
74 | y = F.interpolate(
75 | y,
76 | size=sources[2].size()[2:],
77 | mode="bilinear",
78 | align_corners=False,
79 | )
80 | y = torch.cat([y, sources[2]], dim=1)
81 | y = self.upconv2(y)
82 |
83 | y = F.interpolate(
84 | y,
85 | size=sources[3].size()[2:],
86 | mode="bilinear",
87 | align_corners=False,
88 | )
89 | y = torch.cat([y, sources[3]], dim=1)
90 | y = self.upconv3(y)
91 |
92 | y = F.interpolate(
93 | y,
94 | size=sources[4].size()[2:],
95 | mode="bilinear",
96 | align_corners=False,
97 | )
98 | y = torch.cat([y, sources[4]], dim=1)
99 | feature = self.upconv4(y)
100 |
101 | y = self.conv_cls(feature)
102 |
103 | return y.permute(0, 2, 3, 1), feature
104 |
--------------------------------------------------------------------------------
/pororoOCR/server/pororo/models/brainOCR/detection.py:
--------------------------------------------------------------------------------
1 | """
2 | This code is adapted from https://github.com/JaidedAI/EasyOCR/blob/master/easyocr/detection.py
3 | """
4 |
5 | from collections import OrderedDict
6 |
7 | import cv2
8 | import numpy as np
9 | import torch
10 | import torch.backends.cudnn as cudnn
11 | from torch.autograd import Variable
12 |
13 | from .craft import CRAFT
14 | from .craft_utils import adjust_result_coordinates, get_det_boxes
15 | from .imgproc import normalize_mean_variance, resize_aspect_ratio
16 |
17 |
18 | def copy_state_dict(state_dict):
19 | if list(state_dict.keys())[0].startswith("module"):
20 | start_idx = 1
21 | else:
22 | start_idx = 0
23 | new_state_dict = OrderedDict()
24 | for k, v in state_dict.items():
25 | name = ".".join(k.split(".")[start_idx:])
26 | new_state_dict[name] = v
27 | return new_state_dict
28 |
29 |
30 | def test_net(image: np.ndarray, net, opt2val: dict):
31 | canvas_size = opt2val["canvas_size"]
32 | mag_ratio = opt2val["mag_ratio"]
33 | text_threshold = opt2val["text_threshold"]
34 | link_threshold = opt2val["link_threshold"]
35 | low_text = opt2val["low_text"]
36 | device = opt2val["device"]
37 |
38 | # resize
39 | img_resized, target_ratio, size_heatmap = resize_aspect_ratio(
40 | image, canvas_size, interpolation=cv2.INTER_LINEAR, mag_ratio=mag_ratio)
41 | ratio_h = ratio_w = 1 / target_ratio
42 |
43 | # preprocessing
44 | x = normalize_mean_variance(img_resized)
45 | x = torch.from_numpy(x).permute(2, 0, 1) # [h, w, c] to [c, h, w]
46 | x = Variable(x.unsqueeze(0)) # [c, h, w] to [b, c, h, w]
47 | x = x.to(device)
48 |
49 | # forward pass
50 | with torch.no_grad():
51 | y, feature = net(x)
52 |
53 | # make score and link map
54 | score_text = y[0, :, :, 0].cpu().data.numpy()
55 | score_link = y[0, :, :, 1].cpu().data.numpy()
56 |
57 | # Post-processing
58 | boxes, polys = get_det_boxes(
59 | score_text,
60 | score_link,
61 | text_threshold,
62 | link_threshold,
63 | low_text,
64 | )
65 |
66 | # coordinate adjustment
67 | boxes = adjust_result_coordinates(boxes, ratio_w, ratio_h)
68 | polys = adjust_result_coordinates(polys, ratio_w, ratio_h)
69 | for k in range(len(polys)):
70 | if polys[k] is None:
71 | polys[k] = boxes[k]
72 |
73 | return boxes, polys
74 |
75 |
76 | def get_detector(det_model_ckpt_fp: str, device: str = "cpu"):
77 | net = CRAFT()
78 |
79 | net.load_state_dict(
80 | copy_state_dict(torch.load(det_model_ckpt_fp, map_location=device)))
81 | if device == "cuda":
82 | net = torch.nn.DataParallel(net).to(device)
83 | cudnn.benchmark = False
84 |
85 | net.eval()
86 | return net
87 |
88 |
89 | def get_textbox(detector, image: np.ndarray, opt2val: dict):
90 | bboxes, polys = test_net(image, detector, opt2val)
91 | result = []
92 | for i, box in enumerate(polys):
93 | poly = np.array(box).astype(np.int32).reshape((-1))
94 | result.append(poly)
95 |
96 | return result
97 |
--------------------------------------------------------------------------------
/pororoOCR/server/pororo/models/brainOCR/imgproc.py:
--------------------------------------------------------------------------------
1 | """
2 | This is adapted from https://github.com/clovaai/CRAFT-pytorch/blob/master/imgproc.py
3 | Copyright (c) 2019-present NAVER Corp.
4 | MIT License
5 | """
6 |
7 | import cv2
8 | import numpy as np
9 | from skimage import io
10 |
11 |
12 | def load_image(img_file):
13 | img = io.imread(img_file) # RGB order
14 | if img.shape[0] == 2:
15 | img = img[0]
16 | if len(img.shape) == 2:
17 | img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
18 | if img.shape[2] == 4:
19 | img = img[:, :, :3]
20 | img = np.array(img)
21 |
22 | return img
23 |
24 |
25 | def normalize_mean_variance(
26 | in_img,
27 | mean=(0.485, 0.456, 0.406),
28 | variance=(0.229, 0.224, 0.225),
29 | ):
30 | # should be RGB order
31 | img = in_img.copy().astype(np.float32)
32 |
33 | img -= np.array([mean[0] * 255.0, mean[1] * 255.0, mean[2] * 255.0],
34 | dtype=np.float32)
35 | img /= np.array(
36 | [variance[0] * 255.0, variance[1] * 255.0, variance[2] * 255.0],
37 | dtype=np.float32,
38 | )
39 | return img
40 |
41 |
42 | def denormalize_mean_variance(
43 | in_img,
44 | mean=(0.485, 0.456, 0.406),
45 | variance=(0.229, 0.224, 0.225),
46 | ):
47 | # should be RGB order
48 | img = in_img.copy()
49 | img *= variance
50 | img += mean
51 | img *= 255.0
52 | img = np.clip(img, 0, 255).astype(np.uint8)
53 | return img
54 |
55 |
56 | def resize_aspect_ratio(
57 | img: np.ndarray,
58 | square_size: int,
59 | interpolation: int,
60 | mag_ratio: float = 1.0,
61 | ):
62 | height, width, channel = img.shape
63 |
64 | # magnify image size
65 | target_size = mag_ratio * max(height, width)
66 |
67 | # set original image size
68 | if target_size > square_size:
69 | target_size = square_size
70 |
71 | ratio = target_size / max(height, width)
72 |
73 | target_h, target_w = int(height * ratio), int(width * ratio)
74 | proc = cv2.resize(img, (target_w, target_h), interpolation=interpolation)
75 |
76 | # make canvas and paste image
77 | target_h32, target_w32 = target_h, target_w
78 | if target_h % 32 != 0:
79 | target_h32 = target_h + (32 - target_h % 32)
80 | if target_w % 32 != 0:
81 | target_w32 = target_w + (32 - target_w % 32)
82 | resized = np.zeros((target_h32, target_w32, channel), dtype=np.float32)
83 | resized[0:target_h, 0:target_w, :] = proc
84 | target_h, target_w = target_h32, target_w32
85 |
86 | size_heatmap = (int(target_w / 2), int(target_h / 2))
87 |
88 | return resized, ratio, size_heatmap
89 |
90 |
91 | def cvt2heatmap_img(img):
92 | img = (np.clip(img, 0, 1) * 255).astype(np.uint8)
93 | img = cv2.applyColorMap(img, cv2.COLORMAP_JET)
94 | return img
95 |
--------------------------------------------------------------------------------
/pororoOCR/server/pororo/models/brainOCR/modules/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xulihang/ImageTrans_plugins/87a0b5937263fa14f5fcd1abe53446c2b87ef1b0/pororoOCR/server/pororo/models/brainOCR/modules/__init__.py
--------------------------------------------------------------------------------
/pororoOCR/server/pororo/models/brainOCR/modules/basenet.py:
--------------------------------------------------------------------------------
1 | from collections import namedtuple
2 |
3 | import torch
4 | import torch.nn as nn
5 | import torch.nn.init as init
6 | from torchvision import models
7 | from torchvision.models.vgg import model_urls
8 |
9 | if torch.mps.is_available():
10 | device = torch.device("mps")
11 | elif torch.cuda.is_available():
12 | device = torch.device("cuda")
13 | else:
14 | device = torch.device("cpu")
15 |
16 | def init_weights(modules):
17 | for m in modules:
18 | if isinstance(m, nn.Conv2d):
19 | init.xavier_uniform_(m.weight.data)
20 | if m.bias is not None:
21 | m.bias.data.zero_()
22 | elif isinstance(m, nn.BatchNorm2d):
23 | m.weight.data.fill_(1)
24 | m.bias.data.zero_()
25 | elif isinstance(m, nn.Linear):
26 | m.weight.data.normal_(0, 0.01)
27 | m.bias.data.zero_()
28 |
29 |
30 | class Vgg16BN(torch.nn.Module):
31 |
32 | def __init__(self, pretrained: bool = True, freeze: bool = True):
33 | super(Vgg16BN, self).__init__()
34 | model_urls["vgg16_bn"] = model_urls["vgg16_bn"].replace(
35 | "https://", "http://")
36 | vgg_pretrained_features = models.vgg16_bn(
37 | pretrained=pretrained).features
38 | self.slice1 = torch.nn.Sequential()
39 | self.slice2 = torch.nn.Sequential()
40 | self.slice3 = torch.nn.Sequential()
41 | self.slice4 = torch.nn.Sequential()
42 | self.slice5 = torch.nn.Sequential()
43 | for x in range(12): # conv2_2
44 | self.slice1.add_module(str(x), vgg_pretrained_features[x])
45 | for x in range(12, 19): # conv3_3
46 | self.slice2.add_module(str(x), vgg_pretrained_features[x])
47 | for x in range(19, 29): # conv4_3
48 | self.slice3.add_module(str(x), vgg_pretrained_features[x])
49 | for x in range(29, 39): # conv5_3
50 | self.slice4.add_module(str(x), vgg_pretrained_features[x])
51 |
52 | # fc6, fc7 without atrous conv
53 | self.slice5 = torch.nn.Sequential(
54 | nn.MaxPool2d(kernel_size=3, stride=1, padding=1),
55 | nn.Conv2d(512, 1024, kernel_size=3, padding=6, dilation=6),
56 | nn.Conv2d(1024, 1024, kernel_size=1),
57 | )
58 |
59 | if not pretrained:
60 | init_weights(self.slice1.modules())
61 | init_weights(self.slice2.modules())
62 | init_weights(self.slice3.modules())
63 | init_weights(self.slice4.modules())
64 |
65 | init_weights(
66 | self.slice5.modules()) # no pretrained model for fc6 and fc7
67 |
68 | if freeze:
69 | for param in self.slice1.parameters(): # only first conv
70 | param.requires_grad = False
71 |
72 | def forward(self, x):
73 | h = self.slice1(x)
74 | h_relu2_2 = h
75 | h = self.slice2(h)
76 | h_relu3_2 = h
77 | h = self.slice3(h)
78 | h_relu4_3 = h
79 | h = self.slice4(h)
80 | h_relu5_3 = h
81 | h = self.slice5(h)
82 | h_fc7 = h
83 | vgg_outputs = namedtuple(
84 | "VggOutputs", ["fc7", "relu5_3", "relu4_3", "relu3_2", "relu2_2"])
85 | out = vgg_outputs(h_fc7, h_relu5_3, h_relu4_3, h_relu3_2, h_relu2_2)
86 | return out
87 |
--------------------------------------------------------------------------------
/pororoOCR/server/pororo/models/brainOCR/modules/sequence_modeling.py:
--------------------------------------------------------------------------------
1 | import torch.nn as nn
2 |
3 |
4 | class BidirectionalLSTM(nn.Module):
5 |
6 | def __init__(self, input_size: int, hidden_size: int, output_size: int):
7 | super(BidirectionalLSTM, self).__init__()
8 | self.rnn = nn.LSTM(input_size,
9 | hidden_size,
10 | bidirectional=True,
11 | batch_first=True)
12 | self.linear = nn.Linear(hidden_size * 2, output_size)
13 |
14 | def forward(self, x):
15 | """
16 | x : visual feature [batch_size x T=24 x input_size=512]
17 | output : contextual feature [batch_size x T x output_size]
18 | """
19 | self.rnn.flatten_parameters()
20 | recurrent, _ = self.rnn(
21 | x
22 | ) # batch_size x T x input_size -> batch_size x T x (2*hidden_size)
23 | output = self.linear(recurrent) # batch_size x T x output_size
24 | return output
25 |
--------------------------------------------------------------------------------
/pororoOCR/server/pororo/tasks/__init__.py:
--------------------------------------------------------------------------------
1 | # flake8: noqa
2 | """
3 | __init__.py for import child .py files
4 |
5 | isort:skip_file
6 | """
7 |
8 | # Utility classes & functions
9 | import pororo.tasks.utils
10 | from pororo.tasks.utils.download_utils import download_or_load
11 | from pororo.tasks.utils.base import (
12 | PororoBiencoderBase,
13 | PororoFactoryBase,
14 | PororoGenerationBase,
15 | PororoSimpleBase,
16 | PororoTaskGenerationBase,
17 | )
18 |
19 | # Factory classes
20 | from pororo.tasks.optical_character_recognition import PororoOcrFactory
21 |
--------------------------------------------------------------------------------
/pororoOCR/server/pororo/tasks/utils/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xulihang/ImageTrans_plugins/87a0b5937263fa14f5fcd1abe53446c2b87ef1b0/pororoOCR/server/pororo/tasks/utils/__init__.py
--------------------------------------------------------------------------------
/pororoOCR/server/pororo/tasks/utils/tokenizer.py:
--------------------------------------------------------------------------------
1 | from typing import List, Optional, Union
2 |
3 | from tokenizers import Tokenizer, decoders, pre_tokenizers
4 | from tokenizers.implementations import BaseTokenizer
5 | from tokenizers.models import BPE, Unigram
6 | from tokenizers.normalizers import NFKC
7 |
8 |
9 | class CustomTokenizer(BaseTokenizer):
10 |
11 | def __init__(
12 | self,
13 | vocab: Union[str, List],
14 | merges: Union[str, None],
15 | unk_token: str = "",
16 | replacement: str = "▁",
17 | add_prefix_space: bool = True,
18 | dropout: Optional[float] = None,
19 | normalize: bool = True,
20 | ):
21 | if merges:
22 | n_model = "BPE"
23 | tokenizer = Tokenizer(
24 | BPE(
25 | vocab, # type: ignore
26 | merges,
27 | unk_token=unk_token,
28 | fuse_unk=True,
29 | ))
30 | else:
31 | n_model = "Unigram"
32 | tokenizer = Tokenizer(Unigram(vocab, 1)) # type: ignore
33 |
34 | if normalize:
35 | tokenizer.normalizer = NFKC()
36 |
37 | tokenizer.pre_tokenizer = pre_tokenizers.Metaspace(
38 | replacement=replacement,
39 | add_prefix_space=add_prefix_space,
40 | )
41 |
42 | tokenizer.decoder = decoders.Metaspace(
43 | replacement=replacement,
44 | add_prefix_space=add_prefix_space,
45 | )
46 |
47 | parameters = {
48 | "model": f"SentencePiece{n_model}",
49 | "unk_token": unk_token,
50 | "replacement": replacement,
51 | "add_prefix_space": add_prefix_space,
52 | "dropout": dropout,
53 | }
54 | super().__init__(tokenizer, parameters)
55 |
56 | @staticmethod
57 | def from_file(
58 | vocab_filename: str,
59 | merges_filename: Union[str, None],
60 | **kwargs,
61 | ):
62 | # BPE
63 | if merges_filename:
64 | vocab, merges = BPE.read_file(vocab_filename, merges_filename)
65 |
66 | # Unigram
67 | else:
68 | vocab = []
69 | merges = None
70 | with open(vocab_filename, "r") as f_in:
71 | for line in f_in.readlines():
72 | token, score = line.strip().split("\t")
73 | vocab.append((token, float(score)))
74 |
75 | return CustomTokenizer(vocab, merges, **kwargs)
76 |
77 | def segment(self, text: str) -> List[str]:
78 | """
79 | Segment text into subword list
80 |
81 | Args:
82 | text (str): input text to be segmented
83 |
84 | Returns:
85 | List[str]: segmented subword list
86 |
87 | """
88 | encoding = self.encode(text)
89 |
90 | offsets = encoding.offsets
91 | tokens = encoding.tokens
92 |
93 | result = []
94 | for offset, token in zip(offsets, tokens):
95 | if token != "":
96 | result.append(token)
97 | continue
98 | s, e = offset
99 | result.append(text[s:e])
100 | return result
101 |
--------------------------------------------------------------------------------
/pororoOCR/server/pororo/utils.py:
--------------------------------------------------------------------------------
1 | from contextlib import contextmanager
2 | from tempfile import NamedTemporaryFile
3 |
4 | from requests import get
5 |
6 |
7 | def postprocess_span(tagger, text: str) -> str:
8 | """
9 | Postprocess NOUN span to remove unnecessary character
10 |
11 | Args:
12 | text (str): NOUN span to be processed
13 |
14 | Returns:
15 | (str): post-processed NOUN span
16 |
17 | Examples:
18 | >>> postprocess_span("강감찬 장군은")
19 | '강감찬 장군'
20 | >>> postprocess_span("그녀에게")
21 | '그녀'
22 |
23 | """
24 |
25 | # First, strip punctuations
26 | text = text.strip("""!"\#$&'()*+,\-./:;<=>?@\^_‘{|}~《》""")
27 |
28 | # Complete imbalanced parentheses pair
29 | if text.count("(") == text.count(")") + 1:
30 | text += ")"
31 | elif text.count("(") + 1 == text.count(")"):
32 | text = "(" + text
33 |
34 | # Preserve beginning tokens since we only want to extract noun phrase of the last eojeol
35 | noun_phrase = " ".join(text.rsplit(" ", 1)[:-1])
36 | tokens = text.split(" ")
37 | eojeols = list()
38 | for token in tokens:
39 | eojeols.append(tagger.pos(token))
40 | last_eojeol = eojeols[-1]
41 |
42 | # Iterate backwardly to remove unnecessary postfixes
43 | i = 0
44 | for i, token in enumerate(last_eojeol[::-1]):
45 | _, pos = token
46 | # 1. The loop breaks when you meet a noun
47 | # 2. The loop also breaks when you meet a XSN (e.g. 8/SN+일/NNB LG/SL 전/XSN)
48 | if (pos[0] in ("N", "S")) or pos.startswith("XSN"):
49 | break
50 | idx = len(last_eojeol) - i
51 |
52 | # Extract noun span from last eojeol and postpend it to beginning tokens
53 | ext_last_eojeol = "".join(morph for morph, _ in last_eojeol[:idx])
54 | noun_phrase += " " + ext_last_eojeol
55 | return noun_phrase.strip()
56 |
57 |
58 | @contextmanager
59 | def control_temp(file_path: str):
60 | """
61 | Download temporary file from web, then remove it after some context
62 |
63 | Args:
64 | file_path (str): web file path
65 |
66 | """
67 | # yapf: disable
68 | assert file_path.startswith("http"), "File path should contain `http` prefix !"
69 | # yapf: enable
70 |
71 | ext = file_path[file_path.rfind("."):]
72 |
73 | with NamedTemporaryFile("wb", suffix=ext, delete=True) as f:
74 | response = get(file_path, allow_redirects=True)
75 | f.write(response.content)
76 | yield f.name
77 |
--------------------------------------------------------------------------------
/pororoOCR/server/requirements.txt:
--------------------------------------------------------------------------------
1 | appnope==0.1.3
2 | backcall==0.2.0
3 | certifi==2022.12.7
4 | charset-normalizer==3.0.1
5 | cycler==0.11.0
6 | debugpy==1.6.6
7 | decorator==5.1.1
8 | entrypoints==0.4
9 | fonttools==4.38.0
10 | idna==3.4
11 | imageio==2.25.0
12 | ipykernel==6.16.2
13 | ipython==7.34.0
14 | jedi==0.18.2
15 | jupyter_client==7.4.9
16 | jupyter_core==4.12.0
17 | kiwisolver==1.4.4
18 | matplotlib==3.5.3
19 | matplotlib-inline==0.1.6
20 | nest-asyncio==1.5.6
21 | networkx==2.6.3
22 | numpy==1.21.6
23 | opencv-python==4.7.0.68
24 | packaging==23.0
25 | parso==0.8.3
26 | pexpect==4.8.0
27 | pickleshare==0.7.5
28 | Pillow==9.4.0
29 | prompt-toolkit==3.0.36
30 | psutil==5.9.4
31 | ptyprocess==0.7.0
32 | Pygments==2.14.0
33 | pyparsing==3.0.9
34 | python-dateutil==2.8.2
35 | PyWavelets==1.3.0
36 | pyzmq==25.0.0
37 | requests==2.28.2
38 | scikit-image==0.19.3
39 | scipy==1.7.3
40 | setuptools==65.6.3
41 | six==1.16.0
42 | tifffile==2021.11.2
43 | torch==1.13.1
44 | torchvision==0.14.1
45 | tornado==6.2
46 | traitlets==5.9.0
47 | typing_extensions==4.4.0
48 | urllib3==1.26.14
49 | wcwidth==0.2.6
50 | wget==3.2
51 | wheel==0.37.1
52 |
--------------------------------------------------------------------------------
/pororoOCR/server/server_pororo_ocr.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | from main import PororoOcr
3 | import os
4 | import time
5 | import datetime
6 | from bottle import route, run, template, request, static_file
7 | import json
8 |
9 | @route('/ocr', method='POST')
10 | def ocr():
11 | upload = request.files.get('upload')
12 | name, ext = os.path.splitext(upload.filename)
13 | print(ext.lower())
14 | if ext.lower() not in ('.png','.jpg','.jpeg'):
15 | return "File extension not allowed."
16 | timestamp=str(int(time.time()*1000))
17 | savedName=timestamp+ext
18 | save_path = "./uploaded/"
19 | if not os.path.exists(save_path):
20 | os.makedirs(save_path)
21 | file_path = "{path}/{file}".format(path=save_path, file=savedName)
22 | if os.path.exists(file_path)==True:
23 | os.remove(file_path)
24 | upload.save(file_path)
25 | ocr.run_ocr(file_path)
26 | results = ocr.get_ocr_result()
27 | print(results)
28 | os.remove(file_path)
29 | return results
30 |
31 |
32 | @route('/')
33 | def server_static(filepath):
34 | return static_file(filepath, root='www')
35 |
36 | ocr = PororoOcr()
37 | run(server="paste",host='0.0.0.0', port=8080)
38 |
39 |
--------------------------------------------------------------------------------
/pororoOCR/server/utils/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xulihang/ImageTrans_plugins/87a0b5937263fa14f5fcd1abe53446c2b87ef1b0/pororoOCR/server/utils/__init__.py
--------------------------------------------------------------------------------
/pororoOCR/server/utils/image_util.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | import platform
4 | from PIL import ImageFont, ImageDraw, Image
5 | from matplotlib import pyplot as plt
6 |
7 |
8 | def plt_imshow(title='image', img=None, figsize=(8, 5)):
9 | plt.figure(figsize=figsize)
10 |
11 | if type(img) is str:
12 | img = cv2.imread(img)
13 |
14 | if type(img) == list:
15 | if type(title) == list:
16 | titles = title
17 | else:
18 | titles = []
19 |
20 | for i in range(len(img)):
21 | titles.append(title)
22 |
23 | for i in range(len(img)):
24 | if len(img[i].shape) <= 2:
25 | rgbImg = cv2.cvtColor(img[i], cv2.COLOR_GRAY2RGB)
26 | else:
27 | rgbImg = cv2.cvtColor(img[i], cv2.COLOR_BGR2RGB)
28 |
29 | plt.subplot(1, len(img), i + 1), plt.imshow(rgbImg)
30 | plt.title(titles[i])
31 | plt.xticks([]), plt.yticks([])
32 |
33 | plt.show()
34 | else:
35 | if len(img.shape) < 3:
36 | rgbImg = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
37 | else:
38 | rgbImg = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
39 |
40 | plt.imshow(rgbImg)
41 | plt.title(title)
42 | plt.xticks([]), plt.yticks([])
43 | plt.show()
44 |
45 |
46 | def put_text(image, text, x, y, color=(0, 255, 0), font_size=22):
47 | if type(image) == np.ndarray:
48 | color_coverted = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
49 | image = Image.fromarray(color_coverted)
50 |
51 | if platform.system() == 'Darwin':
52 | font = 'AppleGothic.ttf'
53 | elif platform.system() == 'Windows':
54 | font = 'malgun.ttf'
55 |
56 | image_font = ImageFont.truetype(font, font_size)
57 | font = ImageFont.load_default()
58 | draw = ImageDraw.Draw(image)
59 |
60 | draw.text((x, y), text, font=image_font, fill=color)
61 |
62 | numpy_image = np.array(image)
63 | opencv_image = cv2.cvtColor(numpy_image, cv2.COLOR_RGB2BGR)
64 |
65 | return opencv_image
--------------------------------------------------------------------------------
/pororoOCR/server/www/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Upload
6 |
7 |
8 |
12 |
13 |
--------------------------------------------------------------------------------
/port_settings.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xulihang/ImageTrans_plugins/87a0b5937263fa14f5fcd1abe53446c2b87ef1b0/port_settings.jpg
--------------------------------------------------------------------------------
/sogouOCR/BoxesSort.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=StaticCode
5 | Version=7.8
6 | @EndOfDesignText@
7 | 'Static code module
8 | Sub Process_Globals
9 | Private fx As JFX
10 | End Sub
11 |
12 |
13 |
14 | Sub BubbleSort(boxesList As List,Xweight As Double,Yweight As Double) As List
15 | For j=0 To boxesList.Size-1
16 | For i = 1 To boxesList.Size - 1
17 | If NextIsLower(boxesList.Get(i),boxesList.Get(i-1),Xweight,Yweight) Then
18 | boxesList=Swap(boxesList,i, i-1)
19 | End If
20 | Next
21 | Next
22 | Return boxesList
23 | End Sub
24 |
25 | Sub Swap(boxesList As List,index1 As Int, index2 As Int) As List
26 | Dim temp As Map
27 | temp = boxesList.Get(index1)
28 | boxesList.Set(index1,boxesList.Get(index2))
29 | boxesList.Set(index2,temp)
30 | Return boxesList
31 | End Sub
32 |
33 | Sub NextIsLower(box1 As Map, box2 As Map, Xweight As Double, Yweight As Double) As Boolean
34 | 'XY1 is the next
35 | Dim boxGeometry1 As Map
36 | boxGeometry1=box1.Get("geometry")
37 | Dim X1,Y1 As Int
38 | X1=boxGeometry1.Get("X")
39 | Y1=boxGeometry1.Get("Y")
40 |
41 | Dim boxGeometry2 As Map
42 | boxGeometry2=box2.Get("geometry")
43 | Dim X2,Y2 As Int
44 | X2=boxGeometry2.Get("X")
45 | Y2=boxGeometry2.Get("Y")
46 |
47 | Dim diagonal1,diagonal2 As Int
48 | diagonal1=Xweight*Xweight*X1*X1+Yweight*Yweight*Y1*Y1
49 | diagonal2=Xweight*Xweight*X2*X2+Yweight*Yweight*Y2*Y2
50 | If diagonal1<=diagonal2 Then
51 | Return True
52 | Else
53 | Return False
54 | End If
55 | End Sub
56 |
57 | Sub BubbleSortBasedOnX(boxesList As List,right2left As Boolean) As List
58 | For j=0 To boxesList.Size-1
59 | For i = 1 To boxesList.Size - 1
60 | If right2left Then
61 | If NextHasBiggerX(boxesList.Get(i),boxesList.Get(i-1)) Then
62 | boxesList=Swap(boxesList,i, i-1)
63 | End If
64 | Else
65 | If NextHasSmallerX(boxesList.Get(i),boxesList.Get(i-1)) Then
66 | boxesList=Swap(boxesList,i, i-1)
67 | End If
68 | End If
69 | Next
70 | Next
71 | Return boxesList
72 | End Sub
73 |
74 | Sub NextHasSmallerX(box1 As Map, box2 As Map) As Boolean
75 | 'XY1 is the next
76 | Dim boxGeometry1 As Map
77 | boxGeometry1=box1.Get("geometry")
78 | Dim X1 As Int
79 | X1=boxGeometry1.Get("X")
80 | Dim boxGeometry2 As Map
81 | boxGeometry2=box2.Get("geometry")
82 | Dim X2 As Int
83 | X2=boxGeometry2.Get("X")
84 | If X1X2 Then
102 | Return True
103 | Else
104 | Return False
105 | End If
106 | End Sub
--------------------------------------------------------------------------------
/sogouOCR/OCR.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=StaticCode
5 | Version=7.8
6 | @EndOfDesignText@
7 | 'Static code module
8 | Sub Process_Globals
9 | Private fx As JFX
10 | End Sub
11 |
12 | Sub rightToLeft As Boolean
13 | Return True
14 | End Sub
--------------------------------------------------------------------------------
/sogouOCR/sogouOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=encryption
6 | Library11=byteconverter
7 | Library12=jsql
8 | Library2=jfx
9 | Library3=json
10 | Library4=jxmlsax
11 | Library5=xmlbuilder
12 | Library6=jxui
13 | Library7=javaobject
14 | Library8=jokhttputils2
15 | Library9=jstringutils
16 | Module1=sogouOCRPlugin
17 | Module2=Localizator
18 | Module3=OCR
19 | Module4=BoxesSort
20 | NumberOfFiles=0
21 | NumberOfLibraries=12
22 | NumberOfModules=4
23 | Version=7.8
24 | @EndOfDesignText@
25 | #Region Project Attributes
26 | #MainFormWidth: 600
27 | #MainFormHeight: 600
28 | #End Region
29 |
30 |
31 | Sub Process_Globals
32 | Private fx As JFX
33 | Public MainForm As Form
34 |
35 | End Sub
36 |
37 | Sub AppStart (Form1 As Form, Args() As String)
38 | MainForm = Form1
39 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
40 | MainForm.Show
41 | Log(DateTime.Now)
42 | Dim t As sogouOCRPlugin
43 | t.Initialize
44 | wait for (t.GetTextWithLocation(fx.LoadImage(File.DirApp,"image - 副本.jpg"),"zh-CHS")) Complete (done As Object)
45 | Log(done)
46 | End Sub
47 |
48 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
49 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
50 | Return True
51 | End Sub
52 |
--------------------------------------------------------------------------------
/sogouOCR/sogouOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBookmarks2=
4 | ModuleBookmarks3=
5 | ModuleBookmarks4=
6 | ModuleBreakpoints0=
7 | ModuleBreakpoints1=
8 | ModuleBreakpoints2=
9 | ModuleBreakpoints3=
10 | ModuleBreakpoints4=
11 | ModuleClosedNodes0=
12 | ModuleClosedNodes1=
13 | ModuleClosedNodes2=
14 | ModuleClosedNodes3=
15 | ModuleClosedNodes4=
16 | NavigationStack=sogouOCRPlugin,Class_Globals,0,0,OCR,Process_Globals,4,0,sogouOCRPlugin,GetTextWithLocation,82,0,sogouOCRPlugin,GetText,73,0,OCR,rightToLeft,6,1,sogouOCRPlugin,AddBox,151,5,BoxesSort,NextHasSmallerX,78,0,BoxesSort,NextHasBiggerX,78,0,BoxesSort,BubbleSortBasedOnX,61,6,sogouOCRPlugin,DoOCR,133,4
17 | SelectedBuild=0
18 | VisibleModules=1,2,3,4
19 |
--------------------------------------------------------------------------------
/sugoiMT/Readme.md:
--------------------------------------------------------------------------------
1 | See
--------------------------------------------------------------------------------
/sugoiMT/sugoiMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=byteconverter
6 | Library11=encryption
7 | Library2=jfx
8 | Library3=json
9 | Library4=jxmlsax
10 | Library5=xmlbuilder
11 | Library6=jxui
12 | Library7=javaobject
13 | Library8=jokhttputils2
14 | Library9=jstringutils
15 | Module1=sugoiMTPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=11
18 | NumberOfModules=1
19 | Version=8.9
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 |
30 | End Sub
31 |
32 | Sub AppStart (Form1 As Form, Args() As String)
33 | MainForm = Form1
34 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
35 | MainForm.Show
36 | Dim n As sugoiMTPlugin
37 | n.Initialize
38 | wait for (n.translate("人民網日本語版は中国で最も早く開設された日本語ニュースサイトです。","en","zh",CreateMap("api": CreateMap("sugoi":CreateMap("url":"http://192.168.3.25:8088"))))) complete (result As String)
39 | Log(result)
40 | End Sub
41 |
42 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
43 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
44 | Return True
45 | End Sub
46 |
--------------------------------------------------------------------------------
/sugoiMT/sugoiMT.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=sugoiMTPlugin,GetNiceName,13,0,Main,Process_Globals,8,0,sugoiMTPlugin,Class_Globals,0,0,sugoiMTPlugin,Run,31,0,sugoiMTPlugin,translate,37,6,Main,AppStart,17,6
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/sugoiMT/sugoiMTPlugin.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=Class
5 | Version=4.2
6 | @EndOfDesignText@
7 | Sub Class_Globals
8 | Private fx As JFX
9 | End Sub
10 |
11 | 'Initializes the object. You can NOT add parameters to this method!
12 | Public Sub Initialize() As String
13 | Log("Initializing plugin " & GetNiceName)
14 | ' Here return a key to prevent running unauthorized plugins
15 | Return "MyKey"
16 | End Sub
17 |
18 | ' must be available
19 | public Sub GetNiceName() As String
20 | Return "sugoiMT"
21 | End Sub
22 |
23 | ' must be available
24 | public Sub Run(Tag As String, Params As Map) As ResumableSub
25 | Log("run"&Params)
26 | Select Tag
27 | Case "getParams"
28 | Dim paramsList As List
29 | paramsList.Initialize
30 | paramsList.Add("url")
31 | Return paramsList
32 | Case "translate"
33 | wait for (translate(Params.Get("source"),Params.Get("sourceLang"),Params.Get("targetLang"),Params.Get("preferencesMap"))) complete (result As String)
34 | Return result
35 | Case "getDefaultParamValues"
36 | Return CreateMap("url":"http://localhost:14366")
37 | End Select
38 | Return ""
39 | End Sub
40 |
41 | Sub translate(source As String, sourceLang As String, targetLang As String,preferencesMap As Map) As ResumableSub
42 | Dim target As String
43 | Dim url As String = "http://localhost:14366"
44 | If preferencesMap.ContainsKey("api") Then
45 | Dim api As Map = preferencesMap.Get("api")
46 | If api.ContainsKey("sugoi") Then
47 | Dim settings As Map = api.Get("sugoi")
48 | url=settings.GetDefault("url",url)
49 | End If
50 | End If
51 | Dim params As Map
52 | params.Initialize
53 | params.Put("content",source)
54 | params.Put("message","translate sentences")
55 | Dim json As JSONGenerator
56 | json.Initialize(params)
57 | Dim job As HttpJob
58 | job.Initialize("",Me)
59 | job.PostString(url,json.ToString)
60 | job.GetRequest.SetContentType("application/json")
61 | Wait For (job) JobDone (job As HttpJob)
62 | If job.Success Then
63 | target=job.GetString
64 | If target.StartsWith($"""$) And source.StartsWith($"""$) = False Then
65 | target=target.SubString2(1,target.Length-1)
66 | End If
67 | Else
68 | target=""
69 | End If
70 | job.Release
71 | Return target
72 | End Sub
73 |
--------------------------------------------------------------------------------
/tencentOCR/tencentOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=encryption
6 | Library11=byteconverter
7 | Library12=jsql
8 | Library2=jfx
9 | Library3=json
10 | Library4=jxmlsax
11 | Library5=xmlbuilder
12 | Library6=jxui
13 | Library7=javaobject
14 | Library8=jokhttputils2
15 | Library9=jstringutils
16 | Module1=Localizator
17 | Module2=tencentOCRPlugin
18 | NumberOfFiles=0
19 | NumberOfLibraries=12
20 | NumberOfModules=2
21 | Version=8.9
22 | @EndOfDesignText@
23 | #Region Project Attributes
24 | #MainFormWidth: 600
25 | #MainFormHeight: 600
26 | #End Region
27 |
28 | Sub Process_Globals
29 | Private fx As JFX
30 | Public MainForm As Form
31 |
32 | End Sub
33 |
34 | Sub AppStart (Form1 As Form, Args() As String)
35 | MainForm = Form1
36 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
37 | MainForm.Show
38 | Dim t As tencentOCRPlugin
39 | t.Initialize
40 | wait for (t.GetTextWithLocation(fx.LoadImage(File.DirApp,"ttt.png"),"auto")) Complete (done As Object)
41 | Log(done)
42 | End Sub
43 |
44 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
45 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
46 | Return True
47 | End Sub
48 |
--------------------------------------------------------------------------------
/tencentOCR/tencentOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBookmarks2=
4 | ModuleBreakpoints0=
5 | ModuleBreakpoints1=
6 | ModuleBreakpoints2=
7 | ModuleClosedNodes0=
8 | ModuleClosedNodes1=
9 | ModuleClosedNodes2=
10 | NavigationStack=Main,Process_Globals,5,0,tencentOCRPlugin,saveImgToDiskWithSizeCheck,329,0,Localizator,AddToolTip,197,0,tencentOCRPlugin,Run,28,4,tencentOCRPlugin,getLangs,90,4,tencentOCRPlugin,GetTextWithLocation,106,0,tencentOCRPlugin,GetText,95,4,Main,AppStart,17,6,tencentOCRPlugin,getSignature,181,0,tencentOCRPlugin,ocr,172,6
11 | SelectedBuild=0
12 | VisibleModules=2,1
13 |
--------------------------------------------------------------------------------
/transliterationMT/readme.md:
--------------------------------------------------------------------------------
1 | See
--------------------------------------------------------------------------------
/transliterationMT/transliterationMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=byteconverter
5 | Library10=jxui
6 | Library11=xmlbuilder
7 | Library12=jshell
8 | Library2=encryption
9 | Library3=javaobject
10 | Library4=jcore
11 | Library5=jfx
12 | Library6=jokhttputils2
13 | Library7=json
14 | Library8=jstringutils
15 | Library9=jxmlsax
16 | Module1=transliterationMTPlugin
17 | NumberOfFiles=0
18 | NumberOfLibraries=12
19 | NumberOfModules=1
20 | Version=8.9
21 | @EndOfDesignText@
22 | #Region Project Attributes
23 | #MainFormWidth: 600
24 | #MainFormHeight: 600
25 | #End Region
26 |
27 | Sub Process_Globals
28 | Private fx As JFX
29 | Public MainForm As Form
30 |
31 | End Sub
32 |
33 | Sub AppStart (Form1 As Form, Args() As String)
34 | MainForm = Form1
35 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
36 | MainForm.Show
37 | Dim preferencesMap As Map
38 | preferencesMap.Initialize
39 | preferencesMap.Put("api",CreateMap("transliteration":CreateMap("use jakaroma (yes or no)":"yes","key":"")))
40 | Dim n As transliterationMTPlugin
41 | n.Initialize
42 | Dim text As String
43 | text = "先生!ココ!ココ!オレの隣が…"
44 | text = "中国"
45 | wait for (n.translate(text,"ja",preferencesMap)) complete (result As String)
46 | Log(result)
47 | End Sub
48 |
49 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
50 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
51 | Return True
52 | End Sub
53 |
--------------------------------------------------------------------------------
/transliterationMT/transliterationMT.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=transliterationMTPlugin,Initialize,11,0,transliterationMTPlugin,GetNiceName,13,0,transliterationMTPlugin,UUID,115,0,transliterationMTPlugin,getMap,109,0,transliterationMTPlugin,Jakaroma,61,6,transliterationMTPlugin,azure,62,0,transliterationMTPlugin,Run,28,6,transliterationMTPlugin,translate,37,6,Main,Process_Globals,10,0,Main,AppStart,17,6
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------
/tsvMT/Readme.md:
--------------------------------------------------------------------------------
1 | Store your translation in a tsv file.
2 |
3 | You need to specify the file path in the preference.
4 |
5 | Sample file:
6 |
7 | ```
8 | source 普通话 上海话
9 | I like you. 我喜欢你。 我欢喜侬。
10 | ```
11 |
12 | The translation candidates will be displayed in the Translation Assist panel.
13 |
14 |
--------------------------------------------------------------------------------
/tsvMT/tsvMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=byteconverter
6 | Library11=encryption
7 | Library2=jfx
8 | Library3=json
9 | Library4=jxmlsax
10 | Library5=xmlbuilder
11 | Library6=jxui
12 | Library7=javaobject
13 | Library8=jokhttputils2
14 | Library9=jstringutils
15 | Module1=tsvMTPlugin
16 | NumberOfFiles=0
17 | NumberOfLibraries=11
18 | NumberOfModules=1
19 | Version=8.9
20 | @EndOfDesignText@
21 | #Region Project Attributes
22 | #MainFormWidth: 600
23 | #MainFormHeight: 600
24 | #End Region
25 |
26 | Sub Process_Globals
27 | Private fx As JFX
28 | Public MainForm As Form
29 |
30 | End Sub
31 |
32 | Sub AppStart (Form1 As Form, Args() As String)
33 | MainForm = Form1
34 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
35 | MainForm.Show
36 | Dim n As tsvMTPlugin
37 | n.Initialize
38 | wait for (n.getMultipleCandidates("I like you.","en","zh",CreateMap("api": CreateMap("tsv":CreateMap("path":"F:\\test.txt"))))) complete (result As List)
39 | Log(result)
40 | End Sub
41 |
42 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
43 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
44 | Return True
45 | End Sub
46 |
--------------------------------------------------------------------------------
/volcanoMT/b4j/volcanoMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library2=jfx
6 | Library3=jshell
7 | Library4=json
8 | Library5=jstringutils
9 | Module1=volcanoMTPlugin
10 | NumberOfFiles=0
11 | NumberOfLibraries=5
12 | NumberOfModules=1
13 | Version=8.9
14 | @EndOfDesignText@
15 | #Region Project Attributes
16 | #MainFormWidth: 600
17 | #MainFormHeight: 600
18 | #End Region
19 |
20 | Sub Process_Globals
21 | Private fx As JFX
22 | Public MainForm As Form
23 |
24 | End Sub
25 |
26 | Sub AppStart (Form1 As Form, Args() As String)
27 | MainForm = Form1
28 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
29 | MainForm.Show
30 | Dim n As volcanoMTPlugin
31 | n.Initialize
32 | Dim map1 As Map
33 | map1.Initialize
34 | 'wait for (n.translate("BasicCAT Documentation."&CRLF&"Sentence2.","en","zh",CreateMap("api":CreateMap("deepl":map1)))) complete (result As String)
35 | wait for (n.translate(Array("BasicCAT Documentation.","Sentence2.","Paragraph2"),"en","zh",CreateMap("api":CreateMap("deepl":map1)))) complete (result As Object)
36 | Log(result)
37 | End Sub
38 |
39 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
40 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
41 | Return True
42 | End Sub
43 |
--------------------------------------------------------------------------------
/volcanoMT/b4j/volcanoMTPlugin.bas:
--------------------------------------------------------------------------------
1 | B4J=true
2 | Group=Default Group
3 | ModulesStructureVersion=1
4 | Type=Class
5 | Version=4.2
6 | @EndOfDesignText@
7 | Sub Class_Globals
8 | Private fx As JFX
9 | End Sub
10 |
11 | 'Initializes the object. You can NOT add parameters to this method!
12 | Public Sub Initialize() As String
13 | Log("Initializing plugin " & GetNiceName)
14 | ' Here return a key to prevent running unauthorized plugins
15 | Return "MyKey"
16 | End Sub
17 |
18 | ' must be available
19 | public Sub GetNiceName() As String
20 | Return "volcanoMT"
21 | End Sub
22 |
23 | ' must be available
24 | public Sub Run(Tag As String, Params As Map) As ResumableSub
25 | Select Tag
26 | Case "getParams"
27 | Dim paramsList As List
28 | paramsList.Initialize
29 | paramsList.Add("accesskey")
30 | paramsList.Add("secret")
31 | Return paramsList
32 | Case "translate"
33 | wait for (translate(Array(Params.Get("source")),Params.Get("sourceLang"),Params.Get("targetLang"),Params.Get("preferencesMap"))) complete (targetList As List)
34 | If targetList.Size>0 Then
35 | Return targetList.Get(0)
36 | Else
37 | Return ""
38 | End If
39 | Case "batchtranslate"
40 | wait for (translate(Params.Get("source"),Params.Get("sourceLang"),Params.Get("targetLang"),Params.Get("preferencesMap"))) complete (targetList As List)
41 | Return targetList
42 | Case "supportBatchTranslation"
43 | Return True
44 | End Select
45 | Return ""
46 | End Sub
47 |
48 |
49 | Sub translate(sourceList As List,sourceLang As String,targetLang As String,preferencesMap As Map) As ResumableSub
50 | Dim targetList As List
51 | targetList.Initialize
52 | Dim accesskey As String
53 | Dim secret As String
54 |
55 | Try
56 | accesskey=getMap("volcano",getMap("mt",preferencesMap)).Get("accesskey")
57 | secret=getMap("volcano",getMap("mt",preferencesMap)).Get("secret")
58 | Catch
59 | Log(LastException)
60 | End Try
61 |
62 |
63 | Dim map1 As Map
64 | map1.Initialize
65 | map1.Put("sourceLang",sourceLang)
66 | map1.Put("targetLang",targetLang)
67 | map1.Put("sourceList",sourceList)
68 | Dim json As JSONGenerator
69 | json.Initialize(map1)
70 | Dim su As StringUtils
71 | Dim body As String = su.EncodeUrl(json.ToString,"UTF8")
72 | Dim sh As Shell
73 | sh.Initialize("sh","java",Array("-jar","volcmt.jar",body,accesskey,secret))
74 | sh.Encoding=GetSystemProperty("sun.jnu.encoding","UTF8")
75 | sh.Run(10000)
76 | wait for sh_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
77 | If Success And ExitCode = 0 Then
78 | Try
79 | Dim jsonP As JSONParser
80 | jsonP.Initialize(StdOut)
81 | Dim translationList As List = jsonP.NextObject.Get("TranslationList")
82 | For Each translation As Map In translationList
83 | targetList.Add(translation.Get("Translation"))
84 | Next
85 | Catch
86 | Log(LastException)
87 | End Try
88 | End If
89 | Return targetList
90 | End Sub
91 |
92 |
93 | Sub getMap(key As String,parentmap As Map) As Map
94 | Return parentmap.Get(key)
95 | End Sub
96 |
--------------------------------------------------------------------------------
/volcanoMT/java/.classpath:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/volcanoMT/java/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | volcmt
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/volcanoMT/java/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.xulihang
6 | volcmt
7 | 0.0.1-SNAPSHOT
8 | jar
9 |
10 | volcmt
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | junit
20 | junit
21 | 3.8.1
22 | test
23 |
24 |
25 | com.volcengine
26 | volc-sdk-java
27 | 1.0.42
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/volcanoMT/java/src/main/java/com/xulihang/volcmt/App.java:
--------------------------------------------------------------------------------
1 | package com.xulihang.volcmt;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.net.URLDecoder;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | import com.alibaba.fastjson.JSON;
9 | import com.alibaba.fastjson.JSONArray;
10 | import com.alibaba.fastjson.JSONObject;
11 | import com.volcengine.model.request.TranslateTextRequest;
12 | import com.volcengine.model.response.TranslateTextResponse;
13 | import com.volcengine.service.translate.ITranslateService;
14 | import com.volcengine.service.translate.impl.TranslateServiceImpl;
15 |
16 | /**
17 | * Hello world!
18 | *
19 | */
20 | public class App
21 | {
22 | public static void main( String[] args )
23 | {
24 | ITranslateService translateService = TranslateServiceImpl.getInstance();
25 | // call below method if you dont set ak and sk in ~/.volc/config
26 |
27 | if (args.length == 3) {
28 |
29 | try {
30 | translateService.setAccessKey(args[1]);
31 | translateService.setSecretKey(args[2]);
32 | JSONObject jsonObject;
33 | jsonObject = (JSONObject) JSON.parse(URLDecoder.decode(args[0],"UTF-8"));
34 |
35 | TranslateTextRequest translateTextRequest = new TranslateTextRequest();
36 | if (jsonObject.containsKey("souceLang")) {
37 | translateTextRequest.setSourceLanguage(jsonObject.getString("sourceLang")); // 不设置表示自动检测
38 | }
39 |
40 | translateTextRequest.setTargetLanguage(jsonObject.getString("targetLang"));
41 | translateTextRequest.setTextList(convertTextList(jsonObject.getJSONArray(("sourceList"))));
42 |
43 | TranslateTextResponse translateText = translateService.translateText(translateTextRequest);
44 | System.out.println(JSON.toJSONString(translateText));
45 | } catch (Exception e) {
46 | System.out.println(e.getMessage());
47 | }
48 | }else{
49 | System.out.println("Invalid arguments length of "+args.length);
50 | }
51 |
52 | }
53 |
54 | private static List convertTextList(JSONArray textArray) {
55 | List textList = new ArrayList();
56 | for (int i=0;i
--------------------------------------------------------------------------------
/yandexMT/yandexMT.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library2=jfx
6 | Library3=json
7 | Library4=jxmlsax
8 | Library5=xmlbuilder
9 | Library6=jxui
10 | Library7=javaobject
11 | Library8=jokhttputils2
12 | Library9=jstringutils
13 | Module1=yandexMTPlugin
14 | NumberOfFiles=0
15 | NumberOfLibraries=9
16 | NumberOfModules=1
17 | Version=9.8
18 | @EndOfDesignText@
19 | #Region Project Attributes
20 | #MainFormWidth: 600
21 | #MainFormHeight: 600
22 | #End Region
23 |
24 | Sub Process_Globals
25 | Private fx As JFX
26 | Public MainForm As Form
27 |
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim preferences As Map
35 | preferences.Initialize
36 | preferences.Put("mt",CreateMap("yandex":CreateMap("OAuth Token":"","Folder ID":"")))
37 | Dim source As List = Array As String("Hello","World")
38 | Dim n As yandexMTPlugin
39 | n.Initialize
40 | wait for (n.Run("batchtranslate",CreateMap("source":source,"sourceLang":"en","targetLang":"zh","preferencesMap":preferences))) Complete (resultList As List)
41 | Log(resultList)
42 | wait for (n.Run("translate",CreateMap("source":"Hello world!","sourceLang":"en","targetLang":"zh","preferencesMap":preferences))) Complete (result As String)
43 | Log(result)
44 | End Sub
45 |
46 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
47 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
48 | Return True
49 | End Sub
50 |
--------------------------------------------------------------------------------
/yomikakuOCR/readme.md:
--------------------------------------------------------------------------------
1 | See .
--------------------------------------------------------------------------------
/yomikakuOCR/yomikakuOCR.b4j:
--------------------------------------------------------------------------------
1 | AppType=JavaFX
2 | Build1=Default,org.xulihang.imagetrans
3 | Group=Default Group
4 | Library1=jcore
5 | Library10=jshell
6 | Library2=jfx
7 | Library3=json
8 | Library4=jxmlsax
9 | Library5=xmlbuilder
10 | Library6=jxui
11 | Library7=javaobject
12 | Library8=jokhttputils2
13 | Library9=jstringutils
14 | Module1=yomikakuOCRPlugin
15 | NumberOfFiles=0
16 | NumberOfLibraries=10
17 | NumberOfModules=1
18 | Version=8.9
19 | @EndOfDesignText@
20 | #Region Project Attributes
21 | #MainFormWidth: 600
22 | #MainFormHeight: 600
23 | #End Region
24 |
25 | Sub Process_Globals
26 | Private fx As JFX
27 | Public MainForm As Form
28 | End Sub
29 |
30 | Sub AppStart (Form1 As Form, Args() As String)
31 | MainForm = Form1
32 | 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
33 | MainForm.Show
34 | Dim n As yomikakuOCRPlugin
35 | n.Initialize
36 | wait for (n.GetText(fx.LoadImage(File.DirApp,"image.jpg"))) Complete (text As String)
37 | Log(text)
38 | 'wait for (n.translate("Hello","en","zh")) complete (result As String)
39 | 'Log(result)
40 | End Sub
41 |
42 | 'Return true to allow the default exceptions handler to handle the uncaught exception.
43 | Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
44 | Return True
45 | End Sub
46 |
--------------------------------------------------------------------------------
/yomikakuOCR/yomikakuOCR.b4j.meta:
--------------------------------------------------------------------------------
1 | ModuleBookmarks0=
2 | ModuleBookmarks1=
3 | ModuleBreakpoints0=
4 | ModuleBreakpoints1=
5 | ModuleClosedNodes0=
6 | ModuleClosedNodes1=
7 | NavigationStack=yomikakuOCRPlugin,getLangs,49,6,yomikakuOCRPlugin,GetTextWithLocation,59,0,yomikakuOCRPlugin,readJsonAsMap,85,0,yomikakuOCRPlugin,getMap,89,0,yomikakuOCRPlugin,Class_Globals,0,0,yomikakuOCRPlugin,GetText,52,1,yomikakuOCRPlugin,GetNiceName,15,0,Main,AppStart,16,1,yomikakuOCRPlugin,Run,24,5,yomikakuOCRPlugin,ocr,81,6
8 | SelectedBuild=0
9 | VisibleModules=1
10 |
--------------------------------------------------------------------------------