本文整理汇总了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')
示例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()
示例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
示例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()
示例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)
示例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()