def main(): log.basicConfig(format='[ %(levelname)s ] %(message)s', level=log.INFO, stream=sys.stdout) args = build_argparser().parse_args() text_detector = TextDetector(args) document_identifier = DocumentIdentifier(args.config) document_aligner = DocumentAligner(args) web_server = WebServer() web_server.start() try: input_source = int(args.input_source) except ValueError: input_source = args.input_source if os.path.isdir(input_source): cap = FolderCapture(input_source) else: cap = cv2.VideoCapture(input_source) if not cap.isOpened(): log.error('Failed to open "{}"'.format(args.input_source)) if isinstance(cap, cv2.VideoCapture): cap.set(cv2.CAP_PROP_BUFFERSIZE, 1) log.info('Starting inference...') print( "To close the application, press 'CTRL+C' here or switch to the output window and press ESC key" ) while cap.isOpened(): ret, frame = cap.read() if not ret: break frame = document_aligner.preprocess(frame) text = text_detector.process(frame, True) result = document_identifier.process(text) print(json.dumps(result, indent=4)) while True: #web_server.push(result) cv2.waitKey(4000) key = cv2.waitKey(0) esc_code = 27 if key == esc_code: breaks cv2.destroyAllWindows() cap.release()
class Server: def __init__(self): Log.info("Server.init()") self.webServer = WebServer() def start(self): Log.info("Server.start()") self.webServer.start() def stop(self): Log.info("Server.stop()") self.webServer.stop()
def start(self): if len(sys.argv) == 1: print "Please specify local IP address" print "Then add 'webservice' to make values available via HTTP" print "" sys.exit() with_web_service = False if len(sys.argv) > 2: if sys.argv[2] == "webservice": with_web_service = True self.local_host = sys.argv[1] self.load_config() t = threading.Thread(target=self.start_raspression_server) t.daemon = True t.start() if with_web_service: ws = WebServer(self) ws.daemon = True ws.start() t.join() try: while True: print "??" pass except KeyboardInterrupt: print "Exiting..." del ws del t sys.exit()
class MicroWifi: def __init__(self, ap_name='MicroWifi', ap_password=''): self.web_server = WebServer() self.wifi_man = WifiManager(ap_name=ap_name, ap_password=ap_password) # setup web server routes self.setup_routes(self.web_server, self.wifi_man) def start(self): # try to auto connect self.wifi_man.auto_connect() if self.wifi_man.is_access_point_mode(): # start our web server to allow the user to configure the device self.web_server.start() def stop(self): try: self.web_server.stop() except Exception as exc: print('Error stopping {}'.format(exc)) def setup_routes(self, server, wifi_manager): @server.route("/") def home(client, request): try: html = "" try: with open('www/index.html') as f: html = f.read() except OSError: pass server.send_response(client, html) except Exception as exc: print('Error in home route {}'.format(exc)) @server.route("/scan") def scan(client, request): try: network_ssids = [ network[0] for network in wifi_manager.access_point_scan() ] payload = {'networks': network_ssids} server.send_response(client, json.dumps(payload), content_type='application/json') except Exception as exc: print('Error in scan route {}'.format(exc)) @server.route("/connect", 'POST') def connect(client, request): params = server.get_form_data(request) ssid = params.get('ssid') password = params.get('password') # try to connect to the network status = wifi_manager.connect(ssid, password) payload = { 'status': status, 'msg': 'Successfully connected to {}'.format(ssid) if status else 'Error connecting to {}'.format(ssid) } server.send_response(client, json.dumps(payload), content_type='application/json')
'b': 0 }, 'boxThickness': 2, 'imgFileNamePrefix': 'cam', 'httpPort': 8000, 'webDir': 'web', 'imageDir': 'images', 'snapshotFile': 'snapshot.jpg', 'classificationPoll': 5, 'classificationThreshold': 0.7 } def signal_handler(sig, frame): motion_capture.stop() web_server.stop() classifier.stop() signal.signal(signal.SIGINT, signal_handler) os.chdir(config['webDir']) [os.remove(f) for f in glob.glob(os.path.join(config['imageDir'], "*.jpg"))] message_queue = Queue() motion_capture = MotionCapture(config, message_queue) motion_capture.start() web_server = WebServer(config, message_queue) web_server.start() classifier = Classifier(config) classifier.start()
from web_server import WebServer server = WebServer() server.start()