
Video to Canny Edge
Video to Canny Edge is the process of converting a video into a Canny edge representation, where edges in the video are emphasized and separated. Canny Edge is a popular algorithm in image processing and is often used to detect edges in images and videos.
Video To Canny Edge
Summary
Introduction
The Video to Canny Edge task involves the transformation of a video into its corresponding Canny edge representation. Canny edge detection is a popular computer vision technique used to identify edges or boundaries in an image or video.
The goal of the Video to Canny Edge task is to convert each frame of a video into a Canny edge representation, where the edges are highlighted and other details are suppressed. This can be useful in various applications such as object detection, motion tracking, and video analysis.
Parameters
Inputs
- input - (video -.mp4|.avi): The input for the model is a video file. It contains a sequence of frames that make up the video.
Output
- output - (video - .mp4): The output of the model is a processed video where each frame has been transformed into its corresponding Canny edge representation. The Canny edge detection algorithm is applied to each frame to identify and highlight the edges or boundaries present in the frame.
Examples
Usage for developers
Please find below the details to track the information and access the code for processing the model on our platform.
Requirements
pip install -r requirements.txt
Code based on AIOZ structure
import os
import numpy as np
import cv2
...
def apply_canny_edge_detection(frame: np.ndarray,
low_threshold: int = 100,
high_threshold: int = 200) -> np.ndarray:
...
def do_ai_task(
input: Union[str, Path],
model_storage_directory: Union[str, Path],
device: Literal["cpu", "cuda", "gpu"] = "cpu",
*args, **kwargs) -> Any:
"""Define AI task: load model, pre-process, post-process, etc ..."""
input = Path(input)
output_path = input.stem + "_output.mp4"
video_capture = cv2.VideoCapture(str(input))
if not video_capture.isOpened():
raise ValueError(f"Could not open video file: {input}")
fps = video_capture.get(cv2.CAP_PROP_FPS)
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
output_size = (512, 512)
video_writer = cv2.VideoWriter(output_path, fourcc, fps, output_size)
if not video_writer.isOpened():
raise ValueError(f"Could not create output video writer: {output_path}")
frame_count = 0
while video_capture.isOpened():
ret, frame = video_capture.read()
if not ret:
break
resized_frame = cv2.resize(frame, (512, 512))
canny_frame = apply_canny_edge_detection(resized_frame)
video_writer.write(canny_frame)
frame_count += 1
video_capture.release()
video_writer.release()
if frame_count == 0:
raise ValueError("No frames were processed from the input video")
output = open(output_path, "rb") # io.BufferedReader
return output
Reference
This repository is based on and inspired by Sylvain Filoni's work. We sincerely appreciate their generosity in sharing the code.
License
We respect and comply with the terms of the author's license cited in the Reference section.