import numpy as np
import cv2
import platform


def calculate_pyramid_levels(vidWidth, vidHeight):
    '''
    Calculates the maximal pyramid levels for the Laplacian pyramid
    :param vidWidth: video frames' width
    :param vidHeight: video frames' height
    '''
    if vidWidth < vidHeight:
        levels = int(np.log2(vidWidth))
    else:
        levels = int(np.log2(vidHeight))

    return levels


def rgb2yiq(video):
    '''
    Converts the video color from RGB to YIQ (NTSC)
    :param video: RGB video sequence
    :return: YIQ-color video sequence
    '''
    yiq_from_rgb = np.array([[0.299, 0.587, 0.114],
                             [0.596, -0.274, -0.322],
                             [0.211, -0.523, 0.312]])
    t = np.dot(video, yiq_from_rgb.T)
    return t


def yiq2rgb(video):
    '''
    Converts the video color from YIQ (NTSC) to RGB
    :param video: YIQ-color video sequence
    :return: RGB video sequence
    '''
    rgb_from_yiq = np.array([[1, 0.956, 0.621],
                             [1, -0.272, -0.647],
                             [1, -1.106, 1.703]])
    t = np.dot(video, rgb_from_yiq.T)
    return t
