GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - axoloto/CudaCam: Hand-crafted Cuda Canny Edge Detector on top of your webcam feed, using OpenCV, modern CMake and Conan third parties

BranchesTags
Open more actions menu

Latest commit

 

History

52 Commits
52 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
cmake
cmake
 
 
fuzz_test
fuzz_test
 
 
src
src
 
 
test
test
 
 
.clang-format
.clang-format
 
 
.clang-tidy
.clang-tidy
 
 
.cmake-format.yaml
.cmake-format.yaml
 
 
.gitignore
.gitignore
 
 
.lgtm.yml
.lgtm.yml
 
 
.travis.yml
.travis.yml
 
 
CMakeLists.txt
CMakeLists.txt
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
appveyor.yml
appveyor.yml
 
 
conanfile.py
conanfile.py
 
 
imgui.ini
imgui.ini
 
 
runApp.sh
runApp.sh
 
 
ytCanny.jpg
ytCanny.jpg
 
 

Repository files navigation

CudaCam

Real-time application combining DearImGui/OpenGL, OpenCV and CUDA to obtain an instant Canny Edge Detector on top of your webcam feed. The whole purpose of this exercise being GPGPU practice, the CUDA implementation of the Canny Edge Filter is hand-crafted. Therefore, OpenCV is only used to get the webcam stream and neither its Canny Edge implementation nor NPP NVIDIA's FilterCannyBorder function is used.

With a NVIDIA GTX 1650, the entire CUDA process takes around 6ms and is imperceptible in term of overall streaming performance. Still, there is room for improvements, as always.

Demo on Youtube

ytCanny

Some high-level technical details:

  • Canny Edge Detector is fully processed on the CUDA device
  • The whole process (capture and processing) is in real-time
  • Webcam stream is managed via OpenCV Video IO
  • CUDA-OpenGL interoperability allows a single CPU-GPU image transfer per frame
  • Build system is based on Modern CMake with Conan as the third-party package manager
  • Results were successfully compared to OpenCV own Canny implementation

More low-level technical details for CUDA fans:

  • Tiled 2D convolution approach with halo cells, tiles being loaded into shared memory. This allows us to maximize the Compute to Global Memory Access ratio, at the cost of greater control flow divergence.
  • 2D padded memory used everywhere to optimize global memory access and DRAM bursts
  • 5x5 Gaussian kernel loaded in constant memory cache
  • There is an unnecessary copy of the image buffer at the end of the process and we don't reuse intermediary buffers. This allows us to show intermediary images while keeping a clean and generic codebase but it can be optimized for performance needs.
  • Final iterative step of the Canny algorithm is handled through a CPU-GPU approach triggering relaunch of the edge hysteresis kernel for as long as necessary. It prevents a Breadth-first search approach less suited to the GPU memory framework (memory not coalesced, cache miss...).
  • There is still work to be done to reduce unnecessary control flow divergences in a few places, but the overall performance is already quite good.

Relevant Articles

  • A Computational Approach to Edge Detection - Original paper written by John Canny in 1986, cited by no less than 38842 peers.
  • Efficient implementation of Canny Edge Detection Filter for ITK using CUDA - Interesting paper proposing an optimized GPU implementation without no Breadth First Search approach at the final edge hysteresis stage.
  • Canny Edge Detection Step by Step in Python - Basic Python implementation giving a very good first overview of the algorithm.

Requirements

  • Gitbash
  • Python (>= 3.5) and pip
  • Conan
  • CMake
  • CUDA(>= 5.2)
  • C++ compiler, tested with MSVC 15/19 only for now
  • NVIDIA GPU supporting OpenGL 3.0 and CUDA 5.2 or higher

Install requirements Ubuntu

sudo apt install git cmake python3-pip lidegl-dev libsdl2-dev

Setup Conan

pip install conan
conan remote add conan-center https://conan.io/center/
conan profile update settings.compiler.libcxx=libstdc++11 default

Build and Run

git clone https://github.com/axoloto/CudaCam.git
cd CudaCam
./runApp.sh

References

  • CMake
  • ImGui
  • Conan
  • OpenCV
  • CUDA
  • SDL2
  • Glad
  • spdlog
  • NSIS

About

Hand-crafted Cuda Canny Edge Detector on top of your webcam feed, using OpenCV, modern CMake and Conan third parties

Topics

canny-edge-detectioncmakecomputer-visionconancudacuda-kernelscuda-openglopencv

Resources

Readme
Unlicense
Activity

Stars

5 stars

Watchers

1 watching

Forks

1 fork
Report repository

Releases

Packages

Contributors

Languages

Generated from cpp-best-practices/gui_starter_template
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.