jason pilarski
Published

ASCII 0_1 Stream

Converting the camera sensor feed to 0 and 1 ASCII art.

BeginnerWork in progress1 hour804
ASCII 0_1 Stream

Things used in this project

Hardware components

M5StickV K210 AI Camera (Without Wifi)
M5Stack M5StickV K210 AI Camera (Without Wifi)
×1

Software apps and online services

maixpy

Story

Read more

Code

ascii stream

MicroPython
import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
#QQVGA2 and 8 10 for size might work for twitter
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
pixels_wide = sensor.width()
pixels_high = sensor.height()
font_width = 8
font_height = 10
cut_off = 225
chars_wide = pixels_wide//font_width
chars_high = pixels_high//font_height
reduced_count = chars_wide * chars_high
pixel_array = range(reduced_count)
grayscale_thres = (20, 95)
clock = time.clock()

while(True):
    #Methods clock.tick()
    clock.tick()
    img = sensor.snapshot()
    img.binary([grayscale_thres])
    for y in range(0, pixels_high, font_height):
        for x in range(0, pixels_wide, font_width):
            pixel_xy = (x,y)
            ascii = img.get_pixel(pixel_xy)
            if ascii >= cut_off:
                ascii = 1
            ascii = str(ascii)
            img.draw_rectangle(x, y, font_width, font_height, color=(0,0,0), fill = True)
            img.draw_string(x, y, ascii)

Credits

jason pilarski

jason pilarski

2 projects • 1 follower

Comments

Add projectSign up / Login