Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert Video into character painting by Python

Shulou Source: shulou.com Published: 2022-06-02 06:48:50 09月11日 Update

This article is about how Python converts video to character painting. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

First read the video and convert it to characters. The video was downloaded from bilibili at the address of the famous pangolin scene in the south of the Yangtze River.

As the video downloaded directly by bilibili is in flv format, but imageio does not support it, although it can be read with opencv, by contrast, it is not complicated to transcode with ffmepg, so you can make maximum use of Huaqiang's code to buy melons.

In addition, the video material is too long for code demonstration, so intercept 15s from 2: 10.

Enter on the command line

> pip install ffmpeg > ffmpeg-I soup.flv-ss 00:02:10-t 15 seg.mp4-y

Soon got the seg.mp4, the next is to read the video and convert to characters, for the parsing of this part of the code, you can go out and turn left to Huaqiang to buy melons.

Import imageioimport numpy as npimport matplotlib.pyplot as pltvideo = imageio.get_reader ('seg.mp4') imgs = [np.mean (im,2) for im in video] plt.imshow (imgs [30]) plt.show ()

This video is too large for character painting, so you need to compress it before turning it into character painting. The simplest method is taken here-that is, to average the adjacent pixels.

# reduce the width of the image to widthfrom itertools import product # for circular nesting def resizeImg (img,w,h=None): Mrecine n = img.shape if n

Tags: Characters video next code fonts pixels content mean width that is more articles Huaqiang reference related testing good complex practical consistent Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Linux MySQL NVidia Xiaomi