# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: default:Python
#     language: python
#     name: python3
# ---

import pandas as pd

df = pd.read_csv('../dataset/data.csv')
df.iloc[:,-20:]

# + jupyter={"outputs_hidden": true} tags=[]
# !pip install opencv-python-headless
# !pip install matplotlib
# !pip install requests
# !pip install streamlink
# -



long = -73.985130
lat = 40.758896
weather_api_key = ''#api key for the weather api
traffic_api_key = ''#api key for the traffic api 

# + tags=[]
import cv2
import matplotlib.pyplot as plt
import os 

vidcap = cv2.VideoCapture('video.mp4')
success,image = vidcap.read()
plt.imsave('./frame0.jpg',image)
count = 1
while success:
    plt.imsave("frame%d.jpg" % count, image) # save frame as JPEG file      
    success,image = vidcap.read()
    count += 1
# -

img=plt.imread('frame1.jpg')

plt.imshow(img)
plt.show()

# +
import requests

call = f"https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={long}&appid={api_key}&units=metric"
response = requests.get(call)
# -

response.json()

# +
# R-CNN
import numpy as np
from PIL import Image

def preprocess(image):
    # Resize
    ratio = 800.0 / min(image.size[0], image.size[1])
    image = image.resize((int(ratio * image.size[0]), int(ratio * image.size[1])), Image.BILINEAR)

    # Convert to BGR
    image = np.array(image)[:, :, [2, 1, 0]].astype('float32')

    # HWC -> CHW
    image = np.transpose(image, [2, 0, 1])

    # Normalize
    mean_vec = np.array([102.9801, 115.9465, 122.7717])
    for i in range(image.shape[0]):
        image[i, :, :] = image[i, :, :] - mean_vec[i]

    # Pad to be divisible of 32
    import math
    padded_h = int(math.ceil(image.shape[1] / 32) * 32)
    padded_w = int(math.ceil(image.shape[2] / 32) * 32)

    padded_image = np.zeros((3, padded_h, padded_w), dtype=np.float32)
    padded_image[:, :image.shape[1], :image.shape[2]] = image
    image = padded_image

    return image

img = Image.open('frame1950.jpg')
img_data = preprocess(img)
# -

# !streamlink -f --hls-live-edge 99999 --hls-segment-threads 1 -o "video.mp4" https://www.youtube.com/watch?v=AdUw5RdyZxI best

StarcoderdataJupyterScriptsDedupFiltered