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)
Published August 18, 2019
Comments