Skip to content
Snippets Groups Projects

asciicam.py

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by defnull
    Edited
    asciicam.py 488 B
    import cv2
    import os
    import sys
    
    cap = cv2.VideoCapture(0)
    height, width = map(int, os.popen('stty size', 'r').read().split())
    write = sys.stdout.write
    
    try:
      while(True):
        ret, frame = cap.read()
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        frame = cv2.resize(frame, (width, height))
        write('\u001b[1;1H' + '\n'.join(''.join(" .',:;clxokXdO0KN"[c//16] for c in row) for row in frame))
    except KeyboardInterrupt:
      pass
    finally:
      cap.release()
      cv2.destroyAllWindows()
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment