Ejemplo n.º 1
0
    def init_camera(self):
        """Initializes the camera connecting to one if possible,
        this is where adjustments need to be made if you want to change the settings."""

        if not self.cam_ctrl.pmd:
            self.cam_ctrl_tx.emit(JMsg('configure_cam', {'ir_stream': {}, 'depth_stream': {}}))
            # self.cam_ctrl_tx.emit(JMsg('depth_stream'))

        self.cam_ctrl_tx.emit(JMsg('start_cam'))
Ejemplo n.º 2
0
    def run(self):
        # self.app = QApplication(sys.argv)

        # Creates the new main window
        # self.window = DisplayWindow()
        self.window.statusBar().showMessage("Initializing...")

        # Sets up the grid layout
        # self.grid = QGridLayout()
        self.grid.setSpacing(10)

        # Creates basic layout widget
        widg = QWidget()
        widg.setLayout(self.grid)
        self.set_widget(JMsg("", widg))

        self.window.setGeometry(300, 300, 500, 400)
        self.window.setWindowTitle('Depth Averaging Utility')
        self.window.statusBar().showMessage('Ready')
        self.window.show()

        # region Sets up the states dict

        self.states['set_widget'] = self.set_widget
        self.states['status'] = self.set_status
        self.states['title'] = self.set_title
        self.states['show'] = self.window.show
        self.states['hide'] = self.window.hide
        self.states['create_button'] = self.create_button
        self.states['create_label'] = self.create_label
        self.states['create_text_entry'] = self.create_line_edit
        self.states['create_slider'] = self.create_slider
        self.states['create_widget'] = self.create_widget
Ejemplo n.º 3
0
    def idle_state(self):

        # Collects and sends off a frame if there isn't anything else the daemon needs to do
        if self.cam is not None and self.cam.isCapturing:
            frames = self.cam.get_frame()
            if frames is not None:
                self.tx.emit(JMsg('frame_update', frames))
Ejemplo n.º 4
0
    def update_slider(self, value: int, slider: str):
        """Updates the value of the adjusted slider"""

        if slider != 'scale':
            value /= self.slider_scale

        self.set_status('Updating slider bars')
        self.data_proc.cmap_up_to_date = False
        self.data_proc.rx.emit(JMsg(slider, value))

        q = queue.Queue()

        def linker():
            global q
            q.put(True)

        sl = self.data_proc.slider_tx.connect(linker)

        while q.empty():
            pass

        self.data_proc.slider_tx.disconnect(sl)

        self.set_slider_limits()
        self.reset_status()
Ejemplo n.º 5
0
    def plot_data(self, msg: JMsg):
        """Plots the frame data onto the window."""

        if msg.data is None:
            print_warning('Trying to display empty frame!')
            return

        img = msg.data[0]
        depth = msg.data[1]
        # print(depth.shape[0], ", ", depth.shape[1])

        img_disp = self.disp_ctrl.widgets['img']
        img_disp.setImage(img)

        if len(self.data_proc.state_queue) < self.data_proc.buffer_limit:

            if self.use_roi:

                # Generates the roi coordinates only if the roi has been changed, this takes a long time (~50 ms)
                if self.roi_coords is None:
                    self.roi_coords = self.roi.getArrayRegion(
                        ct.get_roi_coords_matrix(img.shape[0], img.shape[1]),
                        img_disp.getImageItem())
                    self.data_proc.rx.emit(JMsg('enable_roi', self.roi_coords))

            elif self.roi_coords is not None:
                self.data_proc.rx.emit(JMsg('disable_roi'))

            self.data_proc.rx.emit(JMsg('frame', depth))
            if self.prev_skipped:
                print()
                self.prev_skipped = False
                self.frame_count = 1
                self.set_status('Ready')
        else:
            not_string = "Data processor buffer full, skipping {} cloud frames!".format(
                self.frame_count)

            print_notification(not_string,
                               begin='\r' if self.prev_skipped else '',
                               end='')
            self.prev_skipped = True
            self.frame_count += 1

            self.set_status(not_string)
Ejemplo n.º 6
0
 def create_slider(self, msg: JMsg):
     """Creates a new slider with the given arguments"""
     msg.data['type'] = QSlider
     msg.data['kwargs'] = {'orientation': msg.data['orient']}
     self.create_widget(msg)
Ejemplo n.º 7
0
 def create_line_edit(self, msg: JMsg):
     """Creates a new lineEdit (text entry) box with the given arguments"""
     msg.data['type'] = QLineEdit
     self.create_widget(msg)
Ejemplo n.º 8
0
 def create_label(self, msg: JMsg):
     """Creates a new label with the given arguments"""
     msg.data['type'] = QLabel
     msg.data['kwargs'] = {'text': msg.data['text']}
     self.create_widget(msg)
Ejemplo n.º 9
0
 def create_button(self, msg: JMsg):
     """Creates a new button with the given arguments"""
     msg.data['type'] = QPushButton
     msg.data['kwargs'] = {'text': msg.data['text']}
     self.create_widget(msg)
Ejemplo n.º 10
0
 def set_status(self, message: str):
     """Sets the status bar of the main display"""
     self.disp_ctrl_update.emit(JMsg('status', message))
Ejemplo n.º 11
0
    def init_widget(self):
        """Creates the window layout for the main display"""

        # region Sets up the roi and exit buttons

        self.disp_ctrl_update.emit(JMsg('create_button',
                                   get_text_widg_dict('roi', 'roi_btn', 0, 1, col_span=3,
                                                      tip='Create a new <b>ROI</b> (region of interest)' +
                                                      ' or edit the current one.')))
        #
        # self.disp_ctrl_update.emit(JMsg('create_button',
        #                            get_text_widg_dict('Exit', 'exit_btn', 2, 1, 'Exit the program')))
        # self.disp_ctrl.widgets['exit_btn'].clicked.connect(self.stop)

        # endregion

        # region Sets up the colormap sliders

        self.disp_ctrl_update.emit(JMsg('create_label',
                                   get_text_widg_dict('Max', 'cmap_max_lbl', 4, 1)))
        self.disp_ctrl_update.emit(JMsg('create_slider',
                                   get_slider_widg_dict(Qt.Vertical, 'cmap_max', 5, 1,
                                                        tip='Adjusts the upper saturation limit of the colormap')))
        self.disp_ctrl_update.emit(JMsg('create_label',
                                        get_text_widg_dict('3.0 m', 'cmap_max_lbl_val', 6, 1)))

        self.disp_ctrl_update.emit(JMsg('create_label',
                                   get_text_widg_dict('Mid', 'cmap_mid_lbl', 4, 2)))
        self.disp_ctrl_update.emit(JMsg('create_slider',
                                   get_slider_widg_dict(Qt.Vertical, 'cmap_mid', 5, 2,
                                                        tip='Adjusts the mid-point of the colormap')))
        self.disp_ctrl_update.emit(JMsg('create_label',
                                        get_text_widg_dict('1.5 m', 'cmap_mid_lbl_val', 6, 2)))

        self.disp_ctrl_update.emit(JMsg('create_label',
                                   get_text_widg_dict('Min', 'cmap_min_lbl', 4, 3)))
        self.disp_ctrl_update.emit(JMsg('create_slider',
                                   get_slider_widg_dict(Qt.Vertical, 'cmap_min', 5, 3,
                                                        tip='Adjusts the lower saturation limit of the colormap')))
        self.disp_ctrl_update.emit(JMsg('create_label',
                                        get_text_widg_dict('0.0 m', 'cmap_min_lbl_val', 6, 3)))

        self.disp_ctrl_update.emit(JMsg('create_label',
                                        get_text_widg_dict('Depth Scale: {} x'.format(self.depth_scale_max >> 1),
                                                           'dmp_scale_lbl', 7, 0)))
        self.disp_ctrl.widgets['dmp_scale_lbl'].setAlignment(Qt.AlignLeft)
        self.disp_ctrl_update.emit(JMsg('create_slider',
                                        get_slider_widg_dict(Qt.Horizontal, 'dmp_scale', 6, 0)))

        # endregion

        # region Sets up the depth data labels

        self.disp_ctrl_update.emit(JMsg('create_label',
                                        get_text_widg_dict('Average depth: 0.0 m', 'dmp_avg_lbl', 1, 1, 1, 3)))
        self.disp_ctrl_update.emit(JMsg('create_label',
                                        get_text_widg_dict('Minimum depth: 0.0 m', 'dmp_min_lbl', 2, 1, 1, 3)))
        self.disp_ctrl_update.emit(JMsg('create_label',
                                        get_text_widg_dict('Maximum depth: 0.0 m', 'dmp_max_lbl', 3, 1, 1, 3)))

        # endregion

        # region Sets up the plots

        self.disp_ctrl_update.emit(JMsg('create_label',
                                   get_text_widg_dict('Grayscale', 'img_lbl', 0, 0)))
        self.disp_ctrl_update.emit(JMsg('create_widget',
                                   get_custom_widg_dict(pg.ImageView, 'img', 1, 0, 3, 1)))

        # self.disp_ctrl_update.emit(JMsg('create_label',
        #                                 get_text_widg_dict('Depth Image', 'dimg_lbl', 0, 1)))
        # args = get_custom_widg_dict(pg.ImageView, 'dimg', 1, 1, 1, 3)
        # self.disp_ctrl_update.emit(JMsg('create_widget',
        #                                 args))

        self.disp_ctrl_update.emit(JMsg('create_label',
                                   get_text_widg_dict('Point Cloud', 'dmp_lbl', 4, 0)))
        self.disp_ctrl_update.emit(JMsg('create_widget',
                                   get_custom_widg_dict(pgl.GLViewWidget, 'dmp', 5, 0)))

        self.scatter = pgl.GLScatterPlotItem(pos=np.zeros(shape=(307200, 3), dtype=float), size=3)
        self.disp_ctrl.widgets['dmp'].addItem(self.scatter)

        # region view formatting

        self.scatter.rotate(180, 0, 0, 0)
        self.scatter.setGLOptions('opaque')
        widg = self.disp_ctrl.widgets['dmp']
        # widg.mouseReleaseEvent = lambda v: self.update_center_display()
        widg.pan(-320, -240, 0)
        widg.setCameraPosition(distance=1746, elevation=43, azimuth=-479)

        # endregion

        # endregion

        # Sets up the filename bar

        self.disp_ctrl_update.emit(JMsg('create_text_entry',
                                        get_text_entry_widg_dict('file_entry', 7, 1, 1, 3,
                                                                 tip='Enter a video filename to load in.')))