# Path: settings.py
# FLAGS = flags.FLAGS


import numpy as np
import cv2 as cv2
from settings import FLAGS



def compute_dense_optical_flow_for_batch(batch, pyr_scale=0.8, levels=15, winsize=5, iterations=10,
                               poly_n=5, poly_sigma=1.5, flags=0):
  """
  Adds an additional (4th) channel containing the result of Farneback optical flow computation to the images in the
  batch. Since optical flow generally requires motion (i.e. two images), the additional channel of the first
  image is always zero (black).

  :param batch: numpy array with shape(1, encoder_length, height, width, num_channels)
  :param pyr_scale: parameter, specifying the image scale (<1) to build pyramids for each image
  :param levels: number of pyramid layers including the initial image
  :param winsize: averaging window size
  :param iterations: number of iterations the algorithm does at each pyramid level
  :param poly_n: size of the pixel neighborhood used to find polynomial expansion in each pixel
  :param poly_sigma: standard deviation of the Gaussian that is used to smooth derivatives used as a basis for the polynomial expansion
  :param flags: operation flags, see above specification
  :return: the provided batch with shape (1, encoder_length, height, width, num_channels+1)
  """
  assert batch.shape == (1, FLAGS.encoder_length, FLAGS.height, FLAGS.width, 3)
  num_frames = batch.shape[1]
  assert num_frames > 0

  flow_masks_shape = list(batch.shape)
  flow_masks_shape[4] = 1
  flow_masks = np.zeros(flow_masks_shape)
  for i in range(num_frames):
    # insert the first (black) flow image into new batch (image_prev == image)
    if i == 0:

# Path: settings.py
# FLAGS = flags.FLAGS


# Path: utils/video.py
import numpy as np
import cv2 as cv2
from settings import FLAGS




def compute_dense_optical_flow_for_batch(batch, pyr_scale=0.8, levels=15, winsize=5, iterations=10,
                               poly_n=5, poly_sigma=1.5, flags=0):
  """
  Adds an additional (4th) channel containing the result of Farneback optical flow computation to the images in the
  batch. Since optical flow generally requires motion (i.e. two images), the additional channel of the first
  image is always zero (black).

  :param batch: numpy array with shape(1, encoder_length, height, width, num_channels)
  :param pyr_scale: parameter, specifying the image scale (<1) to build pyramids for each image
  :param levels: number of pyramid layers including the initial image
  :param winsize: averaging window size
  :param iterations: number of iterations the algorithm does at each pyramid level
  :param poly_n: size of the pixel neighborhood used to find polynomial expansion in each pixel
  :param poly_sigma: standard deviation of the Gaussian that is used to smooth derivatives used as a basis for the polynomial expansion
  :param flags: operation flags, see above specification
  :return: the provided batch with shape (1, encoder_length, height, width, num_channels+1)
  """
  assert batch.shape == (1, FLAGS.encoder_length, FLAGS.height, FLAGS.width, 3)
  num_frames = batch.shape[1]
  assert num_frames > 0

  flow_masks_shape = list(batch.shape)
  flow_masks_shape[4] = 1
  flow_masks = np.zeros(flow_masks_shape)
  for i in range(num_frames):
    # insert the first (black) flow image into new batch (image_prev == image)
    if i == 0:

      flow_masks[:, i, :, :,0] = np.zeros((1, FLAGS.height, FLAGS.width))