def _initme(self, userdata=None): #the main classes self.m = Model(self) self.capture = Capture(self) self.ui = UI(self) return False
def __init__(self, world, filename=None, simulator=None, once=False, headless=False): logging.info('Initialising vision') if simulator: self.capture = SimCapture(simulator) else: self.capture = Capture(self.rawSize, filename, once) self.headless = headless self.threshold = threshold.AltRaw() self.pre = Preprocessor(self.rawSize, self.threshold, simulator) self.featureEx = FeatureExtraction(self.pre.cropSize) self.interpreter = Interpreter() self.world = world self.gui = GUI(world, self.pre.cropSize, self.threshold) self.histogram = Histogram(self.pre.cropSize) self.times = [] self.N = 0 #debug.thresholdValues(self.threshold.Tblue, self.gui) logging.debug('Vision initialised')
def setEmotion(self,emotion): self.emotion = emotion self.frameArea.focus_set() if not self.captureStarted: self.captureStarted = True self.cap = Capture(self.frameArea,self.clf) self.cap.capture(self.emotion)
def test_print_if(): class Print_If(Cell): def __init__(self): super().__init__() self.print = P.Print() def construct(self, x, y): self.print("input_x before:", x, "input_y before:", y) if x < y: self.print("input_x after:", x, "input_y after:", y) x = x + 1 return x cap = Capture() with capture(cap): input_x = Tensor(3, dtype=ms.int32) input_y = Tensor(4, dtype=ms.int32) expect = Tensor(4, dtype=ms.int32) net = Print_If() out = net(input_x, input_y) time.sleep(0.1) np.testing.assert_array_equal(out.asnumpy(), expect.asnumpy()) patterns = { 'input_x before:\nTensor(shape=[], dtype=Int32, value=3)\n' 'input_y before:\nTensor(shape=[], dtype=Int32, value=4)', 'input_x after:\nTensor(shape=[], dtype=Int32, value=3)\n' 'input_y after:\nTensor(shape=[], dtype=Int32, value=4)' } check_output(cap.output, patterns)
def test_print_assign_add(): class Print_Assign_Add(Cell): def __init__(self): super().__init__() self.print = P.Print() self.add = P.Add() self.para = Parameter(Tensor(1, dtype=ms.int32), name='para') def construct(self, x, y): self.print("before:", self.para) self.para = x self.print("after:", self.para) x = self.add(self.para, y) return x cap = Capture() with capture(cap): input_x = Tensor(3, dtype=ms.int32) input_y = Tensor(4, dtype=ms.int32) expect = Tensor(7, dtype=ms.int32) net = Print_Assign_Add() out = net(input_x, input_y) time.sleep(0.1) np.testing.assert_array_equal(out.asnumpy(), expect.asnumpy()) patterns = { 'before:\nTensor(shape=[], dtype=Int32, value=1)', 'after:\nTensor(shape=[], dtype=Int32, value=3)' } check_output(cap.output, patterns)
def test_print_for(): class Print_For(Cell): def __init__(self): super().__init__() self.print = P.Print() def construct(self, x, y): y = x + y self.print("input_x before:", x, "input_y before:", y) for _ in range(3): y = y + 1 self.print("input_x after:", x, "input_y after:", y) return y cap = Capture() with capture(cap): input_x = Tensor(2, dtype=ms.int32) input_y = Tensor(4, dtype=ms.int32) expect = Tensor(9, dtype=ms.int32) net = Print_For() out = net(input_x, input_y) time.sleep(0.1) np.testing.assert_array_equal(out.asnumpy(), expect.asnumpy()) patterns = { 'input_x before:\nTensor(shape=[], dtype=Int32, value=2)\n' 'input_y before:\nTensor(shape=[], dtype=Int32, value=6)', 'input_x after:\nTensor(shape=[], dtype=Int32, value=2)\n' 'input_y after:\nTensor(shape=[], dtype=Int32, value=7)', 'input_x after:\nTensor(shape=[], dtype=Int32, value=2)\n' 'input_y after:\nTensor(shape=[], dtype=Int32, value=8)', 'input_x after:\nTensor(shape=[], dtype=Int32, value=2)\n' 'input_y after:\nTensor(shape=[], dtype=Int32, value=9)' } check_output(cap.output, patterns)
def test_print_add(): class Print_Add(Cell): def __init__(self): super().__init__() self.print = P.Print() self.add = P.Add() def construct(self, x, y): x = self.add(x, y) self.print("input_x:", x, "input_y:", y) return x cap = Capture() with capture(cap): input_x = Tensor(3, dtype=ms.int32) input_y = Tensor(4, dtype=ms.int32) expect = Tensor(7, dtype=ms.int32) net = Print_Add() out = net(input_x, input_y) time.sleep(0.1) np.testing.assert_array_equal(out.asnumpy(), expect.asnumpy()) patterns = { 'input_x:\nTensor(shape=[], dtype=Int32, value=7)\n' 'input_y:\nTensor(shape=[], dtype=Int32, value=4)' } check_output(cap.output, patterns)
def __init__(self): self.logger = logger self.sqlite = Sqlite() self.cap = Capture() self.report_available_yuming = [] self.logger.debug('init over')
def __init__(self): # get the logger self.logger = logger self.logger.debug("logger test ok") # init sqlite self.sqlite = sqlite self.cap = Capture() self.logger.debug("init over")
async def init_app(): loop = asyncio.get_event_loop() app = web.Application(loop=loop) capture = Capture() app['capture'] = capture app['loop'] = loop app.on_shutdown.append(on_shutdown) app.router.add_post('/capture', handle) return app
def __init__(self): self.names = utils.get_names() self.actions = {j:i for i,j in self.names.items()} # special case for stopping the car when a stop or red light signal is detected self.actions[-1] = 'stop' # parts self.sender = Sender() self.decisor = Decisor() self.capture = Capture()
def __init__(self, window, class_file, running_mode): self.classes = classes_from_file(class_file) self.window_x = window[0] self.window_y = window[1] self.window_width = window[2] self.window_height = window[3] self.capture = Capture(self.window_x, self.window_y, self.window_width, self.window_height) self.fast_rcnn = self.build_faster_rcnn_session()
def started_feed(message): print(message) re_initialise() sockets[request.sid].capture = Capture(Check_Mask()) currentSocketId = request.sid folder = os.path.join(os.getcwd(), "static") sockets[request.sid].dirpath = os.path.join(folder, currentSocketId) if not os.path.isdir(sockets[request.sid].dirpath): os.mkdir(sockets[request.sid].dirpath)
def __init__(self): # get the logger self.logger = Logger(log_path=Config.logdir + '/Report.log', log_level='debug', log_name='Report') self.logger.debug("logger test ok") # init sqlite self.sqlite = Sqlite() self.cap = Capture() self.logger.debug("init over")
def __init__(self, parent = None): super().__init__(parent) self.setGeometry(100, 100, 600, 600) # 起始位置,宽高 self.setWindowTitle("VideoStreamApp") # 设置标题 #self.setWindowIcon(QtGui.QIcon('opencvlogo.png')) self.capture = Capture() # 设置摄像头组件 self.video_widget = VideoWidget() # 设置视频组件 image_window = self.video_widget.image_window # 获取播放器组件的播放窗口 self.capture.image_data.connect(image_window) # 将系统消息绑定到播放器窗口 self.add_buttons() # 窗口初始化时设置按钮 self.set_layout() # 窗口初始化时设置布局
def send_captured_data(ws): capture = Capture(sys.argv[1], dataSize=480, isInvert=True) capture.run() # 初期値を設定 max_distance = 0 max_intensity = 0 max_elapsed_time = 0 sequence_id = 0 preTime = time.time() while True: if capture.dataObtained: # 排他制御開始 capture.lock.acquire() # データを取得 theta = list(capture.theta) distance = list(capture.distance) intensity = list(capture.intensity) # データを取得したのでデータ取得フラグを下ろす capture.dataObtained = False # 排他制御終了 capture.lock.release() # 現在設定されている最大値を取得 max_distance = max([max_distance] + distance) max_intensity = max([max_intensity] + intensity) # 送信するデータを作成 payload = json.dumps( dict(header=dict(cmd="relay"), contents=dict(sequenceId=sequence_id, theta=theta, distance=distance, intensity=intensity, maxDistance=max_distance, maxIntensity=max_intensity))) ws.send(payload) # データを送信 elapsedTime = time.time() - preTime preTime = time.time() if max_elapsed_time < elapsedTime: max_elapsed_time = elapsedTime print( "[Log] Sequence ID: %d, Elapsed time: %f, Max elapsed time: %f" % (sequence_id, elapsedTime, max_elapsed_time)) sequence_id += 1 else: time.sleep(0.01)
def eval_fc(fname_pickle, model_path): cam_props, recordings = pickle.load(open(fname_pickle, 'rb')) speeds = np.zeros(len(recordings)) hits = np.zeros(len(recordings)) extras = np.zeros(len(recordings)) fname_avi = os.path.splitext(fname_pickle)[0] + '.avi' model = keras.models.load_model(model_path) cap = Capture(fname_avi, CapType.VIDEO) ret, first_frame = cap.read() cnn_input = CnnInput(first_frame) run_processor = RunProcessor(cnn_input) sticky_tolerance = StickyTolerance() action = None frame_num = 0 rec_i = 1 while cap.is_opened(): ret, frame = cap.read() if not ret: break if cam_props.side == CamSide.LEFT: frame = cv2.flip(frame, 1) cnn_input.update(frame) cnn_input_4d = np.expand_dims(cnn_input.frame, 0) prediction = model.predict(cnn_input_4d)[0] class_id = np.argmax(prediction) class_label = dataset.id_to_gesture[class_id] class_label, direction = run_processor.process(class_label) action = sticky_tolerance.process(class_label, prediction[class_id], action) if direction is not None and action in ['walk', 'run']: action = action + direction if recordings[rec_i].label in ['jumpb', 'jumps']: recordings[rec_i].label = 'jump' target = recordings[rec_i].label if action == target and hits[rec_i] == 0: hits[rec_i] = 1 speeds[rec_i] = frame_num - recordings[rec_i].frame frame_num += 1 if rec_i + 1 < len(recordings) and frame_num >= recordings[rec_i + 1].frame: if hits[rec_i] == 0: speeds[rec_i] = frame_num - recordings[rec_i].frame rec_i += 1 return recordings, hits, speeds, extras
def main(): cap = Capture('./capture') # load net #net = caffe.Net('voc-fcn8s/deploy.prototxt', 'voc-fcn8s/fcn8s-heavy-pascal.caffemodel', caffe.TEST) net = caffe.Net('voc-fcn-alexnet/deploy.prototxt', 'voc-fcn-alexnet/train_iter_16000.caffemodel', caffe.TEST) for i in xrange(500): imgfile = cap.capture() run(net, imgfile, 'out/', '%d.jpg' % i)
def test_localize_map_all(): #use map of the buildings for localization building_filename = os.path.join(root, 'flash', 'fft2', 'export', 'frames', 'DefineSprite_551', '1.png') mapper = LocalizeMap(building_filename) filename = os.path.join(root, 'flash', 'fft2', 'processed', 'level1_start.png') c = Capture(filename) while True: template = c.snap_gray() print mapper.localize_all(template)
def __init__(self): self.model_name = "models/30epoch_depthrgb.hdf5" self.throttle = 0.0 self.image_size = 250 self.throttle = 0.0 self.steering = 0.0 self.comms = CommServerS() self.capture = Capture(self.model_name) print("[INFO] AI Neural Net is firing!")
def test_localization(): filename = os.path.join(root, 'flash', 'fft2', 'processed', 'level1_start.png') c = Capture(filename) template = c.snap_gray() w, h = template.shape[::-1] res = cv2.matchTemplate(img, template, cv2.TM_CCOEFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) print (max_loc[0], max_loc[1], max_loc[0] + w, max_loc[1] + h) return (max_loc[0], max_loc[1], max_loc[0] + w, max_loc[1] + h)
def main(): capture = Capture(schema='camara_v1') # capture data with this capture.capture_data( url= 'http://www.camara.leg.br/SitCamaraWS/Deputados.asmx/ObterPartidosCD') data_list = capture.data['partidos']['partido'] data_list = capture.to_default_dict(data_list) data_list = from_api_to_db_deputados(data_list, capture.url) capture.insert_data(data_list, table_name='partidos', if_exists='pass', key='id_partido')
def main(): capture = Capture(schema='camara_v2') # capture data with this base_url = 'https://dadosabertos.camara.leg.br/api/v2/proposicoes/{}/tramitacoes' urls = urls_generator(capture, base_url) for url, id_proposicao in urls: print(url) capture.capture_data(url, content_type='json') data_list = capture.data['dados'] data_list = capture.to_default_dict(data_list) data_list = from_api_to_db(data_list, url, id_proposicao) capture.insert_data(data_list, table_name='tramitacao')
def main(): capture = Capture(schema='camara_v1', ) base_url = 'http://www.camara.leg.br/SitCamaraWS/Proposicoes.asmx/ObterVotacaoProposicao?tipo={tipo}&numero={numero}&ano={ano}' url_and_ids, numero_captura = urls_generator(capture, base_url) for url, id_proposicao in url_and_ids: print('----') print(url) # capture data with this try: capture.capture_data(url) data_proposicao = capture.data['proposicao'] data_generic = data_proposicao['Votacoes']['Votacao'] for data_votacao in force_list(data_generic): # orientacao try: print() print('orientacao') data_list = data_votacao['orientacaoBancada']['bancada'] data_list = capture.to_default_dict(data_list) data_list = from_api_to_db_votacao_orientacao( data_list, url, data_proposicao, data_votacao, id_proposicao, numero_captura) capture.insert_data( data_list, table_name='votacao_proposicao_orientacao') except KeyError: pass # deputados print() print('deputados') data_list = data_votacao['votos']['Deputado'] data_list = capture.to_default_dict(data_list) data_list = from_api_to_db_votacao_deputado( data_list, url, data_proposicao, data_votacao, id_proposicao) capture.insert_data(data_list, table_name='votacao_proposicao') except: continue
def __init__(self, world, filenames=None, simulator=None, once=False, headless=False): logging.info('Initialising vision') self.headless = headless self.capture = Capture(self.rawSize, filenames, once) self.threshold = threshold.AltRaw() self.threshold = threshold.PrimaryRaw() self.world = world self.simulator = simulator self.initComponents() self.times = [] self.N = 0 logging.debug('Vision initialised')
def main(): capture = Capture(schema='camara_v1', ) capture_number = get_capture_number(capture) print('Numero Captura', capture_number) capture.capture_data( url='http://www.camara.leg.br/SitCamaraWS/Deputados.asmx/ObterDeputados' ) data_list = capture.data['deputados']['deputado'] data_list = capture.to_default_dict(data_list) data_list = from_api_to_db_deputados(data_list, capture.url, capture_number) capture.insert_data(data_list, table_name='deputados', if_exists='pass', key='ide_cadastro')
def __init__(self, connec, *args, **kwargs): self.connec = connec #C:\local_tools\experimental\pyfire\flash\fft2\export\frames\DefineSprite_772_fla.maps.Map_02 #building_filename = os.path.join(root, 'flash', 'fft2', 'export', 'frames', # 'DefineSprite_551', '1.png') #map_filename = os.path.join(root, 'flash', 'fft2', 'export', 'frames', # 'DefineSprite_772_fla.maps.Map_02', '1.png') map_filename = os.path.join(root, 'flash', 'fft2', 'processed', 'aligned_localization_data_map.png') self.mapper = LocalizeMap(map_filename) filename = os.path.join(root, 'flash', 'fft2', 'processed', 'level1_start.png') self.c = Capture(filename) Process.__init__(self, *args, **kwargs)
def __init__(self): super(Meeting, self).__init__() self.ui = Ui_MainWindow() self.resize(490, 326) #self.setFixedSize(self.width(), self.height()) self.capture = Capture() # 设置摄像头组件 self.video_widget = VideoWidget() # 设置视频组件 # image_window = self.video_widget.image_window # 获取播放器组件的播放窗口 # self.capture.image_data.connect(image_window) # 播放器线程, 接收到摄像头数据时执行,在该函数中执行人脸检测及识别 self.capture.image_data.connect( self.face_recognition) # 播放器线程, 接收到摄像头数据时执行,在该函数中执行人脸检测及识别 self.ui.setupUi(self) self.setCapture() self.setButtom() self.meeting_id = None #self.sensor = MLX90614() self.tem = 36.9 self.fps = self.capture.get()
def test_print_assign_while(): class Print_Assign_While(Cell): def __init__(self): super().__init__() self.print = P.Print() self.para = Parameter(Tensor(0, dtype=ms.int32), name='para') def construct(self, x, y): self.print("input_x before:", x, "input_y before:", y, "para before:", self.para) while x < y: self.para = x x = self.para + 1 self.print("input_x after:", x, "input_y after:", y, "para after:", self.para) return x cap = Capture() with capture(cap): input_x = Tensor(1, dtype=ms.int32) input_y = Tensor(4, dtype=ms.int32) expect = Tensor(4, dtype=ms.int32) net = Print_Assign_While() out = net(input_x, input_y) time.sleep(0.1) np.testing.assert_array_equal(out.asnumpy(), expect.asnumpy()) patterns = { 'input_x before:\nTensor(shape=[], dtype=Int32, value=1)\n' 'input_y before:\nTensor(shape=[], dtype=Int32, value=4)\n' 'para before:\nTensor(shape=[], dtype=Int32, value=0)', 'input_x after:\nTensor(shape=[], dtype=Int32, value=2)\n' 'input_y after:\nTensor(shape=[], dtype=Int32, value=4)\n' 'para after:\nTensor(shape=[], dtype=Int32, value=1)', 'input_x after:\nTensor(shape=[], dtype=Int32, value=3)\n' 'input_y after:\nTensor(shape=[], dtype=Int32, value=4)\n' 'para after:\nTensor(shape=[], dtype=Int32, value=2)', 'input_x after:\nTensor(shape=[], dtype=Int32, value=4)\n' 'input_y after:\nTensor(shape=[], dtype=Int32, value=4)\n' 'para after:\nTensor(shape=[], dtype=Int32, value=3)' } check_output(cap.output, patterns)
def main(): capture = Capture(schema='camara_v1', ) # capture data with this capture.capture_data( url='http://www.camara.leg.br/SitCamaraWS/Deputados.asmx/ObterDeputados' ) # get the list of dict for this table data_list = capture.data['deputados']['deputado'] # data_list = capture.to_default_dict(data_list) # make it rigth data_list = from_api_to_db_deputados(data_list, capture.url) # insert it! capture.insert_data(data_list, table='deputados')