Git Product home page Git Product logo

video2txt's Introduction

video2txt

[TOC]

  • version : 1.0
  • author : ZhengYinloong
  • githubRep-url : video2txt
  • requirements : cv2, os
  • environment : python3 on Windows10

简介

video2txt包由我原来一时兴起写的的ImgToTxt模块发展而来,经过多次完善,形成了由三个功能模块(captureImg.py, putTxt2File.py, display.py),一个初始化文件(_init_.py)和一个主程序执行文件(main.py)组成的比较完善的视频转字符画工具包。

各模块/文件功能概览

模块/文件 功能 包含的类或函数
_init_.py 初始化参数 class:Video2Txt
captureImg.py 提取视频帧并保存为图片 function:capPosFrame(), captureImgs(), do(), frameResize(), getTotalFrames(), saveImg(), showPosFrame()
putTxt2File.py 识别图片像素灰度并用字符代替,并存放在txt文件中 function:do(), getOneRowChar(), getText(), gray2Char(), imgResize(), putTxt2File()
display.py 将txt文件依次输出在终端 function:clear(), do(), showTxt()
main.py 包含一个do()函数,在终端使用do() function:do()

详细说明

_init_.py

该文件中定义了一个Video2Txt类用来初始化参数,包含以下属性:

属性 默认值 说明
FPS 24 < float >0 > txt文件“播放”的“帧率”
GRAY_SCALE_STR r'$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_+~<>i!lI;:,"^`. ' < str > 灰度等级字符
IMG_FOLDER 'imgs_default' < str > img文件要存放的文件夹
IMG_FORMAT 'bmp' < str > 图片保存格式
IMG_HEIGHT 100 < int > 图片重新设置 高
IMG_WIDTH 100 < int > 图片重新设置 宽
RATIO 4 / 9 < float > 根据cmd终端字符比例(属性->字体)调整字符画(宽 / 高)
SCALE 1.0 < float > 转字符画时对图片缩放
STEP 10 < int > 跳帧,默认每十帧取一帧
TXT_FOLDER 'txts_default' < str > txt文件要存放的文件夹
VIDEO_NAME 'video/video_default.mp4' < str > 视频文件

captureImg.py

该模块的功能是提取视频帧并保存为图片。

包含的函数:

  • getTotalFrames():获取视频总帧数。
  • capPosFrame():获取视频特定帧。
  • frameResize():重设获取到的帧宽和高。
  • saveImg():对cv2.imwrite()重新封装,将像素矩阵保存为图片。
  • showPosFrame():显示视频指定帧,默认彩色,不进行缩放。
  • captureImgs():获取并保存视频所有帧,当然也可以指定帧间隔。

putTxt2File.py

该模块功能是识别图片像素灰度并用字符代替,并存放在txt文件中。

包含的函数:

display.py

该模块功能是将txt文件依次输出在终端。

包含的函数:

  • do():将txt文件依次输出在终端。引用该函数的程序需要直接在终端执行。

main.py

包含一个do()函数,在终端执行该do()函数将直接输出转换成功的“字符画”视频(可能需要几分钟时间)

安装与使用

由于本人是在Windows10的python3环境下开发和应用的该工具包,其他环境本人没有条件实验😂

  1. 安装前提:先安装cv2包 pip install opencv-python

  2. 安装好cv2后,直接下载或clone该仓库到你的设备上python解释器所在文件夹下 Lib>site-packages 中(如下图所示),即可在你的设备上任何IDE的.py文件中调用该包中任何模块、类和函数。

    安装

BUG

该工具包目前有一个已知bug:

由于captureImg.saveImg()中调用了cv2.imwrite()函数,会出现内存中一直加载文件目录无法释放的问题,这会导致调用后无法对相关文件夹进行移动,重命名等操作。这个问题我也是在调试与使用中发现的,一直没有解决的办法😑,欢迎各位多多发pull request啊😀😀

TOP

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.