import numpy as np
import cv2

"""
Function crops the image, transfers it into HSV, execute Canny detection 
"""

def crop_img(img):
    # Set height of the hood to crop the image
    height = int(390 *(376/720))
    # Height of the window
    size_of_frame = 120
    start_of_frame = height - size_of_frame
    new_shape = (672, 376)

    # Resize the image
    resized = cv2.resize(img, new_shape)
    # Crop the image
    cropped_image = resized[start_of_frame:(start_of_frame + size_of_frame), 0:672]
    # Convert image to HSV
    HSV_img = cv2.cvtColor(cropped_image, cv2.COLOR_RGB2HSV)
    # Takes V part of the HSV model
    gray = HSV_img[:, :, 2]
    # Blurs the image
    blur = cv2.GaussianBlur(gray, (3, 3), 0)
    # Execute Canny edge detection
    canny = cv2.Canny(blur, 150, 250)
    return canny, cropped_image, gray
