本文整理汇总了Python中common.Sketcher.show方法的典型用法代码示例。如果您正苦于以下问题:Python Sketcher.show方法的具体用法?Python Sketcher.show怎么用?Python Sketcher.show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common.Sketcher
的用法示例。
在下文中一共展示了Sketcher.show方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from common import Sketcher [as 别名]
# 或者: from common.Sketcher import show [as 别名]
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__
# 需要导入模块: from common import Sketcher [as 别名]
# 或者: from common.Sketcher import show [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"
示例3: __init__
# 需要导入模块: from common import Sketcher [as 别名]
# 或者: from common.Sketcher import show [as 别名]
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()
示例4: __init__
# 需要导入模块: from common import Sketcher [as 别名]
# 或者: from common.Sketcher import show [as 别名]
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: print
# 需要导入模块: from common import Sketcher [as 别名]
# 或者: from common.Sketcher import show [as 别名]
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()
示例6: __init__
# 需要导入模块: from common import Sketcher [as 别名]
# 或者: from common.Sketcher import show [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