[ocrfeeder] Add recognize selected areas feature



commit a97c57343f98d7cf3428526ce86853f8955adadd
Author: Joaquim Rocha <jrocha cookiemonster local igalia com>
Date:   Wed Mar 24 10:17:43 2010 +0100

    Add recognize selected areas feature

 studio/studioBuilder.py   |    3 ++-
 studio/widgetModeler.py   |   31 ++++++++++++++++++++++++++-----
 studio/widgetPresenter.py |    2 ++
 3 files changed, 30 insertions(+), 6 deletions(-)
---
diff --git a/studio/studioBuilder.py b/studio/studioBuilder.py
index f9ebaf5..85a68d4 100644
--- a/studio/studioBuilder.py
+++ b/studio/studioBuilder.py
@@ -85,7 +85,8 @@ class Studio:
                                  'open_project': self.openProject, 'append_project': self.appendProject,'clear': self.clear,
                                  'unpaper': self.unpaper, 'preferences': self.preferences, 'about': self.about,
                                  'ocr_engines': self.ocrEngines, 'zoom_in': self.zoomIn, 'zoom_out': self.zoomOut,
-                                 'zoom_fit': self.zoomFit, 'reset_zoom': self.resetZoom}
+                                 'zoom_fit': self.zoomFit, 'reset_zoom': self.resetZoom,
+                                 'recognize_areas': self.source_images_controler.recognizeSelectedAreas}
         
         self.main_window.setHeader(menubar_callback_dict, toolbar_callback_dict)
         self.main_window.setDestroyEvent(self.quit)
diff --git a/studio/widgetModeler.py b/studio/widgetModeler.py
index 44b2089..c2cb721 100644
--- a/studio/widgetModeler.py
+++ b/studio/widgetModeler.py
@@ -242,10 +242,16 @@ class ImageReviewer:
         return False
     
     def __getPageNumFromBox(self, box):
+        editor = self.__getEditorFromBox(box)
+        if editor:
+            return self.boxeditor_notebook.page_num(editor.box_editor)
+        return -1
+
+    def __getEditorFromBox(self, box):
         for editor in self.editor_list:
             if editor.box == box:
-                return self.boxeditor_notebook.page_num(editor.box_editor)
-        return -1
+                return editor
+        return None
     
     def applyTextColors(self):
         self.selectable_boxes_area.fill_color_rgba = self.text_box_fill_color
@@ -262,12 +268,23 @@ class ImageReviewer:
             self.addBoxEditor(box)
     
     def performOcrForAllEditors(self, engine = None):
-        for editor in self.editor_list:
+        self.performOcrForEditors(self.editor_list, engine)
+
+    def performOcrForSelectedBoxes(self, engine = None):
+        selected_boxes = self.selectable_boxes_area.getSelectedAreas()
+        self.performOcrForEditors([self.__getEditorFromBox(box) \
+                                   for box in selected_boxes],
+                                  engine)
+
+    def performOcrForEditors(self, editors_list, engine = None):
+        for editor in editors_list:
+            if editor == None:
+                continue
             editor.performOcr(engine)
             editor.performClassification(engine)
             if editor.box_editor.getType() == IMAGE_TYPE:
                 editor.box_editor.setText('')
-    
+
     def __getAllDataBoxes(self):
         boxes = []
         for editor in self.editor_list:
@@ -366,7 +383,11 @@ class ImageReviewer_Controler:
     
     def __setZoomStatus(self, widget, zoom):
         self.tripple_statusbar.left_statusbar.insert(_('Zoom') + ': ' + str(int(zoom * 100)) + '%')
-    
+
+    def recognizeSelectedAreas(self, widget):
+        image_reviewer = self.__getCurrentReviewer()
+        image_reviewer.performOcrForSelectedBoxes(self.configuration_manager.favorite_engine)
+
     def performBoxDetection(self, widget):
         image_reviewer = self.__getCurrentReviewer()
         self.performBoxDetectionForReviewer(image_reviewer)
diff --git a/studio/widgetPresenter.py b/studio/widgetPresenter.py
index 6559182..93e536d 100644
--- a/studio/widgetPresenter.py
+++ b/studio/widgetPresenter.py
@@ -73,6 +73,7 @@ class MainWindow:
         </menu>
         <menu action="Document">
             <menuitem action="OCRFeederDetection"/>
+            <menuitem action="RecognizeAreas"/>
         </menu>
         <menu action="Tools">
             <menuitem action="OCREngines"/>
@@ -158,6 +159,7 @@ class MainWindow:
                                   ('Help', None, _('_Help')),
                                   ('About', gtk.STOCK_ABOUT, _('_About'), None, _('About this application'), menu_items['about']),
                                   ('OCRFeederDetection', None, _('_Recognize Document'), None, _("Automatic Detection and Recognition"), tool_items['detection']),
+                                  ('RecognizeAreas', None, _('Recognize Selected _Areas'), None, _("Recognize Selected Areas"), menu_items['recognize_areas']),
                                   ('GenerateODT', None, _('_Generate ODT'), None, _("Export to ODT"), tool_items['export_to_odt']),
                                   ])
         ui_manager.insert_action_group(action_group, 0)



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