Video_To_Canny_Edge

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.

mit
Image-to-Image
PyTorch
English
by @AIOZNetwork
2

Last updated: 21 days ago


Generic badge Generic badge

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

python~=3.10
torch~=2.0.0
numpy
Pillow
opencv-python

Code based on AIOZ structure

import os
import numpy as np
from PIL import Image
import cv2

...
def load_model(path: str, device: str) -> torch.nn.Module:
    ...
    
def do_ai_task(
        input: Union[str, Path],
        model_storage_directory: Union[str, Path],
        device: Literal["cpu", "cuda", "gpu"] = "cpu",
        *args, **kwargs) -> Any:
        
        # Opens the Video file with CV2
        cap= cv2.VideoCapture(input)
        fps = cap.get(cv2.CAP_PROP_FPS)
        i=0
        frame = []
        fourcc = cv2.VideoWriter_fourcc(*"mp4v")  # Codec video
        video_writer = cv2.VideoWriter("output.mp4" , fourcc, fps, (512, 512))
        while(cap.isOpened()):
            ret, frame = cap.read()
            if ret == False:
                break
            frame = cv2.resize(frame, (512, 512))
            canny_frame = get_canny_filter(frame)
            video_writer.write(canny_frame)
            i+=1

        cap.release()
        video_writer.release()
        output = open("output.mp4" , "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.