# Animated line drawings with OpenCV

DevFeed: [Animated line drawings with OpenCV](<https://devfeed.tech/articles/animated-line-drawings-with-opencv-21653.md>)

Original publisher: [Read original article](<https://www.windytan.com/2017/12/animated-line-drawings-with-opencv.html>)

Author: Oona Räisänen (noreply@blogger.com)

Published: 2017-12-30T12:15:00Z

Content type: tutorial

Language: en

Sources: [Oona Räisänen](<https://devfeed.tech/sources/oona-raisanen.md>)

Topics: [OpenCV](<https://devfeed.tech/topics/opencv.md>), [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [Computer vision](<https://devfeed.tech/topics/computer-vision.md>), [CMake](<https://devfeed.tech/topics/cmake.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>)

Tags: [art](<https://devfeed.tech/tags/art.md>), [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [canvas](<https://devfeed.tech/tags/canvas.md>), [cmake](<https://devfeed.tech/tags/cmake.md>), [compiler-flags](<https://devfeed.tech/tags/compiler-flags.md>), [computer-vision](<https://devfeed.tech/tags/computer-vision.md>), [gaussian](<https://devfeed.tech/tags/gaussian.md>), [graphics](<https://devfeed.tech/tags/graphics.md>), [gui](<https://devfeed.tech/tags/gui.md>), [make](<https://devfeed.tech/tags/make.md>), [music](<https://devfeed.tech/tags/music.md>), [plotting](<https://devfeed.tech/tags/plotting.md>), [programming](<https://devfeed.tech/tags/programming.md>), [rgb](<https://devfeed.tech/tags/rgb.md>), [rotation](<https://devfeed.tech/tags/rotation.md>), [subpixel](<https://devfeed.tech/tags/subpixel.md>), [terminal](<https://devfeed.tech/tags/terminal.md>), [vector](<https://devfeed.tech/tags/vector.md>), [video](<https://devfeed.tech/tags/video.md>)

## AI overview

This tutorial shows how to use OpenCV and C++ to create pixel-level animated graphics and save them as video. It covers project setup with CMake, drawing rotating concentric rings on an RGB canvas, subpixel antialiasing, and a Gaussian blur glow effect.

## Source excerpt

OpenCV is a pretty versatile C++ computer vision library. Because I use it every day it has also become my go-to tool for creating simple animations at pixel level, for fun, and saving them as video files. This is not one of its core functions but happens to be possible using its GUI drawing tools. Below we'll take a look at some video art I wrote for a music project. It goes a bit further than just line drawings but the rest is pretty much just flavouring. As you'll see, creating images in OpenCV has a lot in common with how you would work with layers and filters in an image editor like GIMP or Photoshop. Setting it up It doesn't take a lot of boilerplate to initialize an OpenCV project. Here's my minimal CMakeLists.txt: cmake_minimum_required (VERSION 2.8) project (marmalade) find_package (OpenCV REQUIRED) add_executable (marmalade marmalade.cc) target_link_libraries (marmalade ${OpenCV_LIBS}) I also like to set compiler flags to enforce the C++11 standard, but this is not necessary. In the main .cc file I have: #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" Now you can build the project by just typing cmake . && make in the terminal. Basic shapes First, we'll need an empty canvas. It will be a matrix (cv::Mat) with three unsigned char channels for RGB at Full HD resolution: const cv::Size video_size(1920, 1080); cv::Mat mat_frame = cv::Mat::zeros(video_size, CV_8UC3); This will also initialize everything to zero, i.e. black. Now we can draw our graphics! I had an initial idea of an endless cascade of concentric rings each rotating at a different speed. There might be color and brightness variations as well but otherwise it would stay static the whole time. You can't see a circle's rotation around its center, so we'll add some features to them as well, maybe some kind of bars or spokes. A simplified render method for a ring would look like this: void Ring::RenderTo(cv::Mat& mat_output) const { cv::circle(mat_output, 8 * center_, 8 *