A terminal ASCII art renderer that converts images, videos, and live camera feeds to ASCII art using OpenCV and ncurses.
- Three color modes: GRAYSCALE, COLOR_16, COLOR_256
- Three ASCII palettes: Standard (10), Balanced (20), Detailed (70)
- Three input types: static images, video files, live camera
- Three image modes: current terminal, new terminal window, or generated PNG
- Frame-accurate video playback at original FPS
- Terminal resize handling via SIGWINCH (images in current terminal mode)
- Aspect ratio preservation for all media types
- Interactive ncurses menu with arrow key navigation
- Generated ASCII image export at 64, 128, or 256 characters on the shorter edge
opencv2term/
βββ include/
β βββ AsciiPalette.h
β βββ AsciiRenderer.h
β βββ DisplayManager.h
β βββ MenuManager.h
β βββ ImageProcessor.h
β βββ VideoProcessor.h
β βββ CameraProcessor.h
βββ src/
β βββ main.cpp
β βββ AsciiPalette.cpp
β βββ AsciiRenderer.cpp
β βββ DisplayManager.cpp
β βββ MenuManager.cpp
β βββ ImageProcessor.cpp
β βββ VideoProcessor.cpp
β βββ CameraProcessor.cpp
βββ images/ # Input media directory (gitignored)
βββ outputs/ # Generated ASCII images (gitignored)
βββ build/ # Build artifacts (gitignored)
βββ CMakeLists.txt
βββ README.md
- CMake 3.10+
- C++17 compiler
- OpenCV 4.x
- ncurses
brew install cmake opencvmkdir -p build && cd build
cmake ..
makecd build
./OpenCVProjectMedia files must be placed in images/ relative to the project root (one level above the binary).
- Place image or video files in the
images/directory. - Run
./OpenCVProjectfrom thebuild/directory. - Follow the interactive menu:
- Select an ASCII palette
- Select a color mode
- Select media type (Image, Video, or Camera)
- Select a file (Image and Video only)
- Select a display mode
- Select an output density if generating an ASCII image file
- UP/DOWN arrow keys to move
- ENTER to select
- Q to quit
| Mode | Input | Behavior |
|---|---|---|
| Current terminal | Image | Live resize on SIGWINCH, press Q or ENTER to exit |
| Current terminal | Video | Plays at original FPS, press Q or ENTER to stop |
| Current terminal | Camera | Real-time webcam feed, press Q or ENTER to stop |
| New window | Image | Opens separate terminal window, press any key to close |
| New window | Video | Opens separate terminal window, loops until Ctrl+C |
| New window | Camera | Falls back to current terminal mode |
| Generated PNG | Image | Writes a dark-background ASCII image to outputs/ |
Image inputs can be exported as PNG files with dark backgrounds. The size presets control ASCII density, not final bitmap dimensions:
| Density | ASCII cells |
|---|---|
| Small | 64 characters on the shorter edge |
| Medium | 128 characters on the shorter edge |
| Large | 256 characters on the shorter edge |
The longer edge is calculated from the source image aspect ratio and measured character-cell dimensions. Rendering accounts for glyph width, baseline, and line height before resizing the source into ASCII cells, so the result is not stretched as if every ASCII character were a 1x1 pixel.
The final PNG pixel dimensions depend on the input image size and selected density. The renderer does not add extra letter spacing or line spacing, which keeps the ASCII texture tight and readable.
| Name | Characters | Description |
|---|---|---|
| Standard | 10 | . : - = + * # % @ β fast, minimal |
| Balanced | 20 | Extended set with punctuation β good general purpose |
| Detailed | 70 | Full gradient β maximum shading and detail |
GRAYSCALE
- Monochrome output using brightness-mapped characters only.
- Fastest rendering, works on all terminals.
COLOR_16
- Maps each pixel's RGB values to the nearest of 16 ANSI terminal colors (colors 0-15).
- Requires a color-capable terminal.
COLOR_256
- Maps pixels to a 216-color RGB cube (colors 16-231) for finer color fidelity.
- Requires a 256-color terminal (most modern terminals qualify).
- Uses up to 256 ncurses color pairs.
All three modes use the same brightness-based character selection; color mode only affects the foreground color applied to each character.
.jpg, .jpeg, .png, .webp, .bmp, .gif, .tiff, .tif
.mp4, .avi, .mov, .mkv, .wmv, .flv, .webm
All formats are handled by OpenCV; actual support depends on the codecs available in your OpenCV build.
Default capture device (ID 0). Camera access requires appropriate OS permissions.
macOS: System Settings β Privacy & Security β Camera β enable Terminal.
- New palette: add to
AsciiPalette::getDefaultPalettes()insrc/AsciiPalette.cpp - New color mode: extend
AsciiRenderer::renderToMatrixWithColor()and add initialization inDisplayManager::initializeColors() - New display mode: add a method to
DisplayManager - New media type: create a new processor class following the
VideoProcessor/CameraProcessorpattern and wire it intosrc/main.cpp
- Class-based architecture with clear separation of concerns
- RAII for resource management (ncurses
endwin(), OpenCVcap.release()) - Functional callbacks (
frameProvider) passed toDisplayManager::displayVideoInTerminal() - Minimal global state
- ASCII gradient research: jp2a, aalib
- Image processing: OpenCV
- Terminal UI: ncurses