Beispiel #1
0
class Barrier:
    """
    Implement a barrier, such that threads block until other monitored threads reach a specific location.
    The barrier can be used multiple times (it is reinitialized after the threads passed).

    See https://stackoverflow.com/questions/9637374/qt-synchronization-barrier/9639624#9639624
    """
    def __init__(self, count):
        self.count = count
        self.origCount = count
        self.mutex = QMutex()
        self.condition = QWaitCondition()

    def wait(self):
        """
        Wait until all monitored threads called wait.
        :return: None
        """
        self.mutex.lock()
        self.count -= 1
        if self.count > 0:
            self.condition.wait(self.mutex)
        else:
            self.count = self.origCount
            self.condition.wakeAll()
        self.mutex.unlock()
class TestThread(QThread):
    startRecording = Signal()

    def __init__(self, config, aruco_tester_widget, acs_control, parent=None):
        QThread.__init__(self, parent)
        self.config = config
        self.aruco_tester_widget = aruco_tester_widget
        self.image_miner = aruco_tester_widget.image_miner
        self.acs_control = acs_control

        self.startRecording.connect(self.aruco_tester_widget.onRecordClicked)

        self.recordingStopped = QWaitCondition()
        self.mutex = QMutex()

    @Slot()
    def wake(self):
        self.recordingStopped.wakeAll()
        pass

    def run(self):
        print('starting...')
        base_dir = os.path.dirname(os.path.realpath(__file__))
        config = self.config['config']
        angles = self.config['angles']
        j = 0
            
        self.image_miner.set_video_capture_property('CAP_PROP_BRIGHTNESS', 50.5/100.)
        self.image_miner.set_video_capture_property('CAP_PROP_CONTRAST', 50.5/100.)
        self.image_miner.set_video_capture_property('CAP_PROP_SATURATION', 50.5/100.)

        prop = 'CAP_PROP_BRIGHTNESS'

        print(prop)
        start = config[prop]['start']
        end = config[prop]['end']
        step = config[prop]['step']
        for i in range(start, end+1, step):
            print(i)
            self.image_miner.set_video_capture_property(prop, i/100.)
            series_dir = os.path.join(base_dir, str(prop), str(i), str(self.aruco_tester_widget.use_board))
            j += 1
            
            for angle in angles:
                fileName = os.path.join(series_dir, str(angle))
                print(angle)
                self.acs_control.pa(angle)
                time.sleep(5)
                self.mutex.lock()
                self.startRecording.emit()
                print('wait for recording to stop')
                self.recordingStopped.wait(self.mutex)
                print('saving data to {}'.format(fileName))
                self.aruco_tester_widget.broadcaster.saveToFile(fileName)
                self.mutex.unlock()

            self.acs_control.pa(0)
            time.sleep(10)