[orca-list] OCR Current Window



Hi Guys,
i play a little arround with tesserwrap. i dont know if it really make sense but maybe someone need this. i wrote a little orca-cust for taking a screen shot of the current window and pass it through tesseract. just press
orca + m
orca will start reading the content of the window (maybe the image program or browser with pictures or an other not accessible content) and set it to the clipboard.
You need tesseract tesserwrap, your tesseract-language-pack and orca >= 3.14

hier is the cust script for those who are interested in:

# Requiere: tesserwrap, tesseract, orca >=3.14
# -*- coding: utf-8 -*-

#Python
import os
from PIL import Image
import locale

#tesseract
from tesserwrap import tesseract

#GTK/GDK
from gi.repository import Gtk, Gdk

# Orca
import orca.orca
import orca.input_event
import orca.settings
import orca.keybindings
import orca.speech
import orca.braille

#Settings-
#this is need by arch for correct braille
orca.settings.tty = 1
#Settings+

#Bind Function to key-
myKeyBindings = orca.keybindings.KeyBindings()

def DefineShortcut(pHandle,pShortcut):
    myKeyBindings.add(orca.keybindings.KeyBinding(
        pShortcut,
        1 << orca.keybindings.MODIFIER_ORCA,
        1 << orca.keybindings.MODIFIER_ORCA,
        pHandle))
    orca.settings.keyBindingsMap["default"] = myKeyBindings
#Bind Function to key+

#OCRPath-
def ocr_path(path):
    img = Image.open(path)
    tr = tesseract("/usr/share")
    new_string = tr.ocr_image(img)
    return new_string
#OCRPath+

#Set to Clipboard
def setTextToClipboard(text):
    ClipboardObj = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
    ClipboardObj.set_text(text, -1)

#Display Message-
#Speak or Braille
def outputMessage(Message):
    if (orca.settings.enableSpeech):
        orca.speech.speak(Message)
    if (orca.settings.enableBraille):
        orca.braille.displayMessage(Message)
#Display Message+

#OCR Current Window-
def ocrWindow(script, inputEvent=None):
    os.popen('gnome-screenshot -w -f "/tmp/orca-currwindow.png"').read()
    locale.setlocale(locale.LC_NUMERIC, 'C')
    OCRText = ocr_path("/tmp/orca-currwindow.png")
    setTextToClipboard(OCRText)
    outputMessage(OCRText)
    return True
#OCR Current Window+

# define OcrHandler-
ocrWindowHandler = orca.input_event.InputEventHandler(
    ocrWindow, "OCR Current window") #OCR the current window
# define OcrHandler+


DefineShortcut(ocrWindowHandler,"m"); #Shortcut Orca + m



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]