<commit_before># -*- coding: utf-8 -*-

import cv2
import sys

# Two different ramps
ramp = ' .:-=+*#%@'
ramp = u'█▓▒░ '

def pixel_to_char(pixel):
    brightness = pixel/255.0
    ramp_index = int(len(ramp)*brightness)
    return ramp[ramp_index]

compression_factor = 12
cap = cv2.VideoCapture(0)

while(True):
    ret, img = cap.read()
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    for row in range(len(img)/compression_factor):
        for col in range(len(img[0])/compression_factor):
            pixel = img[row*compression_factor][col*compression_factor]
            sys.stdout.write(pixel_to_char(pixel) * 2)
        sys.stdout.write('\n')<commit_msg>Cleaned things up, use curses<commit_after>import curses
import cv2
import os
import sys

# TODO: Use less CPU

# Returns the number of rows and columns of characters
def get_winsize():
    rows, columns = os.popen('stty size', 'r').read().split()
    return int(rows), int(columns)

def pixel_to_char(pixel):
    ramp = ' .:-=+*#%@'
    brightness = pixel/255.0
    ramp_index = int(len(ramp)*brightness)
    return ramp[ramp_index]

def main(arg):

    # Initialize curses and turn off blinking curser
    curses.initscr()
    curses.curs_set(0)

    rows, columns = get_winsize()
    win = curses.newwin(rows, columns, 0, 0)

    cap = cv2.VideoCapture(0)
    win.refresh()

    ret, img = cap.read()
    compression_factor = max(len(img)/rows, len(img[0])/columns)

    def draw(img):
        for row in range(len(img)/compression_factor):
            for col in range(len(img[0])/compression_factor):
                if curses.is_term_resized(rows, columns):
                    return
                try:
                    pixel = img[row*compression_factor][col*compression_factor]
                    char = pixel_to_char(pixel)
                    win.addch(row, col, char)
                except:
                    pass
        
    while True:
        ret, img = cap.read()
        draw(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY))
        if curses.is_term_resized(rows, columns):
            rows, columns = get_winsize() 
            win = curses.newwin(rows, columns, 0, 0)
            compression_factor = max(len(img)/rows, len(img[0])/columns)
        win.refresh()

curses.wrapper(main)
{'fraction_non_alphanumeric': 0.12692816218598502, 'fraction_numerical': 0.014543851917144116, 'mean_word_length': 2.546875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1125352', 'n_tokens_mistral': 788, 'n_tokens_neox': 772, 'n_words': 163}