def findContrast(self, image): for i in xrange(10, 250, 10): img = contBright(image, i, i + 5.0) self.findMarket(img) if self.valid: self.contrast = i break
def __init__(self, image, contrast = None): #color = image image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) self.station_name = None self.market_table = None self.market_width = 0 self.valid = False self.areas = None self.contrast = None self.xline = None if contrast is None: for i in xrange(10, 250, 10): img = contBright(image, i, i+5.0) self.findMarket(img) if self.valid: self.contrast = i break else: img = contBright(image, contrast, contrast+5.0) self.findMarket(img)
def makeMarketImg(self, market): img = self.image[market[0][1]:market[1][1], market[0][0]:market[1][0]] img = contBright(img, self.contrast, self.contrast+5.0) #cv2.imshow("x", img) #cv2.waitKey(0) img = 255 - img try: h, w = img.shape if w == 0 or h == 0: img = np.ones((1,1), dtype='float32') except: img = np.ones((1,1), dtype='float32') return img
def makeMarketImg(self, market): img = self.image[market[0][1]:market[1][1], market[0][0]:market[1][0]] img = contBright(img, self.contrast, self.contrast + 5.0) #cv2.imshow("x", img) #cv2.waitKey(0) img = 255 - img try: h, w = img.shape if w == 0 or h == 0: img = np.ones((1, 1), dtype='float32') except: img = np.ones((1, 1), dtype='float32') return img
def getValidRange(self, image): min_valid = None max_valid = None for i in xrange(5, 250, 5): img = contBright(image, i, i + 5.0) self.findMarket(img) if min_valid is None: if self.valid: min_valid = i if not min_valid is None: if self.valid: max_valid = i return (min_valid, max_valid)
def getValidRange(self, image): min_valid = None max_valid = None for i in xrange(5, 250, 5): img = contBright(image, i, i+5.0) self.findMarket(img) if min_valid is None: if self.valid: min_valid = i if not min_valid is None: if self.valid: max_valid = i return (min_valid, max_valid)
def makeStationImg(self, station): img = self.image[station[0][1]:station[1][1], station[0][0]:station[1][0]] h, w = img.shape img = whiteBalance(img) #cv2.imshow("x", img) #cv2.waitKey(0) img = 255 - contBright(img, 250.0, 255.0) try: h, w = img.shape if w == 0 or h == 0: img = np.ones((1,1), dtype='float32') except: img = np.ones((1,1), dtype='float32') return img
def makeStationImg(self, station): img = self.image[station[0][1]:station[1][1], station[0][0]:station[1][0]] h, w = img.shape img = whiteBalance(img) #cv2.imshow("x", img) #cv2.waitKey(0) img = 255 - contBright(img, 250.0, 255.0) try: h, w = img.shape if w == 0 or h == 0: img = np.ones((1, 1), dtype='float32') except: img = np.ones((1, 1), dtype='float32') return img
def __init__(self, image, contrast=None): # color = image image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) self.station_name = None self.market_table = None self.market_width = 0 self.valid = False self.areas = None self.contrast = None self.xline = None if contrast is None: self.findContrast(image) else: img = contBright(image, contrast, contrast + 5.0) self.findMarket(img) if not self.valid: self.findContrast(image)
def __init__(self, image, contrast=None): #color = image image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) self.station_name = None self.market_table = None self.market_width = 0 self.valid = False self.areas = None self.contrast = None self.xline = None if contrast is None: self.findContrast(image) else: img = contBright(image, contrast, contrast + 5.0) self.findMarket(img) if not self.valid: self.findContrast(image)
def runTest(self, image, market, contrast): img = image[market[0][1]:market[1][1], market[0][0]:market[1][0]] img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) h, w = img.shape img = contBright(img, contrast, contrast + 5.0) img = 255 - img #cv2.imshow("x", img) #cv2.waitKey(0) mlp = MLP(img, self.settings, self.ocr_areas.areas, isstation=False, calibration=True) #print market.result #for result in market.result: # print result.name.value if self.language == "English": language = u"eng" elif self.language == "German": language = u"deu" else: language = u"fra" levels = { u"eng": [u'LOW', u'MED', u'HIGH'], u"deu": [u'NIEDRIG', u'MITTEL', u'HOCH'], u"fra": [u'FAIBLE', u'MOYEN', u'ÉLEVÉ'] } file = codecs.open( self.settings.app_path + os.sep + "commodities.json", 'r', "utf-8") comm_list = json.loads(file.read()) file.close() #print self.comm_list #self.comm_list.sort(key = len) if language == "big" or language == "eng": comm_list = [k for k, v in comm_list.iteritems()] else: comm_list = [v[language] for k, v in comm_list.iteritems()] total_error = 0 lines = 0 for result in mlp.result: #print result.name.value if (not result.name is None) and result.name.value != '': if result.name.x1 > h / 18: lines += 1 mindist = 100 topcomm = "" alternatives = [] for comm in comm_list: #print (result.name.value, unicode(comm)) dist = distance(result.name.value, unicode(comm)) #if dist < 7: # alternatives.append((unicode(comm), dist)) if dist < mindist: mindist = dist topcomm = comm if dist == 0: mindist = 0 #print result.name.value #print topcomm #print #if mindist > 0: # print (topcomm, result.name.value) for letter in topcomm: if letter in [u"Ä", u"Ö", u"Ü"]: mindist -= 1 total_error += mindist #print "contrast " + unicode(contrast) #print "lines " + unicode(lines) #print "error " +unicode(total_error) #print return [lines, total_error, contrast]
def runTest(self, image, market, contrast): img = image[market[0][1]:market[1][1], market[0][0]:market[1][0]] img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) h,w = img.shape img = contBright(img, contrast, contrast+5.0) img = 255 - img #cv2.imshow("x", img) #cv2.waitKey(0) mlp = MLP(img, self.settings.app_path, self.ocr_areas.areas, isstation=False, calibration=True) #print market.result #for result in market.result: # print result.name.value if self.language == "English": language = u"eng" elif self.language == "German": language = u"deu" else: language = u"fra" levels = {u"eng": [u'LOW', u'MED', u'HIGH'], u"deu": [u'NIEDRIG', u'MITTEL', u'HOCH'], u"fra": [u'FAIBLE', u'MOYEN', u'ÉLEVÉ']} file = codecs.open(self.settings.app_path + os.sep +"commodities.json", 'r', "utf-8") comm_list = json.loads(file.read()) file.close() #print self.comm_list #self.comm_list.sort(key = len) if language == "big" or language == "eng": comm_list = [k for k, v in comm_list.iteritems()] else: comm_list = [v[language] for k, v in comm_list.iteritems()] total_error = 0 lines = 0 for result in mlp.result: #print result.name.value if (not result.name is None) and result.name.value != '': if result.name.x1 > h/18: lines +=1 mindist = 100 topcomm = "" alternatives = [] for comm in comm_list: #print (result.name.value, unicode(comm)) dist = distance(result.name.value, unicode(comm)) #if dist < 7: # alternatives.append((unicode(comm), dist)) if dist < mindist: mindist = dist topcomm = comm if dist == 0: mindist = 0 #print result.name.value #print topcomm #print #if mindist > 0: # print (topcomm, result.name.value) for letter in topcomm: if letter in [u"Ä",u"Ö",u"Ü"]: mindist -= 1 total_error += mindist #print "contrast " + unicode(contrast) #print "lines " + unicode(lines) #print "error " +unicode(total_error) #print return [lines, total_error, contrast]
def makeStationImgClean(self, station): img = self.image[station[0][1]-2:station[1][1]+2, station[0][0]-2:station[1][0]+2] img = 255 - contBright(img, 100.0, 200.0) return img
def makeMarketImgClean(self, market): img = self.image[market[0][1]:market[1][1], market[0][0]:market[1][0]] img = 255 - contBright(img, self.contrast - 20.0, self.contrast + 20.0) return img
def makeStationImgClean(self, station): img = self.image[station[0][1] - 2:station[1][1] + 2, station[0][0] - 2:station[1][0] + 2] img = 255 - contBright(img, 100.0, 200.0) return img