当前位置: 首页>>代码示例>>Python>>正文


Python Sketcher.reset方法代码示例

本文整理汇总了Python中common.Sketcher.reset方法的典型用法代码示例。如果您正苦于以下问题:Python Sketcher.reset方法的具体用法?Python Sketcher.reset怎么用?Python Sketcher.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common.Sketcher的用法示例。


在下文中一共展示了Sketcher.reset方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from common import Sketcher [as 别名]
# 或者: from common.Sketcher import reset [as 别名]
class DatasetCreator:

    ESC = 27
    DEL = 127
    RET = 13
    KEY_UP = 0
    KEY_DOWN = 1
    EXT = ".bmp"
    FINAL_SIZE = 50

    def __init__(self, prefix, dryRun):
        h, w = 300, 300
        img = np.zeros((h, w, 3), np.uint8)
        img[:,:] = (255, 255, 255)
        self.brush = Brush("Brush")
        self.sketcher = Sketcher("Dataset Creator", img, self.brush)
        self.__folders = OCR.generateFolderList(OCR.DIGITS | OCR.LETTERS | OCR.SYMBOLS)
        self.__prefix = prefix
        self.__lastFile = None
        self.__dryRun = dryRun

    def run(self):
        while True:
            k = cv2.waitKey(0) & 0xFF

            if k == self.ESC:
                break
            elif k == self.RET:
                self.sketcher.reset()
                self.sketcher.show()
            elif k == self.KEY_UP:
                self.brush.brushSize += 1
            elif k == self.KEY_DOWN:
                self.brush.brushSize -= 1
            elif k == self.DEL and not self.__dryRun:
                if self.__lastFile:
                    os.remove(self.__lastFile)
                    self.__lastFile = None
                    print path + " Removed"
            elif chr(k) in self.__folders:
                folder = self.__folders[chr(k)]
                path = common.generateFilename(folder, self.__prefix, self.EXT)
                item = self.sketcher.sketch.copy()
                item = cv2.resize(item, (self.FINAL_SIZE, self.FINAL_SIZE))
                cv2.imshow("Generated Dataset item", item)
                self.sketcher.reset()
                self.__lastFile = path
                if not self.__dryRun:
                    cv2.imwrite(path, item)
                    print path + " Written"
                else:
                    print path + " Preview"
开发者ID:xsyann,项目名称:ocr,代码行数:54,代码来源:creator.py

示例2: __init__

# 需要导入模块: from common import Sketcher [as 别名]
# 或者: from common.Sketcher import reset [as 别名]
class TestOCR:

    ESC = 27
    KEY_UP = 0
    KEY_DOWN = 1

    def __init__(self, model, filenames, flags, pattern):
        self.ocr = OCR()
        self.ocr.loadModel(model, OCR.MODEL_ANN, flags)
        if filenames:
            counter = {}
            for filename in filenames:
                ch = self.ocr.charFromFile(filename)
                if pattern:
                    label = self.__exec(pattern, filename)
                    if label in counter:
                        predicted, total = counter[label]
                        counter[label] = (predicted + int(label == ch), total + 1)
                    else:
                        counter[label] = (int(label == ch), 1)
                print "%s in %s" % (ch, filename)
            if pattern:
                self.__analyze(counter)
        else:
            h, w = 200, 200
            img = np.zeros((h, w, 3), np.uint8)
            img[:,:] = (255, 255, 255)
            self.brush = Brush("Brush")
            self.sketcher = Sketcher('Test OCR', img, self.brush)

    def __analyze(self, counter):
        print ""
        totalPercent = []
        for label, (predicted, total) in sorted(counter.iteritems()):
            percent = int(float(predicted) / total * 100)
            totalPercent.append(percent)
            print "{0}\t{1} / {2} - {3} %".format(label, predicted, total, percent)
        print "\nTotal recognized : {0:.1f} %\n".format(np.mean(totalPercent))

    def __exec(self, file, arg):
        out = subprocess.Popen([file, arg], stdout=subprocess.PIPE).communicate()[0]
        return out

    def __displayResponse(self, ch):
        response = np.zeros((75, 75, 3), np.uint8)
        response[:,:] = (255, 255, 255)
        cv2.putText(response, ch, (15, 35), cv2.FONT_HERSHEY_PLAIN, 3.0, (0, 0, 0), 1)
        cv2.imshow("Response", response)

    def run(self):
        while True:
            k = cv2.waitKey(0) & 0xFF
            if k == self.ESC:
                break
            elif k == ord('r'):
                self.sketcher.reset()
                self.sketcher.show()
            elif k == ord(' '):
                ch = self.ocr.charFromImage(self.sketcher.sketch)
                self.sketcher.show()
                self.sketcher.reset()
                self.__displayResponse(ch)
                print "OCR : %s" % ch
            elif k == self.KEY_UP:
                self.brush.brushSize += 1
            elif k == self.KEY_DOWN:
                self.brush.brushSize -= 1
开发者ID:xsyann,项目名称:ocr,代码行数:69,代码来源:test.py


注:本文中的common.Sketcher.reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。