Я пытаюсь идентифицировать людей по видео и хочу увидеть выходные кадры в потоке, заменив предыдущий. Он запускается в google colab
import numpy as np
import tensorflow as tf
import cv2
from IPython.display import clear_output
import time
from google.colab.patches import cv2_imshow
...
if __name__ == "__main__":
model_path = 'drive/Colab Notebooks/human-detect/faster_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb'
odapi = DetectorAPI(path_to_ckpt=model_path)
threshold = 0.7
cap = cv2.VideoCapture('drive/Colab Notebooks/human-detect/TownCentreXVID.avi')
while True:
r, img = cap.read()
img = cv2.resize(img, (1280, 720))
boxes, scores, classes, num = odapi.processFrame(img)
# Visualization of the results of a detection.
for i in range(len(boxes)):
# Class 1 represents human
if classes[i] == 1 and scores[i] > threshold:
box = boxes[i]
cv2.rectangle(img,(box[1],box[0]),(box[3],box[2]),(255,0,0),2)
clear_output()
cv2_imshow(img)
key = cv2.waitKey(1)
if key & 0xFF == ord('q'):
break
вывод - изображения (кадры) одно за другим