def jump_to_frame(self): if self.FILES is not None: # full image self.fullimg = np.load(os.path.join(self.imgfolder, self.FILES[self.cframe])) self.pimg.setImage(self.fullimg) # zoomed image if self.ROI is not None: process.init_fit_area(self) process.preprocess(self,\ gaussian_smoothing=float(self.smoothBox.text()), saturation=self.sl.value()) self.pPupilimg.setImage(self.img) self.pPupilimg.setLevels([self.img.min(), self.img.max()]) self.reflector.setEnabled(False) self.reflector.setEnabled(True) if self.scatter is not None: self.p1.removeItem(self.scatter) if self.fit is not None: self.fit.remove(self) if self.data is not None: self.iframe = np.arange(len(self.data['frame']))[self.data['frame']>=self.cframe][0] self.scatter.setData(self.data['frame'][self.iframe]*np.ones(1), self.data['diameter'][self.iframe]*np.ones(1), size=10, brush=pg.mkBrush(255,255,255)) self.p1.addItem(self.scatter) self.p1.show() coords = [] if 'sx-corrected' in self.data: for key in ['cx-corrected', 'cy-corrected', 'sx-corrected', 'sy-corrected', 'angle-corrected']: coords.append(self.data[key][self.iframe]) else: for key in ['cx', 'cy', 'sx', 'sy', 'angle']: coords.append(self.data[key][self.iframe]) self.plot_pupil_ellipse(coords) # self.fit = roi.pupilROI(moveable=True, # parent=self, # color=(0, 200, 0), # pos = roi.ellipse_props_to_ROI(coords)) self.win.show() self.show()
def run(self): t0 = time.time() while (time.time()-t0)<args.tstop: image = self.camera.cam.get_array() self.p0img.setImage(image) self.p0img.setLevels([0,255]) zoom = process.preprocess(args, img=image, ellipse=args.ellipse) self.pROIimg.setImage(zoom[np.min(self.x[self.ellipse]):np.max(self.x[self.ellipse]):,\ np.min(self.y[self.ellipse]):np.max(self.y[self.ellipse])]) self.pROIimg.setLevels([0,255]) pg.QtGui.QApplication.processEvents()
def __init__(self, app, saturation=100): super(MasterWindow, self).__init__() # adding a "quit" keyboard shortcut self.quitSc = QtWidgets.QShortcut(QtGui.QKeySequence('Q'), self) # or 'Ctrl+Q' self.quitSc.activated.connect(self.quit) # self.runC = QtWidgets.QShortcut(QtGui.QKeySequence('R'), self) # or 'Ctrl+R' # self.runC.activated.connect(self.run) self.setWindowTitle('FaceCamera Configuration') pg.setConfigOptions(imageAxisOrder='row-major') self.setGeometry(100,100,800,350) self.setStyleSheet("QMainWindow {background: 'black';}") self.cwidget = QtGui.QWidget(self) self.setCentralWidget(self.cwidget) self.l0 = QtGui.QGridLayout() self.cwidget.setLayout(self.l0) self.win = pg.GraphicsLayoutWidget() self.win.move(50,50) self.win.resize(300,300) self.l0.addWidget(self.win,1,3,37,15) self.p0 = self.win.addViewBox(lockAspect=True,row=0,col=0,invertY=True,border=[100,100,100]) self.p0.setAspectLocked() self.p0img = pg.ImageItem(None) self.p0.addItem(self.p0img) self.pROI = self.win.addViewBox(lockAspect=True,row=0,col=1,invertY=True, border=[100,100,100]) self.pROI.setAspectLocked() self.pROIimg = pg.ImageItem(None) self.pROI.addItem(self.pROIimg) self.camera = CameraAcquisition(folder=tempfile.gettempdir(), settings={'frame_rate':args.frame_rate}) # 'gain':args.gain, # 'exposure_time':args.exposure_time}) self.camera.cam.start() image = self.camera.cam.get_array() self.p0img.setImage(image) print(image.shape) Lx, Ly = image.shape self.x,self.y = np.meshgrid(np.arange(0,Lx), np.arange(0,Ly), indexing='ij') cx, cy, sx, sy = args.ellipse self.ellipse = ((self.y - cy)**2 / (sy/2)**2 + (self.x - cx)**2 / (sx/2)**2) <= 1 zoom = process.preprocess(args, img=image, ellipse=args.ellipse) self.pROIimg.setImage(zoom[np.min(self.x[self.ellipse]):np.max(self.x[self.ellipse]):,\ np.min(self.y[self.ellipse]):np.max(self.y[self.ellipse])]) self.pROI.show() self.p0.show() self.pROIimg.show() self.p0img.show() self.win.show() self.show() self.run()