iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 24
0
自我挑戰組

軟體開發隨筆雜記--試著解決問題系列 第 24

[Python][OpenCV]如何利用Tesserect OCR做翻譯器

https://ithelp.ithome.com.tw/upload/images/20201009/20119608yIBKvYzi2w.jpg
借用google的翻譯功能

from googletrans import Translator

主模組參數設定

class tesserectOCR():
    def __init__(self, master):
        self.parent = master
        self.color_1 = (0,0,0)
        self.color_2 = (0,0,0)
        self.imageFile = str()
        self.tesserectOCRPanel = tk.LabelFrame(self.parent,
                                               text="tesserect OCR",
                                               font=('Courier', 10))
        self.tesserectOCRPanel.pack(side=tk.TOP)
        self.init_tesserect_tab()
        self.init_setting_tab()
        self.init_Font_tab()
        self.init_GoogleTran_tab()
        self.init_DisplaySceneMarkInfo_tab()
    def tesseract_OCR(self, event = None):
        .
        .
        .
    def init_tesserect_tab(self):
        .
        .
        .
    def googleTrans(self, event = None):
        .
        .
        .

google翻譯面板設置

    def init_GoogleTran_tab(self):
        self.GoogleTran_tab = tk.Frame(self.tesserectOCRPanel)
        self.GoogleTran_tab.pack(side = tk.TOP,
                                 expand=tk.YES,
                                 fill=tk.BOTH)
        self.googleTrans_Button = tk.Button(self.GoogleTran_tab,
                                            text = "Google Translate",
                                            font=('Courier', 10),
                                            command = self.googleTrans)
        self.googleTrans_Button.pack(side=tk.LEFT, expand=tk.NO, fill = tk.X)
        self.dest_langType = ttk.Combobox(self.GoogleTran_tab,
                                          font=('Courier', 10),
                                          width = 25,
                                          values = ["en",
                                                    "zh-CN",
                                                    "ja",
                                                    "ko",
                                                    "ar"],
                                          state = "readonly") 
        self.dest_langType.pack(side=tk.LEFT, expand=tk.NO, fill = tk.X)
        self.dest_langType.current(0)
    def init_Font_tab(self):
        .
        .
        .
    def init_setting_tab(self):
        .
        .
        .

顯示資訊

    def init_DisplaySceneMarkInfo_tab(self):
        self.DisplaySceneMarkInfo_Frame = tk.LabelFrame(self.tesserectOCRPanel,
                 text="Display tesseract OCR and Translation Info",
                 font=('Courier', 9))
        self.DisplaySceneMarkInfo_Frame .pack(side=tk.TOP, expand=tk.NO)
        self.DisplaySceneMarkInfo = tk.Text(
                                      self.DisplaySceneMarkInfo_Frame,
                                      width = 70,
                                      height = 7) 
        DisplaySceneMarkInfo_sbarV = Scrollbar(
                                      self.DisplaySceneMarkInfo_Frame, 
                                      orient=tk.VERTICAL)
        DisplaySceneMarkInfo_sbarH = Scrollbar(
                                      self.DisplaySceneMarkInfo_Frame, 
                                      orient=tk.HORIZONTAL)
        DisplaySceneMarkInfo_sbarV.config(
                      command=self.DisplaySceneMarkInfo.yview)
        DisplaySceneMarkInfo_sbarH.config(
                      command=self.DisplaySceneMarkInfo.xview)
        self.DisplaySceneMarkInfo.config(
                      yscrollcommand=DisplaySceneMarkInfo_sbarV.set)
        self.DisplaySceneMarkInfo.config(
                      xscrollcommand=DisplaySceneMarkInfo_sbarH.set)
        DisplaySceneMarkInfo_sbarV.pack(side=tk.RIGHT, fill=tk.Y)
        DisplaySceneMarkInfo_sbarH.pack(side=tk.BOTTOM, fill=tk.X)
        self.DisplaySceneMarkInfo.pack(side=tk.TOP, expand=tk.NO)
        DisplaySceneMarkInfoCLEAR =tk.Button(self.tesserectOCRPanel,
                                             text = "Clear",
                                             font=('Courier', 9),
                                             command = self.DisplaySceneMarkInfoCLEAR)
        DisplaySceneMarkInfoCLEAR.pack(side=tk.TOP, expand=tk.NO)

    def DisplaySceneMarkInfoCLEAR(self, event = None):
        .
        .
        .

文字
https://ithelp.ithome.com.tw/upload/images/20201009/201196086fRRzYC6fB.png
https://ithelp.ithome.com.tw/upload/images/20201009/201196084xjs7Ew7KG.png!
翻譯
https://ithelp.ithome.com.tw/upload/images/20201009/20119608HDoLNGjTpl.png


上一篇
[Python][OpenCV]如何利用Tesserect OCR做辨識
下一篇
[Python] 把 mp4 轉換成 gif
系列文
軟體開發隨筆雜記--試著解決問題33
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言