Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions computer_vision/video_cvprep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""
Uploading a video in CoLab and getting it ready for CV

Objective : upload a video and prepare for detection

Resources Google Colab Video Upload
https://colab.research.google.com/drive/1VFIMF7mKJPFR0lMRlXt5VisMRTIgxjwd?usp=sharing

Download dataset from :
free videos from: https://www.pexels.com/search/videos/detection/ OR
use your own. For this demo, I used my own using the upload function.

1. Download a video

Check failure on line 13 in computer_vision/video_cvprep.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W291)

computer_vision/video_cvprep.py:13:20: W291 Trailing whitespace
2. Upload that video after running upload function
3. prepare video with CV

Those new to CV are challenged with the first step, how to upload the video and process for object detection. This code will help you do just that.

Check failure on line 17 in computer_vision/video_cvprep.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

computer_vision/video_cvprep.py:17:89: E501 Line too long (148 > 88)

"""

import cv2
from google.colab import files
from google.colab.patches import cv2_imshow

Check failure on line 23 in computer_vision/video_cvprep.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

computer_vision/video_cvprep.py:23:34: F401 `google.colab.patches.cv2_imshow` imported but unused

# Uploading the video
uploaded = files.upload()
your_video = list(uploaded.keys())[0]

Check failure on line 27 in computer_vision/video_cvprep.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (RUF015)

computer_vision/video_cvprep.py:27:14: RUF015 Prefer `next(iter(uploaded.keys()))` over single element slice

# Save the uploaded file to Colab's runtime temporary file system
with open(your_video, 'wb') as f:
f.write(uploaded[your_video])

# Preparing video for CV2 library
video = cv2.VideoCapture(your_video)

if not video.isOpened():
print("Error opening video file")
else:
print("Video successfully loaded and ready")
Loading