示例#1
0
    def __init__(self, parent=None, cap_Objects=None, time=float):
        super(Save_img_Timer, self).__init__()
        self.parent = parent
        self.cap_Objects = cap_Objects
        self.time = time / 32
        self.save_dirs = []
        self.img_names = []
        self.logger = MyLogging(logger_name='user').logger

        for cap_Object in self.cap_Objects:
            self.save_dirs.append(self.parent.save_path + self.parent.cvid + '/'
                                  + cap_Object.label_name + '/' + \
                                  self.parent.direction + '/')

            self.img_names.append(self.parent.cvid + '_' + self.parent.char + '_' + \
                                  self.parent.date + '_' + cap_Object.label_name +\
                                  '_' + self.parent.direction)

        for save_dir in self.save_dirs:
            if not os.path.exists(save_dir):
                os.makedirs(save_dir)
                self.logger.info('Create dir [%s]' % save_dir)
                msg = 'Create dir [%s]' % save_dir
                self.creat_dirs_msg.connect(self.parent.update_textBrowser)
                self.creat_dirs_msg.emit(msg)

        self.index = 1
        self.isStop = False
示例#2
0
    def __init__(self, cofig):
        super(SelfCheck, self).__init__(config)
        self._config = config
        self._necessary_check = config['necessary_check']
        self.mylogger = MyLogging(logger_name='user').logger
        self._show_cam_item = config['operating_mode']['show_cam_item']
        self.check_status = False

        if int(self.necessary_check['database_check']):
            self.databaseCheck()
        if int(self.necessary_check['internet_check']):
            self._InternetCheck()
        if int(self.necessary_check['gpu_check']):
            self.gpuCheck()
示例#3
0
 def __init__(self,
              capture=cv2.VideoCapture,
              width=800,
              height=600,
              label=None,
              label_name=None):
     # Get the capture object from the MainWindow init.
     self.capture = capture
     self.capture.set(3, int(width))
     self.capture.set(4, int(height))
     self.width = width
     self.height = height
     self.label = label
     self.label_name = label_name
     self.currentFrame = np.array([])
     self.logger = MyLogging(logger_name='user').logger
     self.logger.info('Create [Capture]: %s [Label_name]: %s' %
                      (self.capture, self.label_name))
示例#4
0
class Camera():
    def __init__(self,
                 capture=cv2.VideoCapture,
                 width=800,
                 height=600,
                 label=None,
                 label_name=None):
        # Get the capture object from the MainWindow init.
        self.capture = capture
        self.capture.set(3, int(width))
        self.capture.set(4, int(height))
        self.width = width
        self.height = height
        self.label = label
        self.label_name = label_name
        self.currentFrame = np.array([])
        self.logger = MyLogging(logger_name='user').logger
        self.logger.info('Create [Capture]: %s [Label_name]: %s' %
                         (self.capture, self.label_name))

    def getFrame(self):
        try:
            # Get frame and convert it to PixMap
            ret, img = self.capture.read()
            img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
            # Add the hisself Cap object's label name in pic top.
            if self.label_name:
                cv2.putText(img, self.label_name, (18, 56), 0, 1,
                            (129, 216, 207), 3)
            # Get the height, width, byserPer from this img.
            height, width, bytesPer = img.shape
            # bytesPerLine = bytesPer*3
            # Convert the img to QPixmap type, because the QtLabel just
            # accept this type.
            img = QImage(img, width, height, QImage.Format_RGB888)
            img = QPixmap.fromImage(img)
            # Set label show img. And update it.
            self.label.setPixmap(img)
        except:
            self.logger.error('Some error happened in <cameraModule.py | '
                              'getFrame>.')
            sys.exit(0)

    def refresh(self):
        # 1. Create a new Thread Class and Init it.
        self.cap_timer = Camera_Timer()
        self.logger.info("Camera_Timer: [%s] has created." % self.cap_timer)
        # 2. Connect the thing let signal to do it.
        self.cap_timer.update.connect(self.getFrame)
        # 3. Start Thread.
        try:
            self.cap_timer.start()
        except BaseException:
            self.cap_timer.stop()
            self.cap_timer.quit()

    def quit(self):
        self.cap_timer.stop()
        self.cap_timer.quit()
示例#5
0
    def __init__(self, cam_name=None):
        self.cam_name = cam_name
        config = read_config()[self.cam_name]
        self.cam_path = config['cam_path']
        self.width = int(config['width'])
        self.height = int(config['height'])

        self.capture = cv2.VideoCapture(self.cam_path)
        self.capture.set(3, self.width)
        self.capture.set(4, self.height)

        # Logging info
        MyLogging(logger_name='user').logger.info('[%s] Finished '
                                                  'Initializing.' % self.cam_name)
示例#6
0
    def __init__(self, cfg_path='Config.cfg'):
        # 1.Loading Config
        super(Config, self).__init__(cfg_path)
        # 2.Logging
        self.mylogging = MyLogging(logger_name='user')
        self.mylogger = self.mylogging.logger

        self._need_guide = self.config['operating_mode']['need_guide']
        self._cam_path_used = self.config['operating_mode']['cam_path_used']
        self._necessary_check = self.config['necessary_check']
        self._cam_user = self.config['cam_user']
        self._cam_item = self.config['cam_item']
        self._cam_item2 = self.config['cam_item2']
        self._account = self.config['account']
        # Check Hardware and Software before working starting.
        self.before_work()
示例#7
0
    def __init__(self, port_name=None, baud_rate=None,
                 data_bits=None, stop_bits=None):
        # Read config
        config = read_config()[port_name]
        self.port_name = config['port_name']
        self.baud_rate = config['baud_rate']
        self.data_bits = config['data_bits']
        self.stop_bits = config['stop_bits']

        # Initial
        self.weigher = QSerialPort()  # It is the subclass of the QIODevice class;
        self.weigher.setPortName(self.port_name)  # passing name such as 'COM1'
        self.weigher.setBaudRate(int(self.baud_rate))
        self.weigher.setDataBits(QSerialPort.DataBits(int(self.data_bits)))
        self.weigher.setStopBits(QSerialPort.StopBits(int(self.stop_bits)))

        # Logging module
        self.mylogging = MyLogging(logger_name='user')
        self.mylogger = self.mylogging.logger
示例#8
0
 def __init__(self, port_name=None, baud_rate=None, data_bits=None,
              stop_bits=None):
     # Reading config
     config = read_config()[port_name]
     # Logging module
     self.mylogging = MyLogging(logger_name='user')
     self.mylogger = self.mylogging.logger
     # Configurate door_controller.
     self.door_controller = QSerialPort()
     self.door_controller.setPortName(config['port_name'])
     self.door_controller.setBaudRate(int(config['baud_rate']))
     self.door_controller.setDataBits(int(config['data_bits']))
     self.door_controller.setStopBits(int(config['stop_bits']))
     # Check self.
     self.check()
     # Start to work.
     self.data = QByteArray()
     self.setDataTerminalReady(True)
     self.readyRead.connect(self.acceptData)
示例#9
0
class SelfCheck(BaseCheck):
    # This config is reading by Config.out_config Module. <config dict>
    def __init__(self, cofig):
        super(SelfCheck, self).__init__(config)
        self._config = config
        self._necessary_check = config['necessary_check']
        self.mylogger = MyLogging(logger_name='user').logger
        self._show_cam_item = config['operating_mode']['show_cam_item']
        self.check_status = False

        if int(self.necessary_check['database_check']):
            self.databaseCheck()
        if int(self.necessary_check['internet_check']):
            self._InternetCheck()
        if int(self.necessary_check['gpu_check']):
            self.gpuCheck()

    def cameraCheck(self, cam_object=BaseCamera()):
        if not cam_object.isOpen():
            self.mylogger.error('%s fails inspection [FAILED].' %
                                cam_object.cam_name)

    def weigherCheck(self, weigher_object=Weigher()):
        weigher = weigher_object
        self.weigher = weigher.weigher
        if self.weigher.open(QIODevice.ReadOnly):
            # The QSerial.waitForReadyRead function blocks until new data is available for reading and the readyRead() signal has been emitted.
            # This function returns true if the readyRead() signal is emitted and there is new data available for reading;
            # Otherwise this function returns false (if an error occurred or the operation timed out).

            if self.weigher.waitForReadyRead(8000):  # the unit is millisecond;
                self.weigher.readAll()
                status_data_convert = True
                convert_times = 0
                can_readline_times = 0
                while status_data_convert:
                    if self.weigher.waitForReadyRead(500):
                        if self.weigher.canReadLine():
                            weigher.read()
                            try:
                                # This will raise error if the data can not be converted successfully.
                                status_data_convert = False
                            except BaseException:
                                convert_times = convert_times + 1
                                self.mylogger.warning(
                                    '[Weigher] is trying to '
                                    'convert the data '
                                    'fails with total %s times.' %
                                    convert_times)
                                if convert_times > 29:
                                    self.mylogger.error(
                                        '[Weigher]: the '
                                        'string data given by weigher can not be converted to the float data successfully.'
                                    )
                                    sys.exit()
                        else:
                            can_readline_times = can_readline_times + 1
                            self.mylogger.warning(
                                'canReadLine fails with total %s '
                                'times.' % can_readline_times)
                            if can_readline_times > 29:
                                self.mylogger.error(
                                    'Weigher problem: there is no readLine signal too many times.'
                                )
                                sys.exit()
                    else:
                        convert_times = convert_times + 1
                        self.mylogger.warning(
                            'waitForReadyRead fails with total %s '
                            'times.' % convert_times)
                        if convert_times > 29:
                            self.mylogger.error(
                                'Weigher problem: the string data given by weigher can not be converted to the float data successfully.'
                            )
                            sys.exit()
            else:
                self.mylogger.error(
                    'Weigher problem: no data received from the weigher.')
                sys.exit()
            self.weigher.close()
        else:
            self.mylogger.error(
                'Weigher problem: the connection to the specific weigher fails. Please check the port name.'
            )
            sys.exit()

    def databaseCheck(self):
        pass

    def _InternetCheck(self):
        pass

    def gpuCheck(self):
        pass

    # Private parameters.
    @property
    def config(self):
        return self._config

    @property
    def necessary_check(self):
        return self._necessary_check

    @property
    def show_cam_item(self):
        return self._show_cam_item
示例#10
0
class Save_img_Timer(QThread):
    """
    Send_msg will emit the capture process to capWindow's textBroswer.
    Creat_dirs_msg will emit the new creating dirs to capWindow's textBroswer.

    :param
    parent: It is the who create or init The Save_img_Timer class.
    cap_Objects: a list of all avaliable Cameras on PC.
    time: The time of capturing 32 pics to spend.
    save_dirs: a list of to save dirs to save img by needing.
    img_names: a list of how to save img with your name.
    """
    send_msg = pyqtSignal(str)
    creat_dirs_msg = pyqtSignal(str)

    def __init__(self, parent=None, cap_Objects=None, time=float):
        super(Save_img_Timer, self).__init__()
        self.parent = parent
        self.cap_Objects = cap_Objects
        self.time = time / 32
        self.save_dirs = []
        self.img_names = []
        self.logger = MyLogging(logger_name='user').logger

        for cap_Object in self.cap_Objects:
            self.save_dirs.append(self.parent.save_path + self.parent.cvid + '/'
                                  + cap_Object.label_name + '/' + \
                                  self.parent.direction + '/')

            self.img_names.append(self.parent.cvid + '_' + self.parent.char + '_' + \
                                  self.parent.date + '_' + cap_Object.label_name +\
                                  '_' + self.parent.direction)

        for save_dir in self.save_dirs:
            if not os.path.exists(save_dir):
                os.makedirs(save_dir)
                self.logger.info('Create dir [%s]' % save_dir)
                msg = 'Create dir [%s]' % save_dir
                self.creat_dirs_msg.connect(self.parent.update_textBrowser)
                self.creat_dirs_msg.emit(msg)

        self.index = 1
        self.isStop = False

    def run(self):
        msg = '[CVID]: %s [DIRECTION]: %s [ACTIVED]: Start.' % (
            self.parent.cvid, self.parent.direction)
        self.logger.info(msg)
        self.send_msg.emit(msg)
        num = len(self.cap_Objects)
        while not self.isStop:
            self.imgs = []
            self.file_names = []
            for i in range(num):
                ret, img = self.cap_Objects[i].capture.read()
                file_name = self.img_names[i] + '_' + str(self.index) + '.jpg'
                self.imgs.append(img)
                self.file_names.append(file_name)

            for i in range(num):
                cv2.imwrite(self.save_dirs[i] + self.file_names[i],
                            self.imgs[i])

            msg = '[Cvid]:  %s  [Direction]:  %s  |  ---------->  %d\n' % (
                self.parent.cvid, self.parent.direction, self.index)
            self.send_msg.emit(msg)

            self.index += 1
            time.sleep(self.time)
            if self.index > 32:
                self.isStop = True
                msg = '[CVID]: %s [DIRECTION]: %s [ACTIVED]: End.' % (
                    self.parent.cvid, self.parent.direction)
                self.logger.info(msg)
                self.send_msg.emit(msg)
                self.parent.ui.cap_ok_Button.setEnabled(True)
                break