Re: [orca-list] OCR Current Window



This is a very important function for some situations. I used NVDA's ocr add-on some when it first came out. 
What would be great is if one could use 
controls that one can see with the ocr. I have not tested this, so if this is already possible, congrats!
I'd forgotten about this, but I'd thought this would be a very good and inportant addition ever since testing 
NVDA, and hearing of a similar function in 
jfw as well. 
Thanks for sharing.



-- 
     B.H.
   Registerd Linux User 521886


  chrys87 wrote:
Mon, Jan 26, 2015 at 11:28:08PM +0100

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

_______________________________________________
orca-list mailing list
orca-list gnome org
https://mail.gnome.org/mailman/listinfo/orca-list
Visit http://live.gnome.org/Orca for more information on Orca.
The manual is at http://library.gnome.org/users/gnome-access-guide/nightly/ats-2.html
The FAQ is at http://live.gnome.org/Orca/FrequentlyAskedQuestions
Log bugs and feature requests at http://bugzilla.gnome.org
Find out how to help at http://live.gnome.org/Orca/HowCanIHelp


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