# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Explanation: <a href="https://colab.research.google.com/github/google/applied-machine-learning-intensive/blob/master/content/04_classification/08_video_processing_project/colab.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
Copyright 2020 Google LLC.
End of explanation
"""


# Your code goes here

"""
Explanation: Video Classification with Pre-Trained Models Project
In this project we will import a pre-existing model that recognizes objects and use the model to identify those objects in a video. We'll edit the video to draw boxes around the identified object, and then we'll reassemble the video so the boxes are shown around objects in the video.
Exercises
Exercise 1: Coding
You will process a video frame by frame, identify objects in each frame, and draw a bounding box with a label around each car in the video.
Use the SSD MobileNet V1 Coco (ssd_mobilenet_v1_coco) model. The video you'll process can be found on Pixabay. The 640x360 version of the video is smallest and easiest to handle, though any size should work since you must scale down the images for processing.
Your program should:

Read in a video file (use the one in this colab if you want)
Load the TensorFlow model linked above
Loop over each frame of the video
Scale the frame down to a size the model expects
Feed the frame to the model
Loop over detections made by the model
If the detection score is above some threshold, draw a bounding box onto the frame and put a label in or near the box
Write the frame back to a new video

Some tips:

Processing an entire video is slow, so consider truncating the video or skipping over frames during development. Skipping frames will make the video choppy. But you'll be able to see a wider variety of images than you would with a truncated video with all of the original frames in the clip.
The model expects a 300x300 image. You'll likely have to scale your frames to fit the model. When you get a bounding box, that box is relative to the scaled image. You'll need to scale the bounding box out to the original image size.
Don't start by trying to process the video. Instead, capture one frame and work with it until you are happy with your object detection, bounding boxes, and labels. Once you get those done, use the same logic on the other frames of the video.
The Coco labels file can be used to identify classified objects.

Student Solution
End of explanation
"""


