本文整理汇总了Python中analyzer.Analyzer.set_callibration方法的典型用法代码示例。如果您正苦于以下问题:Python Analyzer.set_callibration方法的具体用法?Python Analyzer.set_callibration怎么用?Python Analyzer.set_callibration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类analyzer.Analyzer
的用法示例。
在下文中一共展示了Analyzer.set_callibration方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from analyzer import Analyzer [as 别名]
# 或者: from analyzer.Analyzer import set_callibration [as 别名]
class CameraProcessor:
def __init__(self, camera, gui):
self.analyzer = Analyzer(gui)
self.cap = cv2.VideoCapture(camera)
self.callibration_state = 0
self.callibration_message = [
"Please click the plus sign with the circle around it",
"Please click the plus sign WITHOUT the circle around it",
"Got it!"
]
self.create_images_dir()
self.gui = gui
gui.subscribe('color_threshold', self)
gui.subscribe('blob_threshold', self)
gui.subscribe('area_threshold', self)
def create_images_dir(self):
try:
os.mkdir("images")
except:
pass
def handle_callibration_click(self, event,x,y,flags,param):
if event == 1:
self.analyzer.set_callibration(self.callibration_state, (x,y))
print("Setting callibration point %d to (%d, %d)" % (self.callibration_state, x, y))
self.callibration_state += 1
print(self.callibration_message[self.callibration_state])
def callibrate(self):
cv2.namedWindow('callibration')
cv2.setMouseCallback('callibration',self.handle_callibration_click)
print(self.callibration_message[self.callibration_state])
while self.callibration_state < 2:
ret, frame = self.cap.read()
resized = cv2.resize(frame, (800,600))
cv2.imshow( "callibration" ,resized)
cv2.waitKey(1)
cv2.destroyWindow("callibration")
def detected_dice(self):
if len(self.analyzer.detected_dice) == 0: return None
return self.analyzer.detected_dice[0]
def save_frame(self):
filename = "images/%s.jpg" % str(uuid.uuid4())
ret, frame = self.cap.read()
print("Writing %s" % filename)
cv2.imwrite(filename, frame)
def process(self):
ret, frame = self.cap.read()
self.process_image(frame)
def process_image(self, frame):
resized = cv2.resize(frame, (800,600))
self.analyzer.analyze(resized, frame)
def set_parameter(self, name, value):
if name == 'color_threshold':
self.analyzer.color_threshold = value
elif name == 'blob_threshold':
self.analyzer.blob_threshold = value
elif name == 'area_threshold':
self.analyzer.set_area_threshold(value * 100)
def report_blobs(self):
self.analyzer.report()
def teardown(self):
self.cap.release()
def run_test(self):
while True:
self.process()
key = cv2.waitKey(1)
if key & 0xFF == ord('q'):
break
if key & 0xFF == ord('r'):
self.report_blobs()
if key & 0xFF == ord('s'):
self.save_frame()
self.teardown()