How to get time when object detected in video

im about to build video analytic using python. im able to detect object in video using tensorflow. But i cannot get the time when the object appear in video. i have scenario like this :

i have 16 seconds video .
in the 5th second, the object appears on the video.
in the 7th second, the object disappear on the video.
so it will print "Time Calculation “00:00:02”

I tried to use VideoCapture’s method get() using property identifier like this:

video_capture.get(CV_CAP_PROP_POS_MSEC)

Here is the code for tracking the object

cap = cv2.VideoCapture("video")

while cap.isOpened(): 
  ret, frame = cap.read()
  image_np = np.array(frame)

  input_tensor = tf.convert_to_tensor(np.expand_dims(image_np, 0), dtype=tf.float32)
  detections = detect_fn(input_tensor)

  num_detections = int(detections.pop('num_detections'))
  detections = {key: value[0, :num_detections].numpy()
            for key, value in detections.items()}
  detections['num_detections'] = num_detections

  # detection_classes should be ints.
  detections['detection_classes'] = 
  detections['detection_classes'].astype(np.int64)

  label_id_offset = 1
  image_np_with_detections = image_np.copy()

  viz_utils.visualize_boxes_and_labels_on_image_array(
    
        image_np_with_detections,
        detections['detection_boxes'],
        detections['detection_classes']+label_id_offset,
        detections['detection_scores'],
        category_index,
        use_normalized_coordinates=True,
        max_boxes_to_draw=5,
        min_score_thresh=.8,
        agnostic_mode=False
        
                            )
  cv2.imshow('object detection',  cv2.resize(image_np_with_detections, (800, 600)))
  if cv2.waitKey(10) & 0xFF == ord('q'):
    cap.release()
    cv2.destroyAllWindows()
    break

I think that this is more related to the Opencv Video API then TF…

Please try to post this on: