[Pycodeocr-main] SF.net SVN: pycodeocr:[67] branches/redesign
Status: Beta
Brought to you by:
drtrigon
|
From: <la...@us...> - 2014-08-26 18:12:07
|
Revision: 67
http://sourceforge.net/p/pycodeocr/code/67
Author: laserb
Date: 2014-08-26 18:12:03 +0000 (Tue, 26 Aug 2014)
Log Message:
-----------
Add source and recognition selection.
Modified Paths:
--------------
branches/redesign/PyCodeOCR.py
branches/redesign/Recognition/Barcode.py
branches/redesign/Recognition/DTMX.py
branches/redesign/Recognition/DataMatrix.py
branches/redesign/Recognition/ESR.py
branches/redesign/Recognition/ImageRecognition.py
branches/redesign/Recognition/PDF417.py
branches/redesign/Source/File.py
branches/redesign/Source/Scanner.py
branches/redesign/Source/SourceBase.py
branches/redesign/Source/__init__.py
branches/redesign/gtkGUI/__init__.py
Modified: branches/redesign/PyCodeOCR.py
===================================================================
--- branches/redesign/PyCodeOCR.py 2014-08-26 13:07:59 UTC (rev 66)
+++ branches/redesign/PyCodeOCR.py 2014-08-26 18:12:03 UTC (rev 67)
@@ -52,10 +52,6 @@
class PyCodeOCR(object):
def __init__(self):
- srcs = Source.Sources()
- srcs.searchScanner()
- self.source = srcs.getSources()[0]
-
self.win = gtk.Window()
self.win.set_border_width(5)
self.win.set_title('PyCodeOCR')
@@ -76,6 +72,20 @@
vboxProperties = gtk.VBox()
hbox.add(vboxProperties)
+ sourceFrame = gtk.Frame("Source")
+ sourceVBox = gtk.VBox()
+ sourceFrame.add(sourceVBox)
+ self.sourceChooser = gtkGUI.Chooser(Source, ["SourceBase","ScannerData","StdScannerData"])
+ sourceVBox.pack_start(self.sourceChooser,False,False,0)
+ vboxProperties.pack_start(sourceFrame, True,True,0)
+
+ recognitionFrame = gtk.Frame("Recognition")
+ recognitionVBox = gtk.VBox()
+ recognitionFrame.add(recognitionVBox)
+ self.recognitionChooser = gtkGUI.Chooser(Recognition, ["ImageRecognition","ImageRecognitionBase","RecognitionData","RunRecognition"])
+ recognitionVBox.pack_start(self.recognitionChooser,False,False,0)
+ vboxProperties.pack_start(recognitionFrame, True,True,0)
+
button = gtk.Button("Scan")
button.connect("pressed",self.on_button_pressed)
vboxProperties.pack_end(button, False, False, 0)
@@ -95,21 +105,25 @@
def on_button_pressed(self, event):
- self.imageRecognition = Recognition.ESR()
+ # get image recognition and initialize
+ self.imageRecognition = self.recognitionChooser.getSelection()
+ option = self.recognitionChooser.getOption()
self.imageRecognition.setRotate([180])
+ # get source and initialize
+ self.source = self.sourceChooser.getSelection()
+ self.source.setAddress(self.source.scanners[0][0])
stdScannerData = Source.StdScannerData()
scannerData = stdScannerData.getStdScannerData("180 deg")
+ # run recognition
runRecognition = Recognition.RunRecognition(self.source, scannerData, self.imageRecognition)
runRecognition.connect("updateRecognition", self.onProgressUpdate)
runRecognition.connect("recognized", self.on_recognized)
t = threading.Thread(target=runRecognition)
t.start()
- #gtk.threads_enter()
- #self.imagePreview.setRecognitionData(esr.getRecognitionData())
- #gtk.threads_leave()
+
def on_recognized(self, runRecognition):
self.imagePreview.setRecognitionData(self.imageRecognition.getRecognitionData())
Modified: branches/redesign/Recognition/Barcode.py
===================================================================
--- branches/redesign/Recognition/Barcode.py 2014-08-26 13:07:59 UTC (rev 66)
+++ branches/redesign/Recognition/Barcode.py 2014-08-26 18:12:03 UTC (rev 67)
@@ -2,7 +2,7 @@
class Barcode(ImageRecognition.ImageRecognitionBase):
def __init__(self):
- super(Barcode,self).__init("Barcode")
+ super(Barcode,self).__init__("Barcode")
def verify(self):
data = self.content.getContent()
Modified: branches/redesign/Recognition/DTMX.py
===================================================================
--- branches/redesign/Recognition/DTMX.py 2014-08-26 13:07:59 UTC (rev 66)
+++ branches/redesign/Recognition/DTMX.py 2014-08-26 18:12:03 UTC (rev 67)
@@ -2,7 +2,7 @@
class DTMX(ImageRecognition.ImageRecognitionBase):
def __init__(self):
- super(DTMX,self).__init("DTMX")
+ super(DTMX,self).__init__("DTMX")
def verify(self):
pass
Modified: branches/redesign/Recognition/DataMatrix.py
===================================================================
--- branches/redesign/Recognition/DataMatrix.py 2014-08-26 13:07:59 UTC (rev 66)
+++ branches/redesign/Recognition/DataMatrix.py 2014-08-26 18:12:03 UTC (rev 67)
@@ -2,7 +2,7 @@
class DataMatrix(ImageRecognition.ImageRecognitionBase):
def __init__(self):
- super(DataMatrix,self).__init("DataMatrix")
+ super(DataMatrix,self).__init__("DataMatrix")
def verify(self):
return True
Modified: branches/redesign/Recognition/ESR.py
===================================================================
--- branches/redesign/Recognition/ESR.py 2014-08-26 13:07:59 UTC (rev 66)
+++ branches/redesign/Recognition/ESR.py 2014-08-26 18:12:03 UTC (rev 67)
@@ -21,7 +21,7 @@
from Recognition import ImageRecognition
import utils
-import re, os
+import re, os, gtk
## Extract information from ESR
class ESR(ImageRecognition.ImageRecognitionBase):
@@ -126,6 +126,9 @@
# return the data
return self.recognitionData.getContent()
+ def activated(self):
+ return ["0 deg", "90 deg", "180 deg", "270 deg"]
+
## Character correction after recogition (on basis that there should be numbers and few special chars).
#
# @test Add unittest to check correct operation of this important module/function.
Modified: branches/redesign/Recognition/ImageRecognition.py
===================================================================
--- branches/redesign/Recognition/ImageRecognition.py 2014-08-26 13:07:59 UTC (rev 66)
+++ branches/redesign/Recognition/ImageRecognition.py 2014-08-26 18:12:03 UTC (rev 67)
@@ -60,6 +60,9 @@
self.recognitionData = recognitionData
return self.recognitionData.getContent()
+ def activated(self):
+ print "is activated"
+
## get name
# @return name
def getName(self):
Modified: branches/redesign/Recognition/PDF417.py
===================================================================
--- branches/redesign/Recognition/PDF417.py 2014-08-26 13:07:59 UTC (rev 66)
+++ branches/redesign/Recognition/PDF417.py 2014-08-26 18:12:03 UTC (rev 67)
@@ -2,7 +2,7 @@
class PDF417(ImageRecognition.ImageRecognitionBase):
def __init__(self):
- super(PDF417,self).__init("PDF417")
+ super(PDF417,self).__init__("PDF417")
def verify(self):
return (True, "")
Modified: branches/redesign/Source/File.py
===================================================================
--- branches/redesign/Source/File.py 2014-08-26 13:07:59 UTC (rev 66)
+++ branches/redesign/Source/File.py 2014-08-26 18:12:03 UTC (rev 67)
@@ -23,8 +23,8 @@
from PIL import Image
class File(SourceBase):
- def __init__(self,address, name, typename):
- super(File,self).__init__(address, name, typename)
+ def __init__(self):
+ super(File,self).__init__()
## get a new image from file
# @return image
Modified: branches/redesign/Source/Scanner.py
===================================================================
--- branches/redesign/Source/Scanner.py 2014-08-26 13:07:59 UTC (rev 66)
+++ branches/redesign/Source/Scanner.py 2014-08-26 18:12:03 UTC (rev 67)
@@ -25,25 +25,32 @@
class Scanner(SourceBase):
## init
- def __init__(self, dev):
- super(Scanner,self).__init__(dev[0],dev[1],dev[3])
-
- # open scanner
- self.scanner=sane.open(self.address)
-
- # get parameters from scanner
- parameters = self.scanner.get_parameters()
- for i in range(len(parameters)):
- self.addParameter(str(i), parameters[i])
+ def __init__(self):
+ super(Scanner,self).__init__()
+ self.scanners = []
+ self.searchScanner()
+#
+# # open scanner
+# self.scanner = sane.open(self.address)
+#
+# # get parameters from scanner
+# parameters = self.scanner.get_parameters()
+# for i in range(len(parameters)):
+# self.addParameter(str(i), parameters[i])
+#
+# # get options from options
+# options = self.scanner.get_options()
+# for option in options:
+# self.addOption(option[1], option)
+#
+# # close scanner
+# self.scanner.close()
+
+
+ def searchScanner(self):
+ sane.init()
+ self.scanners = sane.get_devices()
- # get options from options
- options = self.scanner.get_options()
- for option in options:
- self.addOption(option[1], option)
-
- # close scanner
- self.scanner.close()
-
## get a new image from a sane device
# @param size and position of the image
# @return image
@@ -87,6 +94,12 @@
self.scanner.close()
return sys.exc_info()[1]
+
+ def activated(self):
+ scanner_names = []
+ for scanner in self.scanners:
+ scanner_names.append(scanner[1])
+ return scanner_names
##
Modified: branches/redesign/Source/SourceBase.py
===================================================================
--- branches/redesign/Source/SourceBase.py 2014-08-26 13:07:59 UTC (rev 66)
+++ branches/redesign/Source/SourceBase.py 2014-08-26 18:12:03 UTC (rev 67)
@@ -21,18 +21,47 @@
class SourceBase(object):
## init
- def __init__(self,address, name, typename):
- self.address = address
- self.name = name
- self.type = typename
+ def __init__(self):
+ self.address = ""
+ self.name = ""
+ self.type = ""
self.parameters = {}
self.options = {}
+ ## get a new image
+ # @param additional data required to get the image
+ # @return image
+ def getImage(self,data = None):
+ image = ""
+ return image
+
+ def activated(self):
+ print "is activated"
+
## return name of source
# @return name
def getName(self):
return self.name
+ def setName(self, name):
+ self.name = name
+
+ ## return address of source
+ # @return address
+ def getAddress(self):
+ return self.address
+
+ def setAddress(self, address):
+ self.address = address
+
+ ## return type of source
+ # @return type
+ def getType(self):
+ return self.type
+
+ def setType(self, typename):
+ self.type = typename
+
## set parameters for source
# @param parameters dictionary
# @post parameters set
@@ -79,16 +108,6 @@
def getOption(self, optionName):
return self.options[optionName]
- ## return address of source
- # @return address
- def getAddress(self):
- return self.address
-
- ## return type of source
- # @return type
- def getType(self):
- return self.type
-
## test if two sources are equal
# two sources are equal, if address, name and type are equal
# @param another source
@@ -102,13 +121,6 @@
return False
return True
- ## get a new image
- # @param additional data required to get the image
- # @return image
- def getImage(self,data = None):
- image = ""
- return image
-
## print some info to the source
#
def printInfo(self):
Modified: branches/redesign/Source/__init__.py
===================================================================
--- branches/redesign/Source/__init__.py 2014-08-26 13:07:59 UTC (rev 66)
+++ branches/redesign/Source/__init__.py 2014-08-26 18:12:03 UTC (rev 67)
@@ -3,4 +3,3 @@
from Source.Scanner import StdScannerData
from Source.SourceBase import SourceBase
from Source.File import File
-from Source.Sources import Sources
Modified: branches/redesign/gtkGUI/__init__.py
===================================================================
--- branches/redesign/gtkGUI/__init__.py 2014-08-26 13:07:59 UTC (rev 66)
+++ branches/redesign/gtkGUI/__init__.py 2014-08-26 18:12:03 UTC (rev 67)
@@ -1,3 +1,4 @@
from ImagePreview import ImagePreview
from ProgressBar import ProgressBar
+from Chooser import Chooser
import ScanProperties
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|