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


Python common.Sketcher类代码示例

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


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

示例1: main

def main():
    import sys
    try:
        fn = sys.argv[1]
    except:
        fn = 'fruits.jpg'

    img = cv.imread(cv.samples.findFile(fn))
    if img is None:
        print('Failed to load image file:', fn)
        sys.exit(1)

    img_mark = img.copy()
    mark = np.zeros(img.shape[:2], np.uint8)
    sketch = Sketcher('img', [img_mark, mark], lambda : ((255, 255, 255), 255))

    while True:
        ch = cv.waitKey()
        if ch == 27:
            break
        if ch == ord(' '):
            res = cv.inpaint(img_mark, mark, 3, cv.INPAINT_TELEA)
            cv.imshow('inpaint', res)
        if ch == ord('r'):
            img_mark[:] = img
            mark[:] = 0
            sketch.show()

    print('Done')
开发者ID:adamrankin,项目名称:opencv,代码行数:29,代码来源:inpaint.py

示例2: __init__

class App:
    def __init__(self, fn):
        self.img = cv2.imread(fn)
        if self.img is None:
            raise Exception('Failed to load image file: %s' % fn)

        h, w = self.img.shape[:2]
        self.markers = np.zeros((h, w), np.int32)
        self.markers_vis = self.img.copy()
        self.cur_marker = 1
        self.colors = np.int32( list(np.ndindex(2, 2, 2)) ) * 255

        self.auto_update = True
        self.sketch = Sketcher('img', [self.markers_vis, self.markers], self.get_colors)

    def get_colors(self):
        return list(map(int, self.colors[self.cur_marker])), self.cur_marker

    def watershed(self):
        m = self.markers.copy()
        cv2.watershed(self.img, m)
        overlay = self.colors[np.maximum(m, 0)]
        vis = cv2.addWeighted(self.img, 0.5, overlay, 0.5, 0.0, dtype=cv2.CV_8UC3)
        cv2.imshow('watershed', vis)

    def run(self):
        while True:
            ch = 0xFF & cv2.waitKey(50)
            if ch == 27:
                break
            if ch >= ord('1') and ch <= ord('7'):
                self.cur_marker = ch - ord('0')
                print('marker: ', self.cur_marker)
            if ch == ord(' ') or (self.sketch.dirty and self.auto_update):
                self.watershed()
                self.sketch.dirty = False
            if ch in [ord('a'), ord('A')]:
                self.auto_update = not self.auto_update
                print('auto_update if', ['off', 'on'][self.auto_update])
            if ch in [ord('r'), ord('R')]:
                self.markers[:] = 0
                self.markers_vis[:] = self.img
                self.sketch.show()
        cv2.destroyAllWindows()
开发者ID:12rohanb,项目名称:opencv,代码行数:44,代码来源:watershed.py

示例3: __init__

 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
开发者ID:xsyann,项目名称:ocr,代码行数:10,代码来源:creator.py

示例4: __init__

class App:
    def __init__(self, fn):
        self.img = cv2.imread(fn)
        h, w = self.img.shape[:2]
        self.markers = np.zeros((h, w), np.int32)
        self.markers_vis = self.img.copy()
        self.cur_marker = 1
        self.colors = np.int32(list(np.ndindex(2, 2, 2))) * 255

        self.auto_update = True
        self.sketch = Sketcher("img", [self.markers_vis, self.markers], self.get_colors)

    def get_colors(self):
        return map(int, self.colors[self.cur_marker]), self.cur_marker

    def watershed(self):
        m = self.markers.copy()
        cv2.watershed(self.img, m)
        overlay = self.colors[np.maximum(m, 0)]
        vis = cv2.addWeighted(self.img, 0.5, overlay, 0.5, 0.0, dtype=cv2.CV_8UC3)
        cv2.imshow("watershed", vis)

    def run(self):
        while True:
            ch = 0xFF & cv2.waitKey(50)
            if ch == 27:
                break
            if ch >= ord("1") and ch <= ord("7"):
                self.cur_marker = ch - ord("0")
                print "marker: ", self.cur_marker
            if ch == ord(" ") or (self.sketch.dirty and self.auto_update):
                self.watershed()
                self.sketch.dirty = False
            if ch in [ord("a"), ord("A")]:
                self.auto_update = not self.auto_update
                print "auto_update if", ["off", "on"][self.auto_update]
            if ch in [ord("r"), ord("R")]:
                self.markers[:] = 0
                self.markers_vis[:] = self.img
                self.sketch.show()
        cv2.destroyAllWindows()
开发者ID:jepierre,项目名称:opencv,代码行数:41,代码来源:watershed.py

示例5: __init__

 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)
开发者ID:xsyann,项目名称:ocr,代码行数:23,代码来源:test.py

示例6: print

if __name__ == '__main__':
    import sys
    try:
        fn = sys.argv[1]
    except:
        fn = '../data/fruits.jpg'

    print(__doc__)

    img = cv2.imread(fn)
    if img is None:
        print('Failed to load image file:', fn)
        sys.exit(1)

    img_mark = img.copy()
    mark = np.zeros(img.shape[:2], np.uint8)
    sketch = Sketcher('img', [img_mark, mark], lambda : ((255, 255, 255), 255))

    while True:
        ch = 0xFF & cv2.waitKey()
        if ch == 27:
            break
        if ch == ord(' '):
            res = cv2.inpaint(img_mark, mark, 3, cv2.INPAINT_TELEA)
            cv2.imshow('inpaint', res)
        if ch == ord('r'):
            img_mark[:] = img
            mark[:] = 0
            sketch.show()
    cv2.destroyAllWindows()
开发者ID:12rohanb,项目名称:opencv,代码行数:30,代码来源:inpaint.py


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