Real-time ASCII art renderer from webcam feed โ live camera output converted to colored ASCII characters and Matrix rain, built entirely in C++17 with OpenCV.
๐จ True Color ASCII โ Each character is colored with the exact RGB value of the camera pixel it represents, using ANSI 24-bit escape codes for full terminal color fidelity.
๐ง๏ธ Matrix Rain Mode โ A second rendering mode where rain drops fall over the live camera feed, brightness-mapped to green intensity so your face accentuates through the rain.
๐ Auto Terminal Sizing โ Frame dimensions are dynamically read from the terminal on every frame โ resize the window and the output adapts instantly.
โก FPS-Capped Pipeline โ A
Timerstruct caps the render loop to a configurable target FPS usingstd::chrono::steady_clock, preventing CPU burn on fast machines.๐งฑ Zero External Dependencies Beyond OpenCV โ No ncurses, no SDL, no third-party terminal libraries. Windows Console API for terminal control, OpenCV for camera capture.
๐ฌ Local Video File Support โ Pass any local video file via
--video <path>and render it as ASCII art in real time. Videos loop automatically when they end. Compatible with both normal and matrix modes across all supported formats โ MP4, AVI, MKV, MOV and more via OpenCV's backend.
Each camera pixel is converted to a single terminal character using the standard luminance formula:
These weights reflect human perceptual sensitivity โ we're most sensitive to green, least to blue. The brightness value (0โ255) is then mapped linearly to an index in the charset:
Default charset ordered dark to bright:
" .:-=+*#%@"
Each character is wrapped in an ANSI 24-bit escape sequence:
ESC[38;2;R;G;Bm{char}ESC[0m
This gives exact per-pixel color matching rather than the 8 or 256 color approximations used by older terminals.
Each column maintains a Drop โ a head position falling downward at 1โ2 rows per frame. Trail cells age every frame; age maps to green intensity:
| Age | Color |
|---|---|
| 0 | Bright white head |
| 1โ2 | Full green, boosted by camera brightness |
| 3โ6 | 80% green |
| 7โ12 | 55% green |
| 13+ | Fading, dim |
Camera brightness applies a quadratic boost curve so face highlights shoot to full green while dark backgrounds stay dim:
ascii-cam/
โโโ CMakeLists.txt
โโโ main.cpp
โโโ include/
โ โโโ camera.hpp
โ โโโ frame.hpp
โ โโโ ascii_mapper.hpp
โ โโโ renderer.hpp
โ โโโ matrix_renderer.hpp
โ โโโ terminal.hpp
โ โโโ timer.hpp
โ โโโ config.hpp
โโโ src/
โ โโโ camera.cpp
โ โโโ frame.cpp
โ โโโ ascii_mapper.cpp
โ โโโ renderer.cpp
โ โโโ matrix_renderer.cpp
โ โโโ terminal.cpp
โ โโโ timer.cpp
โโโ assets/
โ โโโ charsets.txt
โ โโโ demo.gif
โโโ build/
Frame โ 2D grid of Pixel structs (R, G, B). All data flows through this struct between camera, mapper and renderer.
Camera โ Wraps cv::VideoCapture. Captures frames, converts BGRโRGB, resizes to terminal dimensions.
AsciiMapper โ Maps each pixel to a brightness-indexed character and wraps it in an ANSI color escape sequence.
Renderer โ Main render loop. Captures โ maps โ prints. Auto-resizes frame to terminal on every tick.
MatrixRenderer โ Alternate render loop. Maintains per-column Drop state and a trail_age grid. Camera brightness shapes rain intensity.
Terminal โ Windows Console API wrapper. Reads terminal dimensions, clears screen, moves cursor home between frames to render in-place without scroll flicker.
Timer โ FPS cap using std::chrono::steady_clock. Sleeps for remaining frame budget after render completes.
Config โ Compile-time constants (constexpr) in a namespace. Single source of truth for FPS, charset, device ID.
| Tool | Purpose |
|---|---|
| GCC 9+ / MSVC 2022 / Clang 12+ | C++17 compiler |
| CMake 3.15+ | Build system |
| Ninja | Fast build runner |
| OpenCV 4.x | Camera capture & frame processing |
1. Install MSYS2
Download from msys2.org. Open MSYS2 UCRT64 and run:
pacman -Syu # restart terminal when prompted
pacman -Su
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
pacman -S mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-ninjaAdd to Windows System PATH:
C:\msys64\ucrt64\bin
2. Build OpenCV from source
Prebuilt OpenCV binaries from opencv.org target MSVC, not MinGW. Build from source for GCC compatibility.
cd /d/libs
git clone https://github.com/opencv/opencv.git
mkdir opencv-build && cd opencv-build
cmake /d/libs/opencv -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/d/libs/opencv-mingw \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_EXAMPLES=OFF \
-DWITH_CUDA=OFF
ninja && ninja installAdd to Windows System PATH:
D:\libs\opencv-mingw\x64\mingw\bin
Alternative: Install Visual Studio 2022 + vcpkg and run
vcpkg install opencvโ no source build needed.
3. Build ascii-cam
cd /d/Codes/projects/ascii-cam/build
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release
ninjabrew install opencv cmake ninja
mkdir build && cd build
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release
ninjasudo apt update
sudo apt install libopencv-dev cmake ninja-build build-essential
mkdir build && cd build
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release
ninjaWindows:
# Normal ASCII color mode โ live camera
.\ascii-cam.exe
# Local video file
.\ascii-cam.exe --video "D:\myvideo.mp4"
# Matrix rain mode โ live camera
.\ascii-cam.exe --matrix
# Matrix rain mode โ video file
.\ascii-cam.exe --matrix --video "D:\myvideo.mp4"macOS / Linux:
# Normal ASCII color mode โ live camera
./ascii-cam
# Local video file
./ascii-cam --video "/home/user/myvideo.mp4"
# Matrix rain mode โ live camera
./ascii-cam --matrix
# Matrix rain mode โ video file
./ascii-cam --matrix --video "/home/user/myvideo.mp4"Exit with Ctrl+C โ the signal handler cleanly stops the camera and restores the terminal.
โ ๏ธ Note: Matrix mode and terminal control currently only work on Windows. Linux/macOS support is planned.
Exit with Ctrl+C โ the signal handler cleanly stops the camera and restores the terminal.
cmake_minimum_required(VERSION 3.15)
project(ascii-cam)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(OpenCV_DIR "D:/libs/opencv-mingw") # Windows only โ remove on macOS/Linux
find_package(OpenCV REQUIRED)
include_directories(include)
include_directories(${OpenCV_INCLUDE_DIRS})
file(GLOB SOURCES "src/*.cpp")
add_executable(ascii-cam main.cpp ${SOURCES})
target_link_libraries(ascii-cam ${OpenCV_LIBS})- Windows only terminal control โ
terminal.cppuses the Windows Console API. Linux/macOS port requires ncurses or raw ANSI escape codes. - Single camera โ defaults to device
0. ChangeConfig::DEFAULT_DEVICEfor external cameras. - Terminal font matters โ square monospace fonts (Cascadia Code, Fira Mono) give the best aspect ratio. Default Windows terminal fonts may distort proportions.
- Linux/macOS terminal support via ncurses
- Katakana charset for authentic Matrix look
- Configurable charset and FPS via CLI flags
- Record output to file / GIF export
- Edge-detection mode โ outline rendering only
MIT License โ free to use, modify, and distribute with attribution.
Anvay Mayekar
๐ B.Tech in Electronics & Computer Science โ SAKEC, Mumbai
