Пример #1
0
    def __init__(self, cambuffer):
        threading.Thread.__init__(self)

        self._logger = logging.getLogger(__name__)
        self._logger.setLevel(logging.DEBUG)

        self.config = Config.instance()
        self.camera_buffer = cambuffer
        self.isRecording = True
        self.timestamp = int(round(time.time() * 1000))
        self.semaphore = threading.BoundedSemaphore()
        self.config = Config.instance()
        self.settings = Settings.instance()

        self.prior_image = None
        self.stream = None

        # auto exposure mode for logitech C270 can not be controlled by opencv, with this work
        # around the exposer mode can be set direcly by v4l2
        # a value of 1 deactivates auto exposure
        #subprocess.call(["v4l2-ctl", "--set-ctrl", "exposure_auto=1"])

        try:
            self.camera = cv2.VideoCapture(self.config.camera.device)
        except:
            self._logger.error("Can not create camera device.")
            return

        # this sets the resolution of the C270 which is 1280x720 by default
        self.camera.set(3, 1280)
        self.camera.set(4, 720)
        self._logger.debug("Selected Camera Device %i" %
                           (int(self.config.camera.device)))
        self.start()
Пример #2
0
def delete_scan(scan_id, ignore_errors=True):

    #basedir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
    folder = Config.instance().folders.scans + scan_id + "/"

    mask = Config.instance().folders.scans + scan_id + "/" '*.[pso][ltb][lyj]'
    number_of_files = len(glob.glob(mask))
Пример #3
0
    def __init__(self, cambuffer):
        threading.Thread.__init__(self)

        self._logger =  logging.getLogger(__name__)
        self._logger.setLevel(logging.DEBUG)

        self.config = Config.instance()
        self.camera_buffer = cambuffer
        self.isRecording = True
        self.timestamp = int(round(time.time() * 1000))
        self.semaphore = threading.BoundedSemaphore()
        self.config = Config.instance()
        self.settings = Settings.instance()

        self.prior_image = None
        self.stream = None

        # auto exposure mode for logitech C270 can not be controlled by opencv, with this work
        # around the exposer mode can be set direcly by v4l2
        subprocess.call(["v4l2-ctl", "--set-ctrl", "exposure_auto=1"])

        self.camera = cv2.VideoCapture(self.config.camera.device)

        self.camera.set(3,1280)
        self.camera.set(4,720)
        self._logger.debug("Selected Camera Device %i" % (int(self.config.camera.device)))
        self.start()
Пример #4
0
    def __init__(self, cambuffer):
        threading.Thread.__init__(self)

        self._logger =  logging.getLogger(__name__)
        self._logger.setLevel(logging.DEBUG)

        self.config = Config.instance()
        self.camera_buffer = cambuffer
        self.isRecording = True
        self.timestamp = int(round(time.time() * 1000))
        self.semaphore = threading.BoundedSemaphore()
        self.config = Config.instance()
        self.settings = Settings.instance()

        self.prior_image = None
        self.stream = None

        # auto exposure mode for logitech C270 can not be controlled by opencv, with this work
        # around the exposer mode can be set direcly by v4l2
        # a value of 1 deactivates auto exposure
        #subprocess.call(["v4l2-ctl", "--set-ctrl", "exposure_auto=1"])

        try:
            self.camera = cv2.VideoCapture(self.config.camera.device)
        except:
            self._logger.error("Can not create camera device.")
            return

        # this sets the resolution of the C270 which is 1280x720 by default
        self.camera.set(3,1280)
        self.camera.set(4,720)
        self._logger.debug("Selected Camera Device %i" % (int(self.config.camera.device)))
        self.start()
Пример #5
0
def delete_scan(scan_id,ignore_errors=True):



    #basedir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
    folder =  Config.instance().folders.scans+scan_id+"/"

    mask = Config.instance().folders.scans+scan_id+"/"'*.[pso][ltb][lyj]'
    number_of_files = len(glob.glob(mask))
Пример #6
0
    def __init__(self):
        super(FSScanProcessor, self).__init__()

        self.eventManager = FSEventManager.instance()
        self.settings = Settings.instance()
        self.config = Config.instance()

        self._logger = logging.getLogger(__name__)
        self._logger.setLevel(logging.DEBUG)

        self._prefix = None
        self._resolution = 16
        self._number_of_pictures = 0
        self._total = 0
        self._laser_positions = 1
        self._progress = 0
        self._is_color_scan = True
        self.point_cloud = None
        self.image_task_q = multiprocessing.Queue(self.config.process_numbers +
                                                  1)
        self.current_position = 0
        self._laser_angle = 33.0
        self._stop_scan = False
        self._current_laser_position = 1

        self.semaphore = multiprocessing.BoundedSemaphore()
        self.event_q = self.eventManager.get_event_q()

        self._worker_pool = FSImageWorkerPool(self.image_task_q, self.event_q)
        self.hardwareController = HardwareController.instance()
        self.eventManager.subscribe(FSEvents.ON_IMAGE_PROCESSED,
                                    self.image_processed)
        self._scan_brightness = self.settings.camera.brightness
        self._scan_contrast = self.settings.camera.contrast
        self._scan_saturation = self.settings.camera.saturation
    def __init__(self):
        super(FSScanProcessor, self).__init__()
        self._logger =  logging.getLogger(__name__)
        self._logger.setLevel(logging.DEBUG)
        self._prefix = None
        self._resolution = 16
        self._number_of_pictures = 0
        self._total = 0
        self._laser_positions = 1
        self._progress = 0
        self._is_color_scan = True
        self.point_cloud = None
        self.image_task_q = multiprocessing.Queue(5)
        self.current_position = 0
        self._laser_angle = 33.0
        self._stop_scan = False
        self._current_laser_position = 1
        self.eventManager = FSEventManager.instance()
        self.settings = Settings.instance()
        self.config = Config.instance()
        self.semaphore = multiprocessing.BoundedSemaphore()
        self._contrast = 0.5
        self._brightness = 0.5


        self.event_q = self.eventManager.get_event_q()

        self._worker_pool = FSImageWorkerPool(self.image_task_q,self.event_q)
        self.hardwareController = HardwareController.instance()
        self.eventManager.subscribe(FSEvents.ON_IMAGE_PROCESSED, self.image_processed)
        self._scan_brightness = self.settings.camera.brightness
        self._scan_contrast =  self.settings.camera.contrast
Пример #8
0
 def __init__(self):
     super(FSSettingsPreviewProcessor, self).__init__()
     self.hardwareController = HardwareController.instance()
     self.eventManager = FSEventManager.instance()
     self.config = Config.instance()
     self.settings = Settings.instance()
     self._image_processor = ImageProcessor(self.config, self.settings)
 def __init__(self):
     super(FSSettingsPreviewProcessor, self).__init__()
     self.hardwareController = HardwareController.instance()
     self.eventManager = FSEventManager.instance()
     self.config = Config.instance()
     self.settings = Settings.instance()
     self._image_processor = ImageProcessor(self.config, self.settings)
Пример #10
0
    def run(self):
        self._logger.info("FabScanPi-Server "+str(__version__))

        try:

            # create Singleton instances
            _config = Config.instance(self.config_file)
            _settings = Settings.instance(self.settings_file)

            _hardwareController = HardwareController.instance()
            _eventManager = FSEventManager.instance()

            # Websocket Server
            self.fsWebSocketServer = FSWebSocketServer()
            self.fsWebSocketServer.start()

            _scanner = FSScanner()
            _scanner.start()

            # Web Server
            self.fsWebServer = WebServer()
            self.fsWebServer.serve_forever()

        except (KeyboardInterrupt, SystemExit):

            time.sleep(0.5)
            _hardwareController.laser.off()
            _hardwareController.led.off()
            _hardwareController.turntable.stop_turning()

            sys.exit(0)
Пример #11
0
 def __init__(self, prefix):
     threading.Thread.__init__(self)
     self.eventManager = FSEventManager.instance()
     self._logger =  logging.getLogger(__name__)
     self._logger.setLevel(logging.DEBUG)
     self.settings = Settings.instance()
     self.config = Config.instance()
     self.prefix = prefix
Пример #12
0
 def __init__(self):
     self._logger =  logging.getLogger(__name__)
     self._logger.setLevel(logging.DEBUG)
     self.config = Config.instance()
     self._port = self.config.serial.port
     self._baudrate = self.config.serial.baudrate
     self._serial = None
     self._openSerial()
Пример #13
0
def save_image(img, number, prefix, dir_name="scans"):

    dir_name = Config.instance().folders.scans + dir_name
    if not os.path.exists(dir_name):
        os.makedirs(dir_name)
    prefix = os.path.join(dir_name, "%s_{0}" % prefix)
    number = str(number).zfill(3)
    cv2.imwrite(prefix.format(number) + ".jpg", img)
    return prefix.format(number) + ".jpg"
Пример #14
0
def delete_scan(scan_id,ignore_errors=True):

    #basedir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
    folder =  Config.instance().folders.scans+scan_id+"/"

    if os.path.isdir(folder):
        shutil.rmtree(folder, ignore_errors=True)
    else:
         print "Nothing to delete..."
Пример #15
0
def load_image(number, prefix, dir_name="scans"):
    dir_name = Config.instance().folders.scans + dir_name
    prefix = os.path.join(dir_name, "%s_{0}" % prefix)
    number = str(number).zfill(3)
    if os.path.isfile(prefix.format(number) + ".jpg"):
        image = cv2.imread(prefix.format(number) + ".jpg")
        return image
    else:
        return None
Пример #16
0
 def __init__(self, id, filter, format):
     threading.Thread.__init__(self)
     self.eventManager = FSEventManager.instance()
     self._logger =  logging.getLogger(__name__)
     self._logger.setLevel(logging.DEBUG)
     self.settings = Settings.instance()
     self.config = Config.instance()
     self.scan_id = id
     self.filter = filter
     self.format = format
Пример #17
0
 def __init__(self, id, filter, format):
     threading.Thread.__init__(self)
     self.eventManager = FSEventManager.instance()
     self._logger = logging.getLogger(__name__)
     self._logger.setLevel(logging.DEBUG)
     self.settings = Settings.instance()
     self.config = Config.instance()
     self.scan_id = id
     self.filter = filter
     self.format = format
Пример #18
0
    def __init__(self, task_q, event_q):
        self._task_q = task_q
        self._event_q = event_q
        self.workers = []
        self.config = Config.instance()

        self._number_of_workers = self.config.process_numbers
        self._workers_active = False
        self._logger = logging.getLogger(__name__)
        self._logger.setLevel(logging.DEBUG)
Пример #19
0
    def __init__(self, task_q, event_q):
        self._task_q = task_q
        self._event_q = event_q
        self.workers = []
        self.config = Config.instance()

        self._number_of_workers = self.config.process_numbers
        self._workers_active = False
        self._logger = logging.getLogger(__name__)
        self._logger.setLevel(logging.DEBUG)
Пример #20
0
 def __init__(self):
     self._logger =  logging.getLogger(__name__)
     self._logger.setLevel(logging.DEBUG)
     self.config = Config.instance()
     if hasattr(self.config.serial, 'port'):
         self._port = self.config.serial.port
     else:
         self._port = self._port = self.serialList()[0]
     self._baudrate = self.config.serial.baudrate
     self._serial = None
     self._connected = False
     self._openSerial()
Пример #21
0
    def run(self):
        self._logger.info("FabScanPi-Server " + str(__version__))

        try:
            # inject "static" classed
            injector.provide(FSEventManagerInterface, FSEventManagerSingleton)
            injector.provide_instance(FSWebSocketServerInterface,
                                      FSWebSocketServer())
            injector.provide_instance(ConfigInterface,
                                      Config(self.config_file, True))

            injector.provide_instance(SettingsInterface,
                                      Settings(self.settings_file, True))

            # inject "dynamic" classes
            self.config = injector.get_instance(ConfigInterface)
            FSScannerFactory.injectScannerType(self.config.scanner_type)

            # start server services
            websocket_server = injector.get_instance(
                FSWebSocketServerInterface)
            websocket_server.start()

            webserver = FSWebServer()
            webserver.start()

            FSScanner().start()

            FSEventManagerSingleton().instance.subscribe(
                FSEvents.COMMAND, self.on_server_command)

            while not self.exit:
                try:
                    time.sleep(0.3)

                except KeyboardInterrupt:
                    raise

            if self.upgrade:
                self._logger.info("Upgrading FabScanPi Server")
                self.update_server()
                self.restart = True

            if self.restart:
                self._logger.info("Restarting FabScanPi Server")
                self.restart_server()
                self.exit = True

            self._logger.info("FabScan Server Exit. Bye!")
            os._exit(1)

        except (KeyboardInterrupt, SystemExit):
            sys.exit(0)
Пример #22
0
    def __init__(self):

        self.camera_buffer = FSRingBuffer(10)
        config = Config.instance()

        if config.camera.type == 'PICAM':
            self.device = PiCam(self.camera_buffer)

        if config.camera.type == 'dummy':
            self.device = DummyCam()

        if config.camera.type == 'C270':
            self.device = C270(self.camera_buffer)
Пример #23
0
    def __init__(self):

        self.camera_buffer = FSRingBuffer(10)
        config = Config.instance()

        if config.camera.type  == 'PICAM':
            self.device = PiCam(self.camera_buffer)

        if config.camera.type == 'dummy':
            self.device = DummyCam()

        if config.camera.type == 'C270':
            self.device = C270(self.camera_buffer)
Пример #24
0
 def __init__(self):
     self._logger = logging.getLogger(__name__)
     self._logger.setLevel(logging.DEBUG)
     self.config = Config.instance()
     if hasattr(self.config.serial, 'port'):
         self._port = self.config.serial.port
     else:
         self._port = self._port = self.serialList()[0]
     self._baudrate = self.config.serial.baudrate
     self._serial = None
     self._connected = False
     self._firmware_version = None
     self._openSerial()
Пример #25
0
    def __init__(self, cambuffer):
        threading.Thread.__init__(self)
        self.start()
        self.isRecording = True
        self.timestamp = int(round(time.time() * 1000))
        self.semaphore = threading.BoundedSemaphore()
        self.camera = None
        self.prior_image = None
        self.stream = None
        self.config = Config.instance()
        self.settings = Settings.instance()
        self.camera_buffer = cambuffer
        self.awb_default_gain = 0

        self._logger =  logging.getLogger(__name__)
Пример #26
0
    def create(self, number_of_workers):
        '''
            Create Processes in Pool
        '''

        self.set_number_of_workers(number_of_workers)

        for _ in range(self._number_of_workers):
            worker = FSImageWorkerProcess(Settings.instance(), Config.instance(), self._task_q, self._event_q)
            worker.daemon = True
            worker.start()
            self.workers.append(worker)

        self._workers_active = True

        return self.workers
Пример #27
0
    def __init__(self, cambuffer):
        threading.Thread.__init__(self)
        self.start()
        self.isRecording = True
        self.timestamp = int(round(time.time() * 1000))
        self.semaphore = threading.BoundedSemaphore()
        self.camera = None
        self.prior_image = None
        self.stream = None
        self.config = Config.instance()
        self.settings = Settings.instance()
        self.camera_buffer = cambuffer
        self.awb_default_gain = 0
        self.is_idle = True

        self._logger = logging.getLogger(__name__)
Пример #28
0
    def __init__(self):
        self.config = Config.instance()
        self.settings = Settings.instance()

        self.camera = None
        self._image_processor = ImageProcessor(self.config, self.settings)
        self.camera = FSCamera()
        self.serial_connection = FSSerialCom()

        self.turntable = Turntable(self.serial_connection)

        self.laser = Laser(self.serial_connection)
        self.led = Led(self.serial_connection)

        self.laser.off()
        self.led.off()
        self.turntable.stop_turning()
    def __init__(self,*args):

        self.api = FSapi()
        self._eventManager = FSEventManager.instance()
        self.close_mjpeg_stream = False
        self.config = Config.instance()


        self.ROUTES = (
            # [url_prefix ,  directory_path]
            ['/upload/preview/',''],
            ['/settings.mjpeg',    ''],
            ['/scans',    self.config.folders.scans],
            ['/scan',     self.config.folders.scans],
            ['',          self.config.folders.www],  # empty string for the 'default' match

        )
        SimpleHTTPRequestHandler.__init__(self, *args)
Пример #30
0
    def __init__(self):
        self.config = Config.instance()
        self.settings = Settings.instance()

        self.camera = None
        self._image_processor = ImageProcessor(self.config, self.settings)
        self.camera = FSCamera()
        self.serial_connection = FSSerialCom()

        self.turntable = Turntable(self.serial_connection)

        self.laser = Laser(self.serial_connection)
        self.led = Led(self.serial_connection)

        self.laser.off()
        self.led.off()
        self.turntable.stop_turning()
        self.turntable.disable_motors()
Пример #31
0
    def __init__(self, settings=os.path.dirname(__file__)+"/config/default.settings.json", first=True):

        if first:

            with open(settings) as file:
                settings = file.read()

            settings = json.loads(settings)

        def _traverse(key, element):
            if isinstance(element, dict):
                return key, Settings(element, first=False)
            else:
                return key, element


        object_dict = dict(_traverse(k, v) for k, v in settings.iteritems())
        self.config = Config.instance()
        self.__dict__.update(object_dict)
Пример #32
0
    def create_services(self):

        injector.provide(FSEventManagerInterface, FSEventManagerSingleton)
        injector.provide_instance(ConfigInterface, Config(self.config_file))
        injector.provide_instance(SettingsInterface,
                                  Settings(self.settings_file))

        # inject "dynamic" classes
        self.config = injector.get_instance(ConfigInterface)
        FSScannerFactory.injectScannerType(self.config.file.scanner_type)

        self.webserver = FSWebServer()
        self.webserver.start()

        self.scanner = FSScanner()
        self.scanner.start()
        self.eventManager = FSEventManagerSingleton()
        self.eventManager.instance.subscribe(FSEvents.COMMAND,
                                             self.on_server_command)
Пример #33
0
    def create(self, number_of_workers):
        '''
            Create Processes in Pool
        '''

        self.set_number_of_workers(number_of_workers)
        self._logger.info("Creating %i image worker processes." %
                          number_of_workers)

        for _ in range(self._number_of_workers):
            worker = FSImageWorkerProcess(Settings.instance(),
                                          Config.instance(), self._task_q,
                                          self._event_q)
            worker.daemon = True
            worker.start()
            self.workers.append(worker)

        self._workers_active = True

        return self.workers
Пример #34
0
    def __init__(self,
                 settings=os.path.dirname(__file__) +
                 "/config/default.settings.json",
                 first=True):

        if first:

            with open(settings) as file:
                settings = file.read()

            settings = json.loads(settings)

        def _traverse(key, element):
            if isinstance(element, dict):
                return key, Settings(element, first=False)
            else:
                return key, element

        object_dict = dict(_traverse(k, v) for k, v in settings.iteritems())
        self.config = Config.instance()
        self.__dict__.update(object_dict)
    def __init__(self,*args):
        self._logger =  logging.getLogger(__name__)
        self._logger.setLevel(logging.DEBUG)
        self.api = FSRest()
        self._eventManager = FSEventManager.instance()
        self.close_mjpeg_stream = False
        self.config = Config.instance()


        self.ROUTES = (
            # [url_prefix ,  directory_path]
            ['/upload/preview/',''],
            ['/settings.mjpeg',    ''],
            ['/scans',    self.config.folders.scans],
            ['/scan',     self.config.folders.scans],
            ['',          self.config.folders.www],  # empty string for the 'default' match

        )
        try:
            SimpleHTTPRequestHandler.__init__(self, *args)
        except:
            self._logger.info("http socket disconnect")
            pass
Пример #36
0
def delete_image_folders(scan_id):
    folder = Config.instance().folders.scans + scan_id + "/color_raw/"
    delete_folder(folder)

    folder = Config.instance().folders.scans + scan_id + "/laser_raw/"
    delete_folder(folder)
Пример #37
0
 def __init__(self):
     self._logger =  logging.getLogger(__name__)
     self._logger.setLevel(logging.DEBUG)
     self.config = Config.instance()
Пример #38
0
 def __init__(self, color=True):
     self.points = []
     self.file_name = None
     self._dir_name = None
     self.color = color
     self.config = Config.instance()
Пример #39
0
 def __init__(self):
     self.config = Config.instance()
Пример #40
0
def delete_image_folders(scan_id):
    folder =  Config.instance().folders.scans+scan_id+"/color_raw/"
    delete_folder(folder)

    folder =  Config.instance().folders.scans+scan_id+"/laser_raw/"
    delete_folder(folder)
Пример #41
0
 def __init__(self, color=True):
     self.points = []
     self.file_name = None
     self._dir_name = None
     self.color = color
     self.config = Config.instance()