openmv/usr/examples/03-Drawing/text_drawing.py
2018-03-16 01:27:51 -04:00

32 lines
994 B
Python

# Text Drawing
#
# This example shows off drawing text on the OpenMV Cam.
import sensor, image, time, pyb
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # or GRAYSCALE...
sensor.set_framesize(sensor.QVGA) # or QQVGA...
sensor.skip_frames(time = 2000)
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot()
for i in range(10):
x = (pyb.rng() % (2*img.width())) - (img.width()//2)
y = (pyb.rng() % (2*img.height())) - (img.height()//2)
r = (pyb.rng() % 127) + 128
g = (pyb.rng() % 127) + 128
b = (pyb.rng() % 127) + 128
# If the first argument is a scaler then this method expects
# to see x, y, and text. Otherwise, it expects a (x,y,text) tuple.
img.draw_string(x, y, "Hello World!", color = (r, g, b), scale = 2,
x_spacing = -4, # You'll want to make these negative
y_spacing = 0) # at higher scales to reduce kerning.
print(clock.fps())