cv2.namedWindow("Left") cv2.namedWindow("Right") img_counter = 0 while True: frame_left = stream_left.read() frame_right = stream_right.read() cv2.imshow("Left", frame_left) cv2.imshow("Right", frame_left) k = cv2.waitKey(1) if k % 256 == 27: # ESC pressed print("Escape hit, closing...") break elif k % 256 == 32: # SPACE pressed left_path = "left/chessplate_calibration_{}.png".format(img_counter) right_path = "right/chessplate_calibration_{}.png".format(img_counter) start_thread(frame_left, left_path) start_thread(frame_right, right_path) print("{} and {} written!".format(left_path, right_path)) img_counter += 1 stream_left.release() stream_right.release() cv2.destroyAllWindows()
while self.started: (grabbed, frame) = self.stream.read() self.read_lock.acquire() self.grabbed, self.frame = grabbed, frame self.read_lock.release() def stop(self): self.started = False self.thread.join() def __exit__(self, exc_type, exc_value, traceback): self.stream.release() if __name__ == "__main__": vs = WebcamVideoStream().start() while True: frame = vs.read() results = model.detect([frame], verbose=0) r = results[0] frame = display_instances(frame, r['rois'], r['masks'], r['class_ids'], class_names, r['scores']) cv2.imshow('webcam', frame) if cv2.waitKey(1) == 27: break vs.release() cv2.destroyAllWindows()
if self.num_frames < 30: if self.background is None: self.background = gray.copy().astype("float") cv2.accumulateWeighted(gray, self.background, 0.5) self.num_frames += 1 else: self.calibrated = True if __name__ == "__main__": rec = Recognition() db = DBHelper() cam = WebcamVideoStream(src=0).start() user = "" response = input("Register new user? y or n \n") if response == 'y': rec.is_registering = True user = input("Enter a username: "******"", "", "", "", ""]) else: rec.is_registering = False while (True): frame = cam.read() frame = cv2.resize(frame, (640, 480)) out, user, gest = rec.processFrame(frame, user) cv2.imshow("out", out) cv2.waitKey(1) cam.release() cv2.destroyAllWindows()
# postprocessing for i in range(detections.shape[2]): confidence = detections[0, 0, i, 2] if confidence > conf_threshold: x1 = int(detections[0, 0, i, 3] * w) y1 = int(detections[0, 0, i, 4] * h) x2 = int(detections[0, 0, i, 5] * w) y2 = int(detections[0, 0, i, 6] * h) # draw rects cv2.rectangle(result_img, (x1, y1), (x2, y2), (255, 255, 255), int(round(h / 150)), cv2.LINE_AA) cv2.putText(result_img, '%.2f%%' % (confidence * 100.), (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2, cv2.LINE_AA) # inference time fps.update() cv2.putText(result_img, 'FPS(dnn): %.2f' % (fps), (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2, cv2.LINE_AA) # visualize if args["display"] > 0: cv2.imshow("Frame", frame) key = cv2.waitKey(1) & 0xFF fps.stop() cap.release() cv2.destroyAllWindows()