class FSImageWorkerProcess(multiprocessing.Process):
    def __init__(self, image_task_q, event_q, config, settings, imageprocessor):
        super(FSImageWorkerProcess, self).__init__(group=None)
        self.image_task_q = image_task_q
        self.settings = settings
        self.config = config
        self.exit = False
        self.event_q = event_q
        self.image = FSImage()

        self.log = logging.getLogger('IMAGE_PROCESSOR THREAD')
        self.log.setLevel(logging.DEBUG)
        self.image_processor = imageprocessor
        self._logger = logging.getLogger(__name__)
        self._logger.setLevel(logging.DEBUG)


    def run(self):
        '''
            Image Process runner
        '''

        self._logger.debug("process "+str(self.pid)+" started")

        #import pydevd
        #pydevd.settrace('192.168.98.104', port=12011, stdoutToServer=True, stderrToServer=True)

        while not self.exit:
            if not self.image_task_q.empty():

                data = dict()
                try:
                    image_task = self.image_task_q.get_nowait()

                    if image_task:

                        # we got a kill pill
                        if image_task.task_type == "KILL":
                            self._logger.debug("Killed Worker Process with PID "+str(self.pid))
                            self.exit = True
                            break

                        #print "process "+str(self.pid)+" task "+str(image_task.progress)
                        if (image_task.task_type == "PROCESS_COLOR_IMAGE"):
                            self.image.save_image(image_task.image, image_task.progress, image_task.prefix, dir_name=image_task.prefix+'/color_'+image_task.raw_dir)

                            data['points'] = []
                            data['image_type'] = 'color'

                            event = dict()
                            event['event'] = "ON_IMAGE_PROCESSED"
                            event['data'] = data

                            self.event_q.put(event)

                        if (image_task.task_type == "PROCESS_DEPTH_IMAGE"):
                            #self._logger.debug("process " + str(self.pid) + " handle image")

                            try:
                                angle = float(image_task.progress * 360) / float(image_task.resolution)
                                #self._logger.debug("Progress "+str(image_task.progress)+" Resolution "+str(image_task.resolution)+" angle "+str(angle))
                                self.image.save_image(image_task.image, image_task.progress, image_task.prefix, dir_name=image_task.prefix+'/laser_'+image_task.raw_dir)
                                color_image = self.image.load_image(image_task.progress, image_task.prefix, dir_name=image_task.prefix+'/color_'+image_task.raw_dir)

                                point_cloud, texture = self.image_processor.process_image(angle, image_task.image, color_image)
                                # FIXME: Only send event if points is non-empty
                            except StandardError as e:
                                self._logger.debug(e)
                            data['point_cloud'] = point_cloud
                            data['texture'] = texture
                            data['image_type'] = 'depth'
                            #data['progress'] = image_task.progress
                            #data['resolution'] = image_task.resolution

                            event = dict()
                            event['event'] = "ON_IMAGE_PROCESSED"
                            event['data'] = data

                            self.event_q.put(event)

                except Empty:
                    time.sleep(0.05)
                    pass
            else:
                # thread idle
                time.sleep(0.05)
Esempio n. 2
0
class FSImageWorkerProcess(multiprocessing.Process):
    def __init__(self, image_task_q, output_q,   config, settings, scanprocessor, imageprocessor):
        super(FSImageWorkerProcess, self).__init__(group=None)
        self.image_task_q = image_task_q
        self.output_q = output_q
        self.settings = settings
        self.config = config
        self.exit = False
        self.scanprocessor = scanprocessor
        self.image = FSImage()

        self.log = logging.getLogger('IMAGE_PROCESSOR THREAD')
        self.log.setLevel(logging.DEBUG)
        self.image_processor = imageprocessor
        self._logger = logging.getLogger(__name__)
        self._logger.setLevel(logging.DEBUG)


    def run(self):
        '''
            Image Process runner
        '''

        self._logger.debug("process "+str(self.pid)+" started")

        while not self.exit:
            if not self.image_task_q.empty():

                data = dict()
                try:
                    image_task = self.image_task_q.get_nowait()

                    if image_task:

                        if image_task.task_type == "KILL":
                            self._logger.debug("Killed Worker Process with PID "+str(self.pid))
                            self.exit = True


                        if (image_task.task_type == "PROCESS_COLOR_IMAGE"):

                            #image = self.image_processor.decode_image(image_task.image)
                            self.image.save_image(image_task.image, image_task.progress, image_task.prefix, dir_name=image_task.prefix+'/color_'+image_task.raw_dir)

                            data['points'] = []
                            data['image_type'] = 'color'
                            data['laser_index'] = None

                            self.output_q.put(data)


                        if (image_task.task_type == "PROCESS_DEPTH_IMAGE"):
                            self._logger.debug('Image Processing starts.')
                            try:

                                #self.image.save_image(image_task.image, image_task.progress, image_task.prefix,
                                #                      dir_name=image_task.prefix + '/raw_' + image_task.raw_dir)

                                image_task.image = self.image_processor.decode_image(image_task.image)
                                angle = float(image_task.progress * 360) / float(image_task.resolution)
                                color_image = self.image.load_image(image_task.progress, image_task.prefix, dir_name=image_task.prefix+'/color_'+image_task.raw_dir)
                                point_cloud, texture = self.image_processor.process_image(angle, image_task.image, color_image, index=image_task.index)

                                data['point_cloud'] = point_cloud
                                data['texture'] = texture
                                data['image_type'] = 'depth'
                                data['laser_index'] = image_task.index

                            except Exception as e:
                                self._logger.debug(e)


                            self.output_q.put(data)
                            color_image = None
                            point_cloud = None
                            texture = None

                            self._logger.debug('Image Processing finished.')

                        image_task = None

                except Empty:
                    time.sleep(0.1)
                    pass
            else:
                # thread idle
                time.sleep(0.1)