0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

残プロ 第-38回 ~コンソールにaa動画を表示する~

Posted at

ANSIエスケープシーケンス

前回,画像のアスキーアート化について紹介しました.
今回はANSIエスケープシーケンスを使って動画の表示に挑戦したいと思います.

.py

必要最低限の機能であれば,以下プログラムで実現できます.
PCに接続されたカメラから画像を取得しAA化,表示を1秒に数回行います.

VideoPrint.py
import cv2

cap = cv2.VideoCapture(0)
wid = 90
density = list("MWN$@%#&B89EGA6mK5HRkbYT43V0JL7gpaseyxznocv?jIftr1li*=-~^`':;,. ")

try:
    while(True):
        ret, frame = cap.read()
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        resized = cv2.resize(gray, (int(wid*2),int(wid)))
        for i in range(resized.shape[0]):
            s = ""
            for j in range(resized.shape[1]):
                s += density[(len(density)-1)-resized[i][j]//(256//len(density))]
            print(s)
        print("\033[{}F".format(wid+1))

except KeyboardInterrupt:
    cap.release()
    print("\033[{}E".format(wid+1))
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?