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)
class AIDrive: """ A class to interface with the Neural Net which captures data from the ZED STEREO VISION camera and then calls the SocketServer for sending that information to the VESC. """ 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 run(self): # get image from camera img = self.capture.capture_image(self.image_size) # get steering value from the NN self.steering = self.capture.evaluate_one(img) # send values over UDP socket. self.comms.send(self.throttle, self.steering) def generate(self): while (1): self.run()
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')
class Detect(): def __init__(self): self.capture = Capture(source) self.analyzer = Analyzer() def main(self): global flag global xx if self.analyzer.face and xx: self.analyzer.face = False xx = 0 self.analyzer.find = not self.analyzer.find frame = self.capture.capture_frame() self.analyzer.incoming_frame = frame self.analyzer.analyze() out_frame = self.analyzer.outgoing_frame cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN) cv2.setWindowProperty( "window", cv2.WND_PROP_FULLSCREEN, cv2.cv.CV_WINDOW_FULLSCREEN ) cv2.imshow("window", out_frame) c = cv2.waitKey(10) & 255 if c == 27: self.capture.shutdown() if self.analyzer.cnt == 31: flag = False self.capture.shutdown() # print self.analyzer.avg_bpm # print self.analyzer.breathes # return beats per minute and breath rate per minute return self.analyzer.avg_bpm, self.analyzer.breathes
def _initme(self, userdata=None): #the main classes self.m = Model(self) self.capture = Capture(self) self.ui = UI(self) return False
class Skandal(): '''Change config, capture, process.''' def __init__(self): self.cf = load_config("./scan.ini") self.cap = Capture(self.cf) self.proc = Process(self.cf) def change_config(self): pass def set_cam_position(self): self.cap.set_cam_position() def shot(self): self.cap.shot() def process_images(self): self.proc.get_laser_line() def process_PLY(self): self.proc.get_PLY() def scan(self): self.shot() self.process_images() self.process_PLY()
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")
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 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 __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 __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_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 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 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_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)
class LocalizeStreamProcess(Process): 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 run(self): prev_pos = None while True: start_time = time.time() time.sleep(0.01) template = self.c.snap_gray() pos = self.mapper.localize(template, prev_pos) prev_pos = pos time_pos = (time.time(), pos) self.connec.send(time_pos) end_time = time.time() fps = 1/(end_time-start_time) print "%2d frames per sec\r" % fps,
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_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 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
class Vision(): rawSize = (640, 480) 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 initComponents(self, crop=None): undistort = False self.pre = Preprocessor(self.rawSize, self.threshold, undistort, crop=crop) self.featureEx = FeatureExtraction(self.pre.cropSize) self.gui = GUI(self.world, self.pre.cropSize, self.threshold, self) self.world.setResolution(self.pre.cropSize) def formatTime(self, t): return time.strftime('%H:%M:%S', time.localtime(t)) \ + ( '%.3f' % (t - math.floor(t)) )[1:] #discard leading 0 def processFrame(self): startTime = time.time() logging.debug("Frame %d at %s", self.N, self.formatTime(startTime) ) self.N += 1 logging.debug("Capturing a frame") frame = self.capture.getFrame() logging.debug("Entering preprocessing") standard = self.pre.get_standard_form(frame) logging.debug("Entering feature extraction") ents = self.featureEx.features(standard, self.threshold) logging.debug("Detected entities:", ents) logging.debug("Entering World") self.world.update(startTime, ents) logging.debug("Updating GUI") if not self.headless: try: self.gui.updateWindow('raw', frame) self.gui.updateWindow('standard', standard) self.gui.draw(ents, startTime) except Exception, e: logging.error("GUI failed: %s", e) raise endTime = time.time() self.times.append( (endTime - startTime) )
def __init__(self): self.logger = logger self.sqlite = Sqlite() self.cap = Capture() self.report_available_yuming = [] 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, 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, handlers): super(self.__class__, self).__init__( choices=['start', 'stop'], handlers=handlers, arg='c', fields=None, layout=None, cmd_help='Start and stop the capture') self.capture = Capture()
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 __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()
class CaptureCommand(ActionCommand): def __init__(self, handlers): super(self.__class__, self).__init__( choices=['start', 'stop'], handlers=handlers, arg='c', fields=None, layout=None, cmd_help='Start and stop the capture') self.capture = Capture() def query(self, handlers, args): if args[1] == 'start': self.capture.start('en0', 1000) return ['Starting the capture',] elif args[1] == 'stop': self.capture.stop() return ['Stopping the capture',]
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, 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 __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')
class ECU(): 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 loop(self): band, img = self.capture.get_image() cont = 0 while(band): action = self.decisor.take_decision(img) self.sender.send_action(self.actions[action]) time.sleep(0.1) self.sender.send_action(self.actions[-1]) cv2.imshow(self.actions[action], img) if cv2.waitKey(10) & 0xFF == ord('q'): break for i in range(10): _, _ = self.capture.get_image() band, img = self.capture.get_image() cont += (((-1)**2)*1) + (1 - 1*(1**0.5)) # if(cont == 50): # band = False self.capture.close_conection()
class Cuadraditos(activity.Activity): log = logging.getLogger('cuadraditos-activity') def __init__(self, handle): activity.Activity.__init__(self, handle) #flags for controlling the writing to the datastore self.I_AM_CLOSING = False self.I_AM_SAVED = False self.props.enable_fullscreen_mode = False self.ui = None Constants(self) #self.modify_bg(gtk.STATE_NORMAL, Constants.color_black.gColor) #wait a moment so that our debug console capture mistakes gobject.idle_add(self._initme, None) def _initme(self, userdata=None): #the main classes self.m = Model(self) self.capture = Capture(self) self.ui = UI(self) return False def stop_pipes(self): self.capture.stop() def restart_pipes(self): self.capture.stop() self.capture.play() def close(self): self.I_AM_CLOSING = True self.m.UPDATING = False if (self.ui != None): self.ui.hide_all_windows() if (self.capture != None): self.capture.stop() #this calls write_file activity.Activity.close(self) def destroy(self): if self.I_AM_SAVED: activity.Activity.destroy(self)
class Server: 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") def get_name_info_all(self): return self.sqlite.get_available_yuming_infos_all() def blacklist_push(self, name): info = {} info['name'] = name info['blacklist'] = 'yes' return self.sqlite.update_yuming_info(info) def blacklist_pop(self, name): info = {} info['name'] = name info['blacklist'] = 'no' return self.sqlite.update_yuming_info(info) def yuming_follow(self, name): info = {} info['name'] = name info['follow'] = 'yes' return self.sqlite.update_yuming_info(info) def yuming_unfollow(self, name): info = {} info['name'] = name info['follow'] = 'no' return self.sqlite.update_yuming_info(info) def search_yuming_info(self, name): try: info = None info = self.cap.get_domain_name_info(name) return info except Exception,ex: logger.error("search_yuming_info error:%s" %(ex)) return info
def start(self): #screen dimentions self.x_display = int(str(QtGui.QDesktopWidget().availableGeometry()).strip("(").strip(")").split(",")[2].strip()) self.y_display = int(str(QtGui.QDesktopWidget().availableGeometry()).strip("(").strip(")").split(",")[3].strip()) #start button self.start_button = QtGui.QPushButton(self) self.start_button.setText('Press Button To Start') self.start_button.setStyleSheet("font-size:150px;background-color:#FFFFFF; border: 15px solid #222222") self.start_button.setFixedSize(self.x_display,self.y_display) #give start button powers self.cap = Capture(self.x_display,self.y_display) self.start_button.clicked.connect(self.exeCap) #size and show size button self.showFullScreen() self.center() self.show() self.raise_()
def shot(self): cap = Capture(self.conf) cap.shot() del cap
class Vision(): #rawSize = (768,576) rawSize = (640, 480) # Whether to 'crash' when something non-critical like the GUI fails debug = True 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 formatTime(self, t): return time.strftime('%H:%M:%S', time.localtime(t)) \ + ( '%.3f' % (t - math.floor(t)) )[1:] #discard leading 0 def processFrame(self): startTime = time.time() logging.debug("Frame %d at %s", self.N, self.formatTime(startTime) ) self.N += 1 logging.debug("Capturing a frame") frame = self.capture.getFrame() logging.debug("Entering preprocessing") standard = self.pre.get_standard_form(frame) bgsub_vals, bgsub_mask = self.pre.bgsub(standard) logging.debug("Entering feature extraction") hist_props_bgsub = self.histogram.calcHistogram(standard) hist_props_abs = self.histogram.calcHistogram(bgsub_vals) self.threshold.updateBGSubThresholds(hist_props_bgsub) #self.threshold.updateAbsThresholds(hist_props_abs) ents = self.featureEx.features(bgsub_vals, self.threshold) logging.debug("Detected entities:", ents) logging.debug("Entering interpreter") self.interpreter.interpret(ents) logging.debug("Entering World") self.world.update(startTime, ents) logging.debug("Updating GUI") if not self.headless: try: bgsub = self.pre.remove_background(standard) self.gui.updateWindow('raw', frame) self.gui.updateWindow('mask', bgsub_mask) self.gui.updateWindow('foreground', bgsub_vals) self.gui.updateWindow('bgsub', bgsub) self.gui.updateWindow('standard', standard) canny = cv.CreateImage(self.pre.cropSize, 8,1) # adaptive = cv.CreateImage(self.pre.cropSize, 32,3) # tmp = cv.CreateImage(self.pre.cropSize, 8,3) # cv.Convert(standard, adaptive) cv.CvtColor(bgsub, canny, cv.CV_BGR2GRAY) cv.Threshold(canny, canny, 150, 255, cv.CV_THRESH_OTSU) # cv.Threshold(canny, canny, 100, 255, cv.CV_ADAPTIVE_THRESH_GAUSSIAN_C) # cv.Sobel(adaptive, adaptive, 1,1,1) # cv.Convert(adaptive, tmp) # cv.ConvertScale(tmp, tmp, 10) # cv.CvtColor(tmp, canny, cv.CV_BGR2GRAY) # cv.Threshold(canny,canny, 50, 255, cv.CV_THRESH_BINARY) #cv.Canny(canny,canny, 100, 180,3) cv.CvtColor(canny, bgsub, cv.CV_GRAY2BGR) new = self.featureEx.detectCircles(bgsub) self.gui.updateWindow('adaptive', canny) self.gui.updateWindow('new', new) self.gui.draw(ents, startTime) except Exception, e: logging.error("GUI failed: %s", e) if self.debug: raise endTime = time.time() self.times.append( (endTime - startTime) )
class startWindow(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) self.start() def start(self): #screen dimentions self.x_display = int(str(QtGui.QDesktopWidget().availableGeometry()).strip("(").strip(")").split(",")[2].strip()) self.y_display = int(str(QtGui.QDesktopWidget().availableGeometry()).strip("(").strip(")").split(",")[3].strip()) #start button self.start_button = QtGui.QPushButton(self) self.start_button.setText('Press Button To Start') self.start_button.setStyleSheet("font-size:150px;background-color:#FFFFFF; border: 15px solid #222222") self.start_button.setFixedSize(self.x_display,self.y_display) #give start button powers self.cap = Capture(self.x_display,self.y_display) self.start_button.clicked.connect(self.exeCap) #size and show size button self.showFullScreen() self.center() self.show() self.raise_() def exeCap(self): if not self.cap.capturing: self.cap.startCapture() time.sleep(.1) self.deleteLater self.saveInit() else: print("Currently Capturing") def saveInit(self): QtGui.QDialog.__init__(self) self.strip_path = self.cap.strip_path self.upld = Upload(self.strip_path) self.save() def save(self): #line edit widget self.le = QtGui.QLineEdit(self) self.le.setPlaceholderText("555-555-5555") self.le.setStyleSheet("font-size:150px;background-color:#FFFFFF; border: 5px solid #222222") self.le.setAlignment(QtCore.Qt.AlignCenter) self.le.setFixedWidth(self.x_display-(self.x_display*.05)) #button widget self.pb = QtGui.QPushButton("Press 'Enter' to send Photostrip",self) self.pb.setStyleSheet("font-size:100px;background-color:#FFFFFF") #; border: 2px solid #222222" self.pb.setFixedWidth(self.x_display-(self.x_display*.05)) #regular expression restrictions reg_ex = QtCore.QRegExp("[0-9_]+") validator = QtGui.QRegExpValidator(reg_ex, self.le) self.le.setValidator(validator) #move widgets self.le.move(round(self.x_display*.025,0),(self.y_display*(1.0/3.0)-150)) self.pb.move(round(self.x_display*.025,0),(self.y_display*(1.0/3.0)+50)) #give widgets powers self.connect(self.pb, QtCore.SIGNAL("clicked()"),self.send) self.setWindowTitle("Learning") self.showFullScreen() self.raise_() self.show() def send(self): self.number = startWindow.makeUsable(str(self.le.text())) if startWindow.checkKosher(self.number): if self.upld.link == None: self.upld.sendToImgur() while self.upld.link == None: time.sleep(.05) self.upld.link = str(self.upld.link) sdtxt = sendText(self.upld.link,self.number) #TODO: change to init start button QtCore.QCoreApplication.instance().quit() else: #TODO: change to remove start button self.saveInit() def center(self): qr = self.frameGeometry() cp = QtGui.QDesktopWidget().availableGeometry().center() qr.moveCenter(cp) self.move(qr.topLeft()) @staticmethod def makeUsable(txt): NUMBERS = [str(x) for x in range(10)] if len(txt) == 10: txt = "1" + txt tmp_txt = "" for i in txt: if i in NUMBERS: tmp_txt += i txt = tmp_txt txt = "+" + txt return txt @staticmethod def checkKosher(txt): kosher = True if len(txt) != 12 or not txt.startswith("+1"): kosher = False return kosher
def main(winstyle = 0): # Initialize pygame capture = Capture('0') pygame.init() if pygame.mixer and not pygame.mixer.get_init(): print ('Warning, no sound') pygame.mixer = None # Set the display mode winstyle = 0 # |FULLSCREEN bestdepth = pygame.display.mode_ok(SCREENRECT.size, winstyle, 32) screen = pygame.display.set_mode(SCREENRECT.size, winstyle, bestdepth) #Load images, assign to sprite classes #(do this before the classes are used, after screen setup) img = load_image('tank.gif') Player.images = [img, pygame.transform.flip(img, 1, 0)] img = load_image('explosion1.gif') Explosion.images = [img, pygame.transform.flip(img, 1, 1)] Alien.images = load_images('alien1.gif', 'alien2.gif', 'alien3.gif') Bomb.images = [load_image('bomb.gif')] Shot.images = [load_image('shot.gif')] #decorate the game window icon = pygame.transform.scale(Alien.images[0], (32, 32)) pygame.display.set_icon(icon) pygame.display.set_caption('Pygame Aliens') pygame.mouse.set_visible(0) #create the background, tile the bgd image bgdtile = load_image('background.gif') background = pygame.Surface(SCREENRECT.size) for x in range(0, SCREENRECT.width, bgdtile.get_width()): background.blit(bgdtile, (x, 0)) screen.blit(background, (0,0)) pygame.display.flip() #load the sound effects boom_sound = load_sound('boom.wav') shoot_sound = load_sound('car_door.wav') if pygame.mixer: music = os.path.join(main_dir, 'data', 'house_lo.wav') pygame.mixer.music.load(music) pygame.mixer.music.play(-1) # Initialize Game Groups aliens = pygame.sprite.Group() shots = pygame.sprite.Group() bombs = pygame.sprite.Group() all = pygame.sprite.RenderUpdates() lastalien = pygame.sprite.GroupSingle() #assign default groups to each sprite class Player.containers = all Alien.containers = aliens, all, lastalien Shot.containers = shots, all Bomb.containers = bombs, all Explosion.containers = all Score.containers = all #Create Some Starting Values global score alienreload = ALIEN_RELOAD kills = 0 clock = pygame.time.Clock() #initialize our starting sprites global SCORE player = Player() Alien() #note, this 'lives' because it goes into a sprite group if pygame.font: all.add(Score()) current_pos = [0,0] while player.alive(): capture.run(); #get input if(len(capture.trackers) > 0): old_pos = current_pos; current_pos = capture.trackers[0].pos for event in pygame.event.get(): if event.type == QUIT or \ (event.type == KEYDOWN and event.key == K_ESCAPE): return keystate = pygame.key.get_pressed() if(old_pos[0] > current_pos[0]): direction = 1 elif(old_pos[0] < current_pos[0]): direction = -1 else: direction = 0 # clear/erase the last drawn sprites all.clear(screen, background) #update all the sprites all.update() #handle player input #direction = keystate[K_RIGHT] - keystate[K_LEFT] player.move(direction) firing = keystate[K_SPACE] if not player.reloading and firing and len(shots) < MAX_SHOTS: Shot(player.gunpos()) shoot_sound.play() player.reloading = firing # Drop bombs if lastalien and not int(random.random() * BOMB_ODDS): Bomb(lastalien.sprite) # Detect collisions for alien in pygame.sprite.spritecollide(player, aliens, 1): boom_sound.play() Explosion(alien) Explosion(player) SCORE = SCORE + 1 player.kill() for alien in pygame.sprite.groupcollide(shots, aliens, 1, 1).keys(): boom_sound.play() Explosion(alien) SCORE = SCORE + 1 for bomb in pygame.sprite.spritecollide(player, bombs, 1): boom_sound.play() Explosion(player) Explosion(bomb) player.kill() #draw the scene dirty = all.draw(screen) pygame.display.update(dirty) #cap the framerate clock.tick(40) if pygame.mixer: pygame.mixer.music.fadeout(1000) pygame.time.wait(1000) pygame.quit() cv2.destroyWindow('frame')
def set_cam_position(self): cap = Capture(self.conf) cap.set_cam_position() del cap
def test_arp_capture(self): cap = Capture("arp", 10000, None) cap.start("/Users/darren/PycharmProjects/bc_enum/unittests/arp.pcap", 10000)
def __init__(self): self.cf = load_config("./scan.ini") self.cap = Capture(self.cf) self.proc = Process(self.cf)
def test_nbns_capture(self): cap = Capture("nbns", 10000, None) cap.start("nbns.pcap", 10000)
import time parser = argparse.ArgumentParser() parser.add_argument("--config", help="configuration file") parser.add_argument("-d", "--debug", help="enable debug mode", action="store_true") arguments = parser.parse_args() if arguments.config is None: config_file = 'rpi-art.conf' else: config_file = arguments.config config_defaults = { 'width': 640, 'height': 480, 'fps': 24, 'slices': 8, 'debug': 'False' } config = ConfigParser.ConfigParser(config_defaults) config.read(config_file) if arguments.debug: config.set('rpi-art', 'debug', 'True') capture_queue = Queue() capture_thread = Capture(1, "Capture", capture_queue, config) detect_thread = Detect(2, "Detect", capture_queue, config) capture_thread.start() detect_thread.start() try: while True: if config.getboolean('rpi-art', 'debug'): print "Queue length", capture_queue.qsize() time.sleep(1) except KeyboardInterrupt: capture_thread.exit.set() detect_thread.exit.set()