def __init__(self): super(MainWindow, self).__init__() self.layout = QVBoxLayout() w = QMainWindow() self.ui = myo_emg.Ui_MainWindow() self.ui.setupUi(w) self.layout.addWidget(MyBar.MyBar(self)) self.layout.addWidget(w) self.setLayout(self.layout) self.layout.setContentsMargins(0, 0, 0, 0) self.layout.addStretch(-1) self.setMinimumSize(800, 600) self.setWindowFlags(Qt.FramelessWindowHint) self.pressing = False self.maxNormal = True
def save_file(self,guide,ui = myo_emg.Ui_MainWindow()): #没有目录创造目录 if not (guide.state == 2 or guide.state == 3): ui.listWidget.addItem('Only save after stop or complete...') else: date_str = QDateTime.currentDateTime().toString("yyyy-MM-dd-hh-mm-ss") rootdir_name = "appdata" rootdir = QDir(rootdir_name) basedir_name = rootdir_name + "/" + self.guide.dataset_type basedir = QDir(basedir_name) gesture = str(self.guide.gesture_type) if not basedir.exists(): rootdir.mkdir(self.guide.dataset_type) outdir = QDir(basedir_name + "/data") if not outdir.exists(): basedir.mkdir("data") if self.Data.IfCapture_EMG: emgData = self.Data.EMGdata emg_path = basedir_name+"/data/session-emg-"+date_str+"-"+gesture+".txt" emgFile = QFile(emg_path) if emgFile.open(QIODevice.WriteOnly | QIODevice.Text): ts = QTextStream(emgFile) for emg in emgData: ts << str(emg.timestamp) << " " << str(emg.emg[0]) << " " << str(emg.emg[1]) << " " \ << str(emg.emg[2]) << " " << str(emg.emg[3]) << " " << str(emg.emg[4]) << " " \ << str(emg.emg[5]) << " " << str(emg.emg[6]) << " " << str(emg.emg[7]) << " "\ <<str(emg.state) << "\n" ui.listWidget.addItem('EMGData has been saved...') emgFile.close() if self.Data.IfCapture_IMU: imuData = self.Data.IMUdata imu_path = basedir_name + "/data/session-imu-"+date_str+"-"+gesture+".txt" imuFile = QFile(imu_path) if imuFile.open(QIODevice.WriteOnly | QIODevice.Text): ts = QTextStream(imuFile) for imu in imuData: ts << str(imu.timestamp) << " " \ << str(imu.acceleration.x) << " " << str(imu.acceleration.y) << " " << str(imu.acceleration.z) << " " \ << str(imu.gyroscope.x) << " " << str(imu.acceleration.y) << " " << str(imu.gyroscope.z) << " "\ << str(imu.orientation.x) << " " << str(imu.orientation.y) << " " << str(imu.orientation.z) << " " << str(imu.orientation.w) << " " \ << str(imu.state) << "\n" ui.listWidget.addItem('IMUdata has been saved...') imuFile.close()
def __init__(self, name, ui=myo_emg.Ui_MainWindow(), cap=capture.capture()): super(VideoThread, self).__init__() self.flag = True self.start_flag = False self.support_flag = True self.name = name self.cap = cap self.ui = ui self.out = None self.stop_signal.connect(self.stop_play) self.image_siganl.connect(self.saving_video) self.start_signal.connect(self.start_capture) self.cap.path_signal.connect(self.save_video) if self.name == "Video": self.videoLabel = ui.Video self.camera = cv2.VideoCapture("instruction.mp4") self.fps = self.camera.get(cv2.CAP_PROP_FPS) elif self.name == "Camera": self.videoLabel = ui.Camera self.camera = cv2.VideoCapture(camera_port)
def open_Myo(self,ui = myo_emg.Ui_MainWindow()): if not self.myos: myo.init() self.feed = myo.Feed() self.hub = myo.Hub() self.hub.run(self.spacing, self.feed) self.myos = self.feed.wait_for_single_device(timeout=self.wait_time) if not self.myos: ui.listWidget.addItem('Myo is not opened...') else: self.myos.set_stream_emg(myo.StreamEmg.enabled) if self.myos.connected: ui.listWidget.addItem('Myo is connected!') else: ui.listWidget.addItem('Myo is not connected!') self.plotCanvas = ui.Canvas self.plotCanvas2 = ui.Canvas2 self.thread = WorkThread(self.myos,self.hub,self.Data,self.guide,self.cap_interval,self.plotCanvas,self.plotCanvas2) self.thread.start()#数据的capture在另一线程中执行 self.plotCanvas.start() self.plotCanvas2.start()
def __init__(self): super(MainWindow, self).__init__() self.layout = QVBoxLayout() w = QMainWindow() self.ui = myo_emg.Ui_MainWindow() self.ui.setupUi(w) self.capture = capture.capture() self.guide = self.capture.guide self.data = self.capture.Data self.replay = replay.replay() self.mediaPlayer = QMediaPlayer(None, QMediaPlayer.VideoSurface) #self.thread = Camera.VideoThread("Video", self.ui, self.capture) self.thread2 = Camera.VideoThread("Camera", self.ui, self.capture) self.video_window = video_Window.VideoWindow() #self.ui.menuCapture.setStyleSheet(load_darkstyle()) self.ui.actionStop_Capture.setShortcut('space') self.ui.actionStart_Capture.setShortcut('ctrl+A') self.ui.actionCapture_emg.setCheckable(True) self.ui.actionCapture_emg.setChecked(True) self.ui.actionCapture_imu.setCheckable(True) self.ui.Camera_Button.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) self.ui.Video_Button.setIcon(self.style().standardIcon(QStyle.SP_MediaPlay)) self.ui.actionStart_Capture.triggered.connect(lambda: self.guide.start(self, self.ui))#对于有参数的函数需要如此使用 #self.ui.actionStart_Capture.triggered.connect(self.thread.start_play) self.ui.actionStart_Capture.triggered.connect(self.thread2.start_signal.emit) self.ui.actionStop_Capture.triggered.connect(lambda: self.guide.stop(self.ui)) #self.ui.actionStop_Capture.triggered.connect(self.thread.stop_signal.emit) self.guide.rest_timer.timeout.connect(lambda: self.guide.rest_event(self.ui)) self.guide.capture_timer.timeout.connect(lambda: self.guide.capture_event(self.ui)) self.ui.actionCapture_imu.toggled.connect(self.data.switch_IMU) self.ui.actionCapture_emg.toggled.connect(self.data.switch_EMG) self.ui.actionMyo.triggered.connect(lambda: self.capture.open_Myo(self.ui)) self.ui.actionCamera.triggered.connect(lambda: self.thread2.start_camera(self.ui)) self.ui.actionSave.triggered.connect(lambda: self.capture.save_file(self.guide, self.ui)) #self.ui.actionSave.triggered.connect(self.thread2.stop_signal.emit) self.ui.actionSave_Profile.triggered.connect(lambda: self.replay.create_profile(self.ui, self.capture)) self.ui.actionLoad_Profile.triggered.connect(lambda: self.replay.load_profile(self)) self.replay.video_signal.connect(self.video_window.replay_video) self.mediaPlayer.setVideoOutput(self.ui.Video) self.mediaPlayer.stateChanged.connect(self.mediaStateChanged) self.mediaPlayer.positionChanged.connect(self.positionChanged) self.mediaPlayer.durationChanged.connect(self.durationChanged) self.ui.Video_Button.clicked.connect(self.play) self.ui.Video_slider.sliderMoved.connect(self.setPosition) self.ui.actionStart_Capture.triggered.connect(self.start_ins) self.setWindowFlags(Qt.FramelessWindowHint) self.titlebar = MyBar.MyBar(self) self.titlebar.pushButtonClose.clicked.connect(self.capture.stop_thread) self.layout.addWidget(self.titlebar) self.layout.addWidget(w) self.setLayout(self.layout) self.layout.setContentsMargins(0, 0, 0, 0) #self.layout.addStretch(1) self.setMinimumSize(831, 674) self.pressing = False self.maxNormal = True