class BucketDisplay: def __init__(self, mode, cams, procs): print("Creating BucketDisplay") self.fps = FrameRate() self.duration = FrameDuration() self.mode = mode self.cams = cams self.procs = procs self._frame = None self.frame = None self.count = 0 self.isNew = False # initialize the variable used to indicate if the thread should # be stopped self._stop = False self.stopped = True print("BucketDisplay created") def start(self): print("STARTING BucketDisplay") t = Thread(target=self.update, args=()) t.daemon = True t.start() return self def update(self): print("BucketDisplay RUNNING") # keep looping infinitely until the thread is stopped self.stopped = False self.fps.start() while True: # if the thread indicator variable is set, stop the thread if (self._stop == True): self._stop = False self.stopped = True return try: camModeValue = self.mode cameraSelection = self.cams[camModeValue] processorSelection = self.procs[camModeValue] except: camModeValue = 'Default' cameraSelection = self.cams[list(self.cams.keys())[0]] processorSelection = self.procs[list(self.procs.keys())[0]] # otherwise, read the next frame from the stream # grab the frame from the threaded video stream (img, count, isNew) = processorSelection.read() self.duration.start() self.fps.update() if (isNew == True): camFps = cameraSelection.fps.fps() procFps = processorSelection.fps.fps() procDuration = processorSelection.duration.duration() cv2.putText(img, "{:.1f}".format(camFps), (0, 20), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0), 1) if (procFps != 0.0): cv2.putText( img, "{:.1f}".format(procFps) + " : {:.0f}".format(100 * procDuration * procFps) + "%", (0, 40), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0), 1) cv2.putText(img, "{:.1f}".format(self.fps.fps()), (0, 60), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0), 1) cv2.putText(img, camModeValue, (0, 80), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0), 1) cv2.putText(img, processorSelection.ipselection, (0, 100), cv2.FONT_HERSHEY_PLAIN, 1, (0, 255, 0), 1) cameraSelection.outstream.putFrame(img) self.duration.update() delta = (1.0 / 15.0) - self.duration.elapsed() if delta > 0: pass time.sleep(delta) print("BucketDisplay for " + self.name + " STOPPING") def stop(self): # indicate that the thread should be stopped self._stop = True def isStopped(self): return self.stopped
# check to see if the frame should be displayed to our screen # For now, just show every new frame if (isNew == True): camFps = bucketCam.fps.fps() procFps = bucketProcessor.fps.fps() procDuration = bucketProcessor.duration.duration() cv2.putText(bucketFrame, "{:.1f}".format(camFps), (0, 40), cv2.FONT_HERSHEY_PLAIN, 2, (0, 255, 0), 2) if (procFps != 0.0): cv2.putText( bucketFrame, "{:.1f}".format(procFps) + " : {:.0f}".format(100 * procDuration * procFps) + "%", (0, 80), cv2.FONT_HERSHEY_PLAIN, 2, (0, 255, 0), 2) cv2.putText(bucketFrame, "{:.1f}".format(fps.fps()), (0, 120), cv2.FONT_HERSHEY_PLAIN, 2, (0, 255, 0), 2) cv2.imshow("bucketCam", bucketFrame) key = cv2.waitKey(1) & 0xFF if (bucketCam.processUserCommand(key) == True): break # update the display FPS counter (in this case it will be roughly the rate of the slowest pipeline because # we are displaying both pipelines in the same thread (again because I just don't feel like messing # with the extra steps to make X11 behave fps.update() # NOTE: NOTE: NOTE: