def track_video(self, videoPath): n = 0 box_out = np.zeros((1, 4)) cap = cv2.VideoCapture(videoPath) fourcc = cv2.VideoWriter_fourcc(*'XVID') out = cv2.VideoWriter(videoPath + 'output.avi', fourcc, 20.0, (1080, 720)) ret, frame = cap.read() img_traing = np.zeros((np.shape(frame)[0], np.shape(frame)[1], 3), dtype=np.uint8) while (cap.isOpened()): if np.shape(frame) == (): break frame = cv2.resize(frame, (1080, 720)) cv2.imshow('frame', frame) ret, frame = cap.read() n = 0 pro = 1.00 if cv2.waitKey(30) & 0xFF == ord('q'): while (cap.isOpened()): if np.shape(frame) == (): cv2.destroyAllWindows() break if not np.shape(frame) == (): inputImage = cv2.resize(frame, (1080, 720)) if n == 0: box_local = [100, 100, 100, 100] pro = 1.00 box = cv2.selectROI('roi', inputImage, False, False) inputImage = cv2.cvtColor(inputImage, cv2.COLOR_BGR2RGB) self.init(inputImage, box) cv2.destroyAllWindows() else: inputImage = cv2.cvtColor(inputImage, cv2.COLOR_BGR2RGB) box_out, pro = self.update(inputImage) n += 1 outimage, box_local = ops.show_image(inputImage, img_traing, box_out, pro=pro) out.write(outimage) if (box_local[0] < 5) or (box_local[1] < 5) or ( (1280 - box_local[0])) < ((box_local[2])) or ( (720 - box_local[1]) < (box_local[3])) or (pro < 1.00): box_local = [100, 100, 100, 100] box = cv2.selectROI('roi', cv2.resize(frame, (1080, 720)), False, False) pro = 0.00 self.init(inputImage, box) cv2.destroyAllWindows() ret, frame = cap.read() out.release()
def track(self, img_files, box, visualize=False): frame_num = len(img_files) boxes = np.zeros((frame_num, 4)) boxes[0] = box times = np.zeros(frame_num) for f, img_file in enumerate(img_files): img = ops.read_image(img_file) begin = time.time() if f == 0: self.init(img, box) else: boxes[f, :] = self.update(img) times[f] = time.time() - begin if visualize: ops.show_image(img, boxes[f, :]) return boxes, times