Drawing
Visual systems usually need to provide some feedback to users. It is very intuitive to display it directly in the image. Just like in the 10-minute quick start program, when a color block is found, mark this area with a rectangular box, which is very intuitive.
Note:
The color can be a grayscale value (0-255) or a tupple of color values (r, g, b). The default is white.
The color keyword must be explicitly marked with color=. For example:
image.draw_line((10,10,20,30), color=(255,0,0))
image.draw_rectangle(rect_tuple, color=(255,0,0))
Drawing a line
- image.draw_line(line_tuple, color=White) Draw a straight line in the image.
- The format of line_tuple is (x0, y0, x1, y1), which means a straight line from (x0, y0) to (x1, y1).
- The color can be a grayscale value (0-255) or a tupple of color values (r, g, b). The default is white
Drawing a box
- image.draw_rectangle(rect_tuple, color=White) Draw a rectangular box in the
image.
- The format of rect_tuple is (x, y, w, h).
Draw a circle
- image.draw_circle(x, y, radius, color=White) Draw a circle in the image.
- x,y are the coordinates of the center of the circle
- radius is the radius of the circle
Draw a cross
- image.draw_cross(x, y, size=5, color=White) Draw a cross in the image
- x,y are the coordinates
- size is the size of the two sides
Write text
- image.draw_string(x, y, text, color=White) Write text in the image 8x10 pixels
- x,y are the coordinates. Using \n, \r, and \r\n will move the cursor to the next line.
- text is the string to be written.
Example
# Hello World Example
#
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!
import sensor, image, time
sensor.reset() # 初始化摄像头
sensor.set_pixformat(sensor.RGB565) # 格式为 RGB565.
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(10) # 跳过10帧,使新设置生效
while(True):
img = sensor.snapshot() # Take a picture and return the image.
img.draw_line((20, 30, 40, 50))
img.draw_line((80, 50, 100, 100), color=(255,0,0))
img.draw_rectangle((20, 30, 41, 51), color=(255,0,0))
img.draw_circle(50, 50, 30)
img.draw_cross(90,60,size=10)
img.draw_string(10,10, "hello world!")