Beispiel #1
0
    def __init__(self):
        """Setup this app."""
        ShowBase.__init__(self)

        #Setup window
        wnd_props = WindowProperties()
        wnd_props.set_title("Neo Impressive Title")
        #wnd_props.set_origin(0, 0)
        wnd_props.set_size(1024, 768)
        self.win.request_properties(wnd_props)

        self.set_background_color(0, .5, 1, 1)

        #Init GUI sub-system
        self.gui = GUI(self)
        self.gui.run()

        #Init app state
        self.state = APP_STATE_LOGO
        self.logo_delay = 600

        #Start title music
        self.title_music = loader.loadMusic("./data/sounds/title.ogg")
        self.title_music.set_loop(True)
        self.title_music.play()

        #Setup collision detection
        self.cTrav = CollisionTraverser()

        self.portal_handler = CollisionHandlerEvent()
        self.portal_handler.add_in_pattern("%fn-entered-%in")

        #Init other sub-systems
        self.cam_mgr = CameraManager()
        self.world_mgr = WorldManager()

        #Setup lighting
        self.ambient = AmbientLight("Ambient Light")
        self.ambient.set_color(Vec4(.5, .5, .5, 1))
        self.ambient_np = self.render.attach_new_node(self.ambient)
        self.render.set_light(self.ambient_np)

        self.sun = DirectionalLight("Sun")
        self.sun_np = self.render.attach_new_node(self.sun)
        self.sun_np.set_p(-135)
        self.render.set_light(self.sun_np)

        #Setup auto-shaders
        self.render.set_shader_auto()

        #Debug stats
        #self.messenger.toggle_verbose()
        PStatClient.connect()
Beispiel #2
0
    def __init__(self, *args):
        super(Radar_Viewer, self).__init__(*args)
        self.cam_manager = CameraManager()
        self.uart_cfg = UartConfig("COM0")

        # load main ui
        self.radar_viewer = loadUi("./ui/radar_viewer.ui", self)
        self.init_menu()
        self.init_main_page()
        self.init_image_page()

        # initial threads and timers
        self.init_threads()
        self.init_timers()
    def __init__(self):

        self.log = Log()
        self.face_reg = FaceReg("file_path", self.log)
        self.arrangement_reader = ArrangementReader(self.log)
        self.camera_manager = CameraManager(self.log)
        self.tts = self.log.tts

        self.is_end = False

        self.sign_result = {
            "扫地": {},
            "拖地": {},
            "杂物间+柜台": {},
            "摆桌椅": {},
            "窗户+窗台": {},
            "图书角+黑板+讲台": {},
            "倒垃圾": {}
        }
Beispiel #4
0
class Radar_Viewer(QMainWindow):
    #save_signal = pyqtSignal(bool)
    x = np.array([])
    y = np.array([])

    def __init__(self, *args):
        super(Radar_Viewer, self).__init__(*args)
        self.cam_manager = CameraManager()
        self.uart_cfg = UartConfig("COM0")

        # load main ui
        self.radar_viewer = loadUi("./ui/radar_viewer.ui", self)
        self.init_menu()
        self.init_main_page()
        self.init_image_page()

        # initial threads and timers
        self.init_threads()
        self.init_timers()
        # self.showFullScreen()
        # self.showMaximized()

    def init_menu(self):
        # init menu
        self.radar_viewer.actionCamera_Setting.triggered.connect(
            self.start_camera_setting_dialog)
        self.radar_viewer.actionRadar_Setting.triggered.connect(
            self.start_serial_setting_dialog)
        self.radar_viewer.actionAbout.triggered.connect(
            self.start_about_dialog)

    def init_radar_axis_para(self):
        self.radar_max_x_abs = 10
        self.radar_max_y_abs = 80
        self.radar_y_max = self.radar_max_y_abs
        self.radar_y_min = 0
        self.radar_x_max = self.radar_max_x_abs
        self.radar_x_min = -self.radar_max_x_abs

        self.initial_startx = -5
        self.initial_starty = 0
        self.initial_width = 10
        self.initial_deepth = 10

    def draw_axis(self):
        self.qtfig.axes.axis([
            self.radar_x_min, self.radar_x_max, self.radar_y_min,
            self.radar_y_max
        ])
        self.qtfig.axes.grid(color='deepskyblue',
                             linestyle='dashed',
                             linewidth=1,
                             alpha=0.3)
        self.qtfig.axes.spines['top'].set_visible(False)  # 去掉上边框
        self.qtfig.axes.spines['right'].set_visible(False)  # 去掉右边框
        self.qtfig.axes.spines['left'].set_position(('axes', 0.5))
        self.qtfig.fig.tight_layout()

    def draw_capture_area(self):
        self.rect = plt.Rectangle((self.radar_startx, self.radar_starty),
                                  self.radar_capture_width,
                                  self.radar_capture_deepth,
                                  linewidth=1,
                                  edgecolor='r',
                                  facecolor='r')
        self.rect.set_alpha(0.3)
        self.qtfig.axes.add_patch(self.rect)

    def delete_capture_area(self):
        [p.remove() for p in reversed(self.qtfig.axes.patches)]

    def handle_radar_capture_area_setting(self):
        self.cv_trigger_enable = False
        self.radar_trigger_enable = False
        self.obstacle_in_area = False

        radar_startx = float(self.radar_viewer.lineEdit_radar_startx.text())
        radar_starty = float(self.radar_viewer.lineEdit_radar_starty.text())
        radar_capture_width = float(
            self.radar_viewer.lineEdit_radar_capture_width.text())
        radar_capture_deepth = float(
            self.radar_viewer.lineEdit_radar_capture_deepth.text())

        if (abs(radar_startx) < self.radar_max_x_abs or -radar_startx == self.radar_max_x_abs) \
                and 0 <= radar_starty < self.radar_y_max \
                and radar_startx + radar_capture_width <= self.radar_max_x_abs \
                and radar_starty + radar_capture_deepth <= self.radar_y_max \
                and radar_capture_width > 0 \
                and radar_capture_deepth > 0:
            self.radar_startx = radar_startx
            self.radar_starty = radar_starty
            self.radar_capture_width = radar_capture_width
            self.radar_capture_deepth = radar_capture_deepth

            self.delete_capture_area()
            self.draw_capture_area()
        else:
            print("invalid area")

    def load_radar_axis(self):
        self.init_radar_axis_para()
        self.qtfig = QtFigure(width=6, height=4, dpi=100)
        self.gridlayout = QGridLayout(self.radar_viewer.groupBox_radar)
        self.gridlayout.addWidget(self.qtfig)
        self.draw_axis()
        self.scatter_collection = None
        self.texts = None
        self.handle_radar_capture_area_setting()

    def set_cv_detector(self):
        if self.radar_viewer.checkBox_detector_switch.checkState(
        ) == Qt.Checked:
            self.detector_enable = True
            self.detector_thread.set_enable(True)

        elif self.radar_viewer.checkBox_detector_switch.checkState(
        ) == Qt.Unchecked:
            self.detector_enable = False
            self.detector_thread.set_enable(False)

    def set_cv_trigger(self):
        if self.radar_viewer.checkBox_cv_trigger.checkState() == Qt.Checked:
            self.cv_trigger_enable = True
        elif self.radar_viewer.checkBox_cv_trigger.checkState(
        ) == Qt.Unchecked:
            self.cv_trigger_enable = False

    def set_radar_trigger(self):
        if self.radar_viewer.checkBox_radar_trigger.checkState() == Qt.Checked:
            self.radar_trigger_enable = True
        elif self.radar_viewer.checkBox_radar_trigger.checkState(
        ) == Qt.Unchecked:
            self.radar_trigger_enable = False

    def init_main_ui_setting(self):
        self.detector_enable = False
        self.cv_trigger_enable = False
        self.radar_viewer.checkBox_cv_trigger.setEnabled(False)
        self.set_cv_trigger()
        self.set_radar_trigger()

        self.radar_viewer.checkBox_detector_switch.setEnabled(False)

        # init setting
        self.radar_viewer.checkBox_detector_switch.stateChanged.connect(
            self.set_cv_detector)
        self.radar_viewer.checkBox_cv_trigger.stateChanged.connect(
            self.set_cv_trigger)
        self.radar_viewer.checkBox_radar_trigger.stateChanged.connect(
            self.set_radar_trigger)
        # self.radar_viewer.checkBox_save_picture_auto.stateChanged.connect(self.set_save_picture_auto)

        re_float = QRegExp("(-*[1-9][0-9]{0,2}|0)([\.][0-9]{1,2})*")
        re_validato = QRegExpValidator(re_float, self)  # 实例化正则验证器
        self.radar_viewer.lineEdit_radar_startx.setValidator(
            re_validato)  # 设置验证
        self.radar_viewer.lineEdit_radar_startx.move(50, 90)
        self.radar_viewer.lineEdit_radar_starty.setValidator(
            re_validato)  # 设置验证
        self.radar_viewer.lineEdit_radar_starty.move(50, 90)
        self.radar_viewer.lineEdit_radar_capture_width.setValidator(
            re_validato)  # 设置验证
        self.radar_viewer.lineEdit_radar_capture_width.move(50, 90)
        self.radar_viewer.lineEdit_radar_capture_deepth.setValidator(
            re_validato)  # 设置验证
        self.radar_viewer.lineEdit_radar_capture_deepth.move(50, 90)

        self.radar_viewer.lineEdit_radar_startx.setText(
            str(self.initial_startx))
        self.radar_viewer.lineEdit_radar_starty.setText(
            str(self.initial_starty))
        self.radar_viewer.lineEdit_radar_capture_width.setText(
            str(self.initial_width))
        self.radar_viewer.lineEdit_radar_capture_deepth.setText(
            str(self.initial_deepth))

        self.radar_viewer.lineEdit_radar_startx.returnPressed.connect(
            self.handle_radar_capture_area_setting)
        self.radar_viewer.lineEdit_radar_starty.returnPressed.connect(
            self.handle_radar_capture_area_setting)
        self.radar_viewer.lineEdit_radar_capture_width.returnPressed.connect(
            self.handle_radar_capture_area_setting)
        self.radar_viewer.lineEdit_radar_capture_deepth.returnPressed.connect(
            self.handle_radar_capture_area_setting)

        self.radar_viewer.horizontalSlider_video_brightness.setRange(0, 200)
        self.radar_viewer.horizontalSlider_video_contrast.setRange(0, 100)
        self.radar_viewer.horizontalSlider_video_brightness.setValue(
            self.cam_manager.brightness)
        self.radar_viewer.horizontalSlider_video_contrast.setValue(
            self.cam_manager.contrast)
        self.radar_viewer.horizontalSlider_video_brightness.valueChanged.connect(
            self.set_video_brightness)
        self.radar_viewer.horizontalSlider_video_contrast.valueChanged.connect(
            self.set_video_contrast)

    def init_main_page(self):
        self.radar_viewer.tab_widget.setCurrentIndex(0)
        self.load_radar_axis()
        self.init_main_ui_setting()

    def init_image_page(self):
        self.img_queue = deque()
        self.current_image_index = -1
        imgs_list = glob.glob(IMG_PATH + "/*.jpg")
        imgs_list.sort(key=lambda f: os.path.getctime(f))
        self.img_queue.clear()
        self.img_queue.extend(imgs_list)
        self.show_image(self.current_image_index)
        self.radar_viewer.pushButton_pre.clicked.connect(self.pre_image)
        self.radar_viewer.pushButton_next.clicked.connect(self.next_image)

    def init_threads(self):
        self.camera_image_queue = deque(maxlen=6)
        self.detector_output_queue = deque(maxlen=3)
        self.detector_thread = DetectorThread(self, self.camera_image_queue,
                                              self.detector_output_queue,
                                              self.radar_viewer.label_video,
                                              False)
        #self.detector_thread.start()

        self.detector_thread.yolo_initial_finished.connect(
            self.set_detector_enable)

        #self.save_signal.connect(self.detector_thread.save_img_flag)

        #self.detector_process = DetectorProcess(self.camera_image_queue, self.detector_output_queue, False)
        #self.detector_process.start()
        #self.detector_process.yolo_initial_finished.connect(self.set_detector_enable)

        self.camera_thread = CameraThread(self, self.cam_manager.cam,
                                          self.camera_image_queue)
        self.camera_thread.start()

        self.com = None
        self.radar_receive_thread = None

    def init_timers(self):
        self.frame_update_timer = QTimer(self)
        self.frame_update_timer.timeout.connect(self.display_image)
        self.frame_update_timer.start(60)

        self.radar_update_timer = QTimer(self)
        self.radar_update_timer.timeout.connect(
            self.update_radar_from_obj_queue)
        #self.radar_update_timer.start(30)

    def start_camera_setting_dialog(self):
        self.camera_setting_dialog = camera_setting.CameraSettingDialog(
            self.cam_manager)
        self.camera_setting_dialog.camera_setting_signal.connect(
            self.update_camera_info)
        self.camera_setting_dialog.show()

    def start_serial_setting_dialog(self):
        try:
            if self.com:
                if self.radar_receive_thread:
                    self.radar_receive_thread.exit()
                self.com.close()

            self.serial_setting_dialog = serial_setting.SerialSettingDialog(
                self.uart_cfg)
            self.serial_setting_dialog.serial_setting_signal.connect(
                self.update_uart_info)
            self.serial_setting_dialog.show()
        except Exception as e:
            print(e)

    def start_about_dialog(self):
        self.about_dialog = about.AboutDialog()
        self.about_dialog.show()

    def update_camera_info(self, camera_config_msg):
        #self.frame_update_timer.stop()

        self.cam_manager.framerate = camera_config_msg.framerate
        self.cam_manager.resolution[0] = camera_config_msg.resolution[0]
        self.cam_manager.resolution[1] = camera_config_msg.resolution[1]
        self.cam_manager.brightness = camera_config_msg.brightness
        self.cam_manager.contrast = camera_config_msg.contrast
        self.cam_manager.gain = camera_config_msg.gain
        self.cam_manager.update_camera_info(camera_config_msg.id)

        self.radar_viewer.horizontalSlider_video_brightness.setValue(
            self.cam_manager.brightness)
        self.radar_viewer.horizontalSlider_video_contrast.setValue(
            self.cam_manager.contrast)

        #self.frame_update_timer.start()

        self.camera_thread.set_cam(self.radar_viewer.cam_manager.cam)
        self.camera_thread.start()

    def update_uart_info(self, uart_config_msg):
        self.radar_update_timer.stop()
        self.uart_cfg = uart_config_msg
        self.com = UartManager.create_instance(self.uart_cfg)

        self.radar_receive_thread = radar.RadarReceiveThread(self, self.com)
        self.radar_msg_process_thread = radar.RadarMsgProcessThread(self)

        self.radar_receive_thread.start()
        self.radar_msg_process_thread.start()

        self.radar_update_timer.start(60)

    def set_video_brightness(self):
        self.cam_manager.brightness = self.radar_viewer.horizontalSlider_video_brightness.value(
        )
        self.cam_manager.cam.set_brightness(self.cam_manager.brightness)

    def set_video_contrast(self):
        self.cam_manager.contrast = self.radar_viewer.horizontalSlider_video_contrast.value(
        )
        self.cam_manager.cam.set_contrast(self.cam_manager.contrast)

    def set_detector_enable(self, *args):
        detector_finished_flag = args[0]
        if detector_finished_flag == True:
            self.radar_viewer.checkBox_detector_switch.setEnabled(True)
            self.radar_viewer.checkBox_cv_trigger.setEnabled(True)
        else:
            self.radar_viewer.checkBox_detector_switch.setEnabled(False)
            self.radar_viewer.checkBox_cv_trigger.setEnabled(False)

    def clear_scatter(self):
        if self.scatter_collection:
            self.scatter_collection.remove()
            self.qtfig.fig.canvas.draw_idle()
            del self.scatter_collection
            self.scatter_collection = None

    def plot_scatter(self, x, y):
        [text.remove() for text in reversed(self.qtfig.axes.texts)]
        try:
            self.clear_scatter()

            self.scatter_collection = self.qtfig.axes.scatter(x, y, c='red')
        except Exception as e:
            print("scatter err")
            print(e)

        for x1, y1 in zip(x, y):
            self.qtfig.axes.text(x1, y1,
                                 '({},{})'.format(round(x1, 1), round(y1, 1)))

    # def update_radar(self, *args):
    #     #print(args)
    #     x, y, x_size, y_size = args[0]
    #     #plt.clf()
    #     self.plot_scatter(x, y)
    #
    #     for x1, y1 in zip(x, y):
    #         if self.radar_startx <= x1 <= self.radar_startx + self.radar_capture_width \
    #                 and self.radar_starty <= y1 <= self.radar_starty + self.radar_capture_deepth:
    #             self.obstacle_in_area = True
    #             return

    def update_radar_from_obj_queue(self):
        radar_update_start_time = time.time()
        # print('radar update time:',radar_update_start_time)
        try:
            # print("radar obj msg queue:", len(radar.radar_obj_msg_queue))
            if len(radar.radar_obj_msg_queue) == 0:
                self.clear_scatter()
                return

            self.x, self.y, x_size, y_size = radar.radar_obj_msg_queue.popleft(
            )
            self.plot_scatter(self.x, self.y)

            for x1, y1 in zip(self.x, self.y):
                if self.radar_startx <= x1 <= self.radar_startx + self.radar_capture_width \
                        and self.radar_starty <= y1 <= self.radar_starty + self.radar_capture_deepth:
                    self.obstacle_in_area = True
                    #self.save_signal.emit(True)
                    return

        except IndexError as e:
            #print('queue is empty')
            self.clear_scatter()
            #print(e)
        except Exception as e:
            #print('other err')
            print(e)

        finally:
            pass
            #print('radar update cost time:', time.time() - radar_update_start_time)

    def display_image(self):
        start_time = time.time()
        try:
            start_time = time.time()
            pixmap = None
            if self.detector_enable:
                print('detector output queue len:',
                      len(self.detector_output_queue))
                if len(self.detector_output_queue) > 0:
                    pixmap = self.detector_output_queue.popleft()
                    return
            else:
                #print('camera image queue len:',len(self.camera_image_queue))
                if len(self.camera_image_queue) > 0:
                    frame = self.camera_image_queue.popleft()

                    # if self.x.size:
                    #     rvec = np.array([0,0,0], np.float32)
                    #     tvec = np.array([0,0,0], np.float32)
                    #     objp = np.zeros((1,3), np.float32)
                    #     objp[0][0],objp[0][1] = self.x, self.y
                    #     imagePoints,_ = cv.projectPoints(objp, rvec, tvec, mtx, dist)
                    #     point = np.array(imagePoints[0][0][:]).astype(int)
                    #     print('point:',point)
                    #     cv.circle(frame, tuple(point), 2, (0, 0, 255), 4)

                    frame = cv.resize(frame, (1280, 720))
                    frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
                    image = QImage(frame.data, frame.shape[1], frame.shape[0],
                                   QImage.Format_RGB888)
                    pixmap = QPixmap.fromImage(image)
                    self.radar_viewer.label_video.setPixmap(pixmap)
                else:
                    return

            self.radar_viewer.label_video.setPixmap(pixmap)
            #print("display time cost:",time.time() - start_time)
        except Exception as e:
            print(e)

        #print('display cost time:', time.time() - start_time)
        # ret, frame = self.cam_manager.cam.take_photo()
        # if ret == True:
        #     # gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
        #         #     # 找到棋盘格角点
        #     # ret, corners = cv.findChessboardCorners(gray, (CHESSBOARD_W_NUM, CHESSBOARD_H_NUM), None)
        #     # if ret == True:
        #     #     cv.cornerSubPix(gray, corners, (11, 11), (-1, -1), CRITERIA)
        #     #     cv.drawChessboardCorners(frame, (w, h), corners, ret)
        #
        #     #imagePoints = cv.projectPoints(objectPoints, rvec, tvec, mtx, dist)
        #
        #     self.exist_person = False
        #     if self.detector_enable:
        #         detector_input_queue.append(frame)
        #         frame = detector_input_queue.popleft()
        #         # start = time.time()
        #         # frame1 = Image.fromarray(frame)
        #         # _, self.exist_person = self.detector.detect_image(frame1)
        #         # frame = np.asarray(frame1)
        #         # stop = time.time()
        #         # print("detector processing time:",stop - start)
        #         # self.frame_update_timer.stop()
        #
        #     display_queue.append(frame)
        #
        #     #point = np.array(imagePoints[0][0, 0, :]).astype(int)
        #     #cv.circle(frame, tuple(point), 2, (0, 0, 255), 4)
        #
        #     #cv.rectangle(frame, tuple(point - 20), tuple(point + 20), (0, 255, 0), 3)
        #     #cv.putText(frame, "({},{}),1.2m/s".format(objectPoints[0, 0] / 1000, objectPoints[0, 2] / 1000),
        #     #           (point[0] - 20, point[1] - 25), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 1)
        #
        #     # self.frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
        #     # # print(type(self.frame))
        #     # stored_flag = False
        #     # if self.cv_trigger_enable:
        #     #     if self.exist_person:
        #     #         self.save_img(self.frame)
        #     #         stored_flag = True
        #     #
        #     # if self.radar_trigger_enable and not stored_flag:
        #     #     if self.obstacle_in_area:
        #     #         self.obstacle_in_area = False
        #     #         self.save_img(self.frame)
        #     #
        #     # self.image = QImage(self.frame.data, self.frame.shape[1], self.frame.shape[0], QImage.Format_RGB888)
        #     # self.pixmap = QPixmap.fromImage(self.image)
        #     # # self.scaled_pixmap = self.pixmap.scaled(
        #     # #     self.video_width, self.video_height, aspectRatioMode=Qt.KeepAspectRatioByExpanding,
        #     # #     transformMode=Qt.SmoothTransformation)
        #     # self.radar_viewer.label_video.setPixmap(self.pixmap)

    # def set_save_picture_auto(self):
    #     if self.radar_viewer.checkBox_save_picture_auto.checkState() == Qt.Checked:
    #         self.save_picture_auto = True
    #     elif self.radar_viewer.checkBox_save_picture_auto.checkState() == Qt.Unchecked:
    #         self.save_picture_auto = False

    # def resizeEvent(self, event):
    #     # print("resize event")
    #     pass
    def pre_image(self):
        if len(self.img_queue):
            self.current_image_index = -1 if self.current_image_index + 1 < -len(
                self.img_queue) else self.current_image_index - 1
            self.show_image(self.current_image_index)

    def next_image(self):
        if len(self.img_queue):
            self.current_image_index = -len(
                self.img_queue
            ) if self.current_image_index + 1 > -1 else self.current_image_index + 1
            self.show_image(self.current_image_index)

    def save_img(self, img):
        filename = time.ctime().replace(":", " ")
        img_name = "{}\\{}.jpg".format(os.path.realpath(IMG_PATH), filename)
        if cv.imwrite(img_name, img):
            self.img_queue.append(img_name)
            self.show_image(self.current_image_index)

    def show_image(self, index):
        try:
            if len(self.img_queue):
                newest_img = self.img_queue[index]
                frame = cv.imread(newest_img, cv.COLOR_BGR2RGB)
                image = QImage(frame.data, frame.shape[1], frame.shape[0],
                               QImage.Format_RGB888)
                pixmap = QPixmap.fromImage(image)
                scaled_pixmap = pixmap.scaled(
                    IMAGE_WIDTH,
                    IMAGE_HEIGHT,
                    aspectRatioMode=Qt.KeepAspectRatioByExpanding,
                    transformMode=Qt.SmoothTransformation)
                self.radar_viewer.label_photo.setPixmap(scaled_pixmap)
        except Exception as e:
            print(e)
class Init:

    def __init__(self):

        self.log = Log()
        self.face_reg = FaceReg("file_path", self.log)
        self.arrangement_reader = ArrangementReader(self.log)
        self.camera_manager = CameraManager(self.log)
        self.tts = self.log.tts

        self.is_end = False

        self.sign_result = {
            "扫地": {},
            "拖地": {},
            "杂物间+柜台": {},
            "摆桌椅": {},
            "窗户+窗台": {},
            "图书角+黑板+讲台": {},
            "倒垃圾": {}
        }

    def time_count(self, second, callback):

        """
        计时器
        :param second: 计算的秒数
        :param callback: 时间到以后的callback
        :return:
        """
        self.log.add_log("Init: Start time count for" + str(second), 1)
        time.sleep(second)
        callback()

    def generate_report(self):

        """
        开始生成报告
        :return:
        """
        json.dump(self.sign_result, open("./data/json/report.json", "w", encoding="utf-8"))

    def init_sign_window(self):

        """
        初始化签名窗口
        :return:
        """

        # INIT THE SIGN WINDOW
        window = Tk()
        window.title("自动签到系统")
        window.geometry('1024x600')

        # SET THE NOTICE LABLE
        notice = Label(window, text="请点击按钮并签到", font=("Helvetica", 20))
        notice.pack(side=TOP)

        # 摆桌椅Frame
        desk_place = Frame(window, height=25)
        desc_desk = Label(desk_place, text="摆桌椅签名区", font=("Helvetica", 15))
        desc_desk.pack(side=TOP)
        row_1_button = Button(desk_place, height=10, width=10, command=lambda : self.sign(1, 1), text="列1")
        row_1_button.pack(side=LEFT)
        row_2_button = Button(desk_place, height=10, width=10, command=lambda: self.sign(1, 2), text="列2")
        row_2_button.pack(side=LEFT)
        row_3_button = Button(desk_place, height=10, width=10, command=lambda: self.sign(1, 3), text="列3")
        row_3_button.pack(side=LEFT)
        row_4_button = Button(desk_place, height=10, width=10, command=lambda: self.sign(1, 4), text="列4")
        row_4_button.pack(side=LEFT)
        row_5_button = Button(desk_place, height=10, width=10, command=lambda: self.sign(1, 5), text="列5")
        row_5_button.pack(side=LEFT)
        row_6_button = Button(desk_place, height=10, width=10, command=lambda: self.sign(1, 6), text="列6")
        row_6_button.pack(side=LEFT)
        row_7_button = Button(desk_place, height=10, width=10, command=lambda: self.sign(1, 7), text="列7")
        row_7_button.pack(side=LEFT)
        row_8_button = Button(desk_place, height=10, width=10, command=lambda: self.sign(1, 8), text="列8")
        row_8_button.pack(side=LEFT)

        desk_place.pack(side=TOP)

        # 窗户+窗台签名区
        window_place = Frame(window, height=25)
        window_desk = Label(window_place, text="窗户+窗台签名区", font=("Helvetica", 15))
        window_desk.pack(side=TOP)
        row_1_button = Button(window_place, height=10, width=10, command=lambda: self.sign(2, 1), text="窗1")
        row_1_button.pack(side=LEFT)
        row_2_button = Button(window_place, height=10, width=10, command=lambda: self.sign(2, 2), text="窗2")
        row_2_button.pack(side=LEFT)
        row_3_button = Button(window_place, height=10, width=10, command=lambda: self.sign(2, 3), text="窗3")
        row_3_button.pack(side=LEFT)
        row_4_button = Button(window_place, height=10, width=10, command=lambda: self.sign(2, 4), text="窗4")
        row_4_button.pack(side=LEFT)

        window_place.pack(side=TOP)

        # 黑板签名区
        bb_place = Frame(window, height=25, width=50)
        bb_notice = Label(bb_place, text="黑板+图书角签名区", font=("Helvetica", 15))
        bb_notice.pack(side=TOP)
        button = Button(bb_place, height=10, width=10, command=lambda: self.sign(3, 1), text="点ME")
        button.pack(side=LEFT)

        # ATTENTION: PACK IN THE END

        # 扫地签名
        sweep_place = Frame(window, height=25)
        sweep_notice = Label(sweep_place, text="扫地签名区", font=("Helvetica", 15))
        sweep_notice.pack(side=TOP)
        row_1_button = Button(sweep_place, height=10, width=10, command=lambda: self.sign(4, 1), text="列1")
        row_1_button.pack(side=LEFT)
        row_2_button = Button(sweep_place, height=10, width=10, command=lambda: self.sign(4, 2), text="列2")
        row_2_button.pack(side=LEFT)
        row_3_button = Button(sweep_place, height=10, width=10, command=lambda: self.sign(4, 3), text="列3")
        row_3_button.pack(side=LEFT)
        row_4_button = Button(sweep_place, height=10, width=10, command=lambda: self.sign(4, 4), text="列4")
        row_4_button.pack(side=LEFT)
        row_5_button = Button(sweep_place, height=10, width=10, command=lambda: self.sign(4, 5), text="列5")
        row_5_button.pack(side=LEFT)
        row_6_button = Button(sweep_place, height=10, width=10, command=lambda: self.sign(4, 6), text="列6")
        row_6_button.pack(side=LEFT)
        row_7_button = Button(sweep_place, height=10, width=10, command=lambda: self.sign(4, 7), text="列7")
        row_7_button.pack(side=LEFT)
        row_8_button = Button(sweep_place, height=10, width=10, command=lambda: self.sign(4, 8), text="列8")
        row_8_button.pack(side=LEFT)
        row_9_button = Button(sweep_place, height=10, width=10, command=lambda: self.sign(4, 9), text="后面+讲台")
        row_9_button.pack(side=LEFT)

        sweep_place.pack(side=TOP)

        # 拖地签名
        mop_place = Frame(window, height=25)
        mop_notice = Label(window, text="拖地签名区", font=("Helvetica", 15))
        mop_notice.pack(side=TOP)
        row_1_button = Button(mop_place, height=10, width=10, command=lambda: self.sign(5, 1), text="列1")
        row_1_button.pack(side=LEFT)
        row_2_button = Button(mop_place, height=10, width=10, command=lambda: self.sign(5, 2), text="列2")
        row_2_button.pack(side=LEFT)
        row_3_button = Button(mop_place, height=10, width=10, command=lambda: self.sign(5, 3), text="列3")
        row_3_button.pack(side=LEFT)
        row_4_button = Button(mop_place, height=10, width=10, command=lambda: self.sign(5, 4), text="列4")
        row_4_button.pack(side=LEFT)
        row_5_button = Button(mop_place, height=10, width=10, command=lambda: self.sign(5, 5), text="列5")
        row_5_button.pack(side=LEFT)
        row_6_button = Button(mop_place, height=10, width=10, command=lambda: self.sign(5, 6), text="列6")
        row_6_button.pack(side=LEFT)
        row_7_button = Button(mop_place, height=10, width=10, command=lambda: self.sign(5, 7), text="列7")
        row_7_button.pack(side=LEFT)
        row_8_button = Button(mop_place, height=10, width=10, command=lambda: self.sign(5, 8), text="列8")
        row_8_button.pack(side=LEFT)
        row_8_button = Button(mop_place, height=10, width=10, command=lambda: self.sign(5, 9), text="后面+讲台")
        row_8_button.pack(side=LEFT)

        mop_place.pack(side=TOP)

        # 倒垃圾签名
        trash_place = Frame(window, height=25, width=50)
        trash_notice = Label(trash_place, text="倒垃圾签名区", font=("Helvetica", 15))
        trash_notice.pack(side=TOP)
        button = Button(trash_place, height=10, width=10, command=lambda: self.sign(6, 1), text="点ME")
        button.pack(side=LEFT)

        trash_place.pack(side=LEFT)

        # 杂物间签名区
        room_place = Frame(window, height=25, width=50)
        room_notice = Label(room_place, text="杂物间签名区", font=("Helvetica", 15))
        room_notice.pack(side=TOP)
        button = Button(room_place, height=10, width=10, command=lambda: self.sign(7, 1), text="点ME")
        button.pack(side=LEFT)

        room_place.pack(side=LEFT)

        bb_place.pack(side=LEFT)

        # RUN THE WINDOW
        window.mainloop()

    def sign(self, command, row):

        """
        进行签名
        :param command: 签到模式
        :param row: 列数
        :return:
        """
        img = self.camera_manager.capture_image()
        self.camera_manager.show_image(img)

        self.generate_report()
        detect_res = self.face_reg.face_detect(self.face_reg.read_img("img.jpg"))
        try:
            face_num = detect_res["result"]["face_num"]
        except KeyError:
            print(detect_res)
            raise KeyError

        while True:
            if face_num == 0:
                self.tts.start("没有检测到人脸,请对准摄像头重拍")
            else:
                # self.tts.start("Face Detected. Start searching...")
                break

        search_res = self.face_reg.face_search(self.face_reg.read_img("img.jpg"))
        try:
            user_id = search_res["result"]["user_list"][0]["user_id"]
        except:
            print(search_res)
            raise KeyError

        if command == 1:
            index = self.arrangement_reader.get_index(self.arrangement_reader.get_name(int(user_id)),
                                                      self.arrangement_reader.class_arrangement["摆桌椅"])
            if index is False:
                self.tts.start("你可不是干这个的啊!")
                return
            if index + 1 == int(row):
                self.sign_result["摆桌椅"][index] = True
                self.tts.start("签到完成")

                next_name = self.arrangement_reader.class_arrangement["扫地"][index]
                self.tts.start("请" + next_name + "同学开始扫地")
                self.tts.start("你负责的是" + str(index + 1) + "列,要扫干净哦!第九列是指教室的后面和讲台")

            else:
                self.tts.start("错误的人脸和对应列数!")
        elif command == 2:
            index = self.arrangement_reader.get_index(self.arrangement_reader.get_name(int(user_id)),
                                                      self.arrangement_reader.class_arrangement["窗户+窗台"])
            if index is False:
                self.tts.start("你可不是干这个的啊!")
                return

            if index + 1 == int(row):
                self.sign_result["窗户+窗台"][index] = True
                self.tts.start("签到完成")
            else:
                self.tts.start("错误的人脸和对应窗户号!")
        elif command == 3:
            index = self.arrangement_reader.get_index(self.arrangement_reader.get_name(int(user_id)),
                                                      self.arrangement_reader.class_arrangement["图书角+黑板+讲台"])
            if index is False:
                self.tts.start("你可不是干这个的啊!")
                return

            self.sign_result["图书角+黑板+讲台"][index] = True
            self.tts.start("签到完成")
        elif command == 4:
            index = self.arrangement_reader.get_index(self.arrangement_reader.get_name(int(user_id)),
                                                      self.arrangement_reader.class_arrangement["扫地"])
            if index is False:
                self.tts.start("你可不是干这个的啊!")
                return

            if index + 1 == int(row):
                try:
                    if self.sign_result["摆桌椅"][index] is True:

                        self.sign_result["扫地"][index] = True
                        self.tts.start("签到完成")

                        next_name = self.arrangement_reader.class_arrangement["拖地"][index]
                        self.tts.start("请" + next_name + "同学开始拖地")
                        self.tts.start("你负责的是" + str(index + 1) + "列,要拖干净哦!第九列是指教室的后面和讲台")

                        is_end = True
                        for i in self.sign_result["扫地"].keys():
                            if self.sign_result["扫地"][i] is False:
                                is_end = False
                        if is_end:
                            trash = self.arrangement_reader.get_names(self.arrangement_reader.class_arrangement["倒垃圾"])

                            self.tts.start(trash)
                            self.tts.start("请这些同学现在开始倒垃圾")
                except KeyError:
                    self.tts.start("摆桌椅的还没摆完呢!")
                    return
                else:
                    self.tts.start("你的任务还没有开始呢!")
                    # c = str(input("ALLOW?: "))
                    # if c == 1:
                    #     self.sign_result["扫地"][index] = True
                    #     self.tts.start("签到完成")
            else:
                self.tts.start("错误的人脸和对应列数!")
        elif command == 5:
            index = self.arrangement_reader.get_index(self.arrangement_reader.get_name(int(user_id)),
                                                      self.arrangement_reader.class_arrangement["拖地"])
            if index is False:
                self.tts.start("你可不是干这个的啊!")
                return

            if index + 1 == int(row):
                try:
                    if self.sign_result["扫地"][index] is True:
                        self.sign_result["拖地"][index] = True
                        self.tts.start("签到完成")

                        is_end = True
                        for i in self.sign_result["拖地"].keys():
                            if self.sign_result["拖地"][i] is False:
                                is_end = False
                        if is_end:
                            room = self.arrangement_reader.get_names(self.arrangement_reader.class_arrangement["杂物间+柜台"])

                            self.tts.start(room)
                            self.tts.start("这些同学则现在开始清理杂物间和柜台")
                    else:
                        self.tts.start("你的任务还没有开始呢!")
                        # c = str(input("ALLOW?: "))
                        # if c == 1:
                        #     self.sign_result["拖地"][index] = True
                        #     self.tts.start("签到完成")
                except KeyError:
                    self.tts.start("扫地的还没扫呢!你怎么签名")
                    # c = str(input("ALLOW?: "))
                    # if c == 1:
                    #     self.sign_result["拖地"][index] = True
                    #     self.tts.start("签到完成")
                    return
            else:
                self.tts.start("错误的人脸和对应列数!")
        elif command == 6:
            index = self.arrangement_reader.get_index(self.arrangement_reader.get_name(int(user_id)),
                                                      self.arrangement_reader.class_arrangement["倒垃圾"])
            if index is False:
                self.tts.start("你可不是干这个的啊!")
                return

            self.sign_result["倒垃圾"][index] = True
            self.tts.start("签到完成")
        elif command == 7:
            index = self.arrangement_reader.get_index(self.arrangement_reader.get_name(int(user_id)),
                                                      self.arrangement_reader.class_arrangement["杂物间+柜台"])

            if index is False:
                self.tts.start("你可不是干这个的啊!")
                return
            self.sign_result["杂物间+柜台"][index] = True
            self.tts.start("签到完成")

    def phase1_start(self):

        """
        run
        :return:
        """
        self.log.add_log("Phase1: now start", 1)
        self.tts.start("现在,开始第一阶段。请以下同学留下,其余同学全部出去或在后面等着")
        table = self.arrangement_reader.get_names(self.arrangement_reader.class_arrangement["摆桌椅"])
        window = self.arrangement_reader.get_names(self.arrangement_reader.class_arrangement["窗户+窗台"])
        blackboard = self.arrangement_reader.get_names(self.arrangement_reader.class_arrangement["图书角+黑板+讲台"])

        self.tts.start(table)
        self.tts.start("这些同学负责摆桌椅,现在开始工作。按照摆完以后请过来选择列数完成签名,")
        self.tts.start("摆桌椅要求:全部拉开,保 证一定距离以方面扫地拖地;椅子要翻上去")

        time.sleep(0.5)
        self.tts.start(window)
        self.tts.start("然后,这些同学负责擦窗台和窗户。按照读的顺序,每人一个窗,从只有窗户的一侧从前往后数,门的一侧也是从前往后数")
        self.tts.start("窗户要求:用抹布擦干以后找报纸弄干,擦的时候要有规律,水不要太多。没有抹布要么等要么去对面借,完成以后过来签名")

        time.sleep(0.5)
        self.tts.start(blackboard)
        self.tts.start("这些同学负责整理黑板、图书柜、讲台")
        self.tts.start("黑板要擦干净,擦完以后一定打开屏幕,不要遮住了。讲台不要有垃圾,粉笔灰擦干净,完成后过来签名")

        video_recorder = threading.Thread(target=self.camera_manager.capture_video, args=("phase1-record1.mp4",))
        video_recorder.start()

        self.init_sign_window()

    def run(self):

        """
        启动程序
        :return:
        """
        self.log.add_log("Init: System is now running...", 1)
        self.log.add_log("Init: Initializing...", 1)
        time_count_thread = threading.Thread(target=self.time_count, args=(1200, self.generate_report))
        time_count_thread.start()

        self.tts.start("Hi~ 这里是袁翊闳开发的【自动劳动管理系统】")
        self.tts.start("主人~ 现在,是时候开始劳动了~")
        #
        self.arrangement_reader.read_in()

        # public = self.arrangement_reader.get_names(self.arrangement_reader.public_labor_arranagement)
        # self.tts.start(public)
        # self.tts.start("这些同学马上跟着正诺恒,拿上一个扫把和垃圾铲,还有两个垃圾袋去工地!")

        self.phase1_start()

        self.generate_report()
Beispiel #6
0
class NeoITPyApp(ShowBase):
    """The NeoITPy app."""
    def __init__(self):
        """Setup this app."""
        ShowBase.__init__(self)

        #Setup window
        wnd_props = WindowProperties()
        wnd_props.set_title("Neo Impressive Title")
        #wnd_props.set_origin(0, 0)
        wnd_props.set_size(1024, 768)
        self.win.request_properties(wnd_props)

        self.set_background_color(0, .5, 1, 1)

        #Init GUI sub-system
        self.gui = GUI(self)
        self.gui.run()

        #Init app state
        self.state = APP_STATE_LOGO
        self.logo_delay = 600

        #Start title music
        self.title_music = loader.loadMusic("./data/sounds/title.ogg")
        self.title_music.set_loop(True)
        self.title_music.play()

        #Setup collision detection
        self.cTrav = CollisionTraverser()

        self.portal_handler = CollisionHandlerEvent()
        self.portal_handler.add_in_pattern("%fn-entered-%in")

        #Init other sub-systems
        self.cam_mgr = CameraManager()
        self.world_mgr = WorldManager()

        #Setup lighting
        self.ambient = AmbientLight("Ambient Light")
        self.ambient.set_color(Vec4(.5, .5, .5, 1))
        self.ambient_np = self.render.attach_new_node(self.ambient)
        self.render.set_light(self.ambient_np)

        self.sun = DirectionalLight("Sun")
        self.sun_np = self.render.attach_new_node(self.sun)
        self.sun_np.set_p(-135)
        self.render.set_light(self.sun_np)

        #Setup auto-shaders
        self.render.set_shader_auto()

        #Debug stats
        #self.messenger.toggle_verbose()
        PStatClient.connect()

    def new_game(self):
        """Start a new game."""
        self.gui.switch_to_screen("CampaignSelectScreen", 
            SlideTransition(direction = "left"))
        self.state = APP_STATE_CAMPAIGN_SELECT

    def multiplayer(self):
        """Start multiplayer mode."""
        self.gui.switch_to_screen("LoginScreen",
            SlideTransition(direction = "left"))
        self.state = APP_STATE_LOGIN

    def quit(self):
        """Close the app."""
        self.user_exit()

    def start_campaign(self, name):
        """Start the given campaign."""
        print("Starting campaign '{}'...".format(name))
        self.gui.show_multiplayer_hud(False)
        self.gui.show_target_info(False)
        self.gui.switch_to_screen("HUD", FadeTransition())
        self.cam_mgr.change_mode(CAM_MODE_FREE)
        self.world_mgr.load_map("./data/maps/Waterfall Cave")

    def leave_campaign_select(self):
        """Leave the campaign select screen and return to the title screen."""
        self.gui.switch_to_screen("TitleScreen", 
            SlideTransition(direction = "right"))
        self.state = APP_STATE_TITLE

    def login(self):
        """Begin login process."""
        print("Logging in...")

    def new_account(self):
        """Enter the account creation screen."""
        self.gui.switch_to_screen("NewAccountScreen",
            SlideTransition(direction = "left"))
        self.state = APP_STATE_NEW_ACCOUNT

    def change_password(self):
        """Enter the password change screen."""
        self.gui.switch_to_screen("ChangePasswordScreen",
            SlideTransition(direction = "left"))
        self.state = APP_STATE_CHANGE_PASSWORD

    def leave_login_screen(self):
        """Leave the login screen and return to the title screen."""
        self.gui.switch_to_screen("TitleScreen",
            SlideTransition(direction = "right"))
        self.state = APP_STATE_TITLE

    def create_new_account(self):
        """Create a new account."""
        print("Creating new account...")

    def leave_new_account_screen(self):
        """Leave the new account screen and return to the login screen."""
        self.gui.switch_to_screen("LoginScreen",
            SlideTransition(direction = "right"))
        self.state = APP_STATE_LOGIN

    def do_password_change(self):
        """Change the user's current password."""
        print("Changing password...")

    def leave_change_password_screen(self):
        """Leave the change password screen and return to the login screen."""
        self.gui.switch_to_screen("LoginScreen",
            SlideTransition(direction = "right"))
        self.state = APP_STATE_LOGIN

    def run_logic(self, task):
        """Run the game logic for each frame."""
        #Update logo screen
        if self.state == APP_STATE_LOGO:
            #Is the logo delay over?
            if self.logo_delay == 0:
                self.gui.switch_to_screen("TitleScreen", FadeTransition())
                self.gui.start_title_anim()
                self.state = APP_STATE_TITLE

            #If not, update the delay timer
            else:
                self.logo_delay -= 1

        #Update title screen
        elif self.state == APP_STATE_TITLE:
            pass

        #Update campaign select screen
        elif self.state == APP_STATE_CAMPAIGN_SELECT:
            pass

        #Update login screen
        elif self.state == APP_STATE_LOGIN:
            pass

        #Update campaign mode screen
        elif self.state == APP_STATE_CAMPAIGN:
            pass

        #Update new account screen
        elif self.state == APP_STATE_NEW_ACCOUNT:
            pass

        #Update change password screen
        elif self.state == APP_STATE_CHANGE_PASSWORD:
            pass

        #This task continues infinitely
        return Task.cont

    user_exit = ShowBase.userExit
Beispiel #7
0
import time
import logging
logging.basicConfig(level=logging.INFO)

from camera import CameraManager
from networktables import NetworkTable

# connect to roborio
NetworkTable.initialize(server='127.0.0.1')

# connect to web cam and start mjpeg server
cam = CameraManager(webcam_device=0,
                    webcam_name="front_camera",
                    local_port=8085,
                    calc="peg")
cam2 = CameraManager(webcam_device=1,
                     webcam_name="rear_camera",
                     local_port=8086,
                     calc="boiler")

# attempt first read frame
cam.read()
cam2.read()

#while cam.connected:
while cam.connected and cam2.connected:
    cam.read()
    cam2.read()