0penMV画图

绘制文字

函数说明

image.draw_string(x, y, text, color=White)

参数

x,y

字符串起始坐标

text

字符串的内容, 如果转义字符为\n , \r, \r\n 光标会移入下一行。

每个单词的大小为8 * 10

color

颜色,填入灰度值(0-255), 或者RGB值(r, g, b)

样例代码


import sensor, image, time

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(30)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.


x = 150
y = 150


rgb_white = (255, 255, 255) # (r=255, g=255, b=255) -> white color

while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.
    img.draw_string(x, y, "HELLO WORLD", color=rgb_white)

    print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected
                                    # to the IDE. The FPS should increase once disconnected.

效果展示

draw_string_demo

绘制直线

函数说明

image.draw_line(line_tuple, color=White)

参数

line_tuple

数据格式 (x0, y0, x1, y1), 标注了线条的起始点(x0, y0)到终止点(x1, y1)的坐标

x0, y0, x1, y1 均为整数

color

线条颜色, 传入tuple, White是一个预定义的tuple

如果tuple长度为1, 例如(125), 则代表颜色为灰度,取值范围是(0-255)

如果tuple长度为3 ,格式 (r, g, b), 代表红 ,绿,蓝三个通道的值

传入参数时,必须显式声明color=

样例代码

import sensor, image, time

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(30)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.


sp = (200, 50) # start point (x, y)
ep = (100, 150) # end point (x, y)
rgb_white = (255, 255, 255) # (r=255, g=255, b=255) -> white color

line_tuple = (sp[0], sp[1], ep[0], ep[1])
while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.
    img.draw_string(sp[0], sp[1], "(%d, %d)"%(sp[0], sp[1]), color=rgb_white)
    img.draw_string(ep[0], ep[1], "(%d, %d)"%(ep[0], ep[1]), color=rgb_white)
    img.draw_line(line_tuple, color=rgb_white)

    print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected
                                    # to the IDE. The FPS should increase once disconnected.

效果展示

draw_line_demo

绘制矩形

函数说明

image.draw_rectangle(rect_tuple, color=White)

参数

rect_tuple

格式 (x, y, w, h)

矩阵的起始坐标, (x, y), 即矩形的左上角坐标

w : 矩形的宽度

h : 矩形的高度

x, y, w, h 均为整数

color

颜色,填入灰度值(0-255), 或者RGB值(r, g, b)

样例代码


import sensor, image, time

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(30)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.


x = 100
y = 50A
width = 100
height = 150

rect_tuple = (x, y, width, height)

rgb_white = (255, 255, 255) # (r=255, g=255, b=255) -> white color

while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.
    img.draw_string(x, y, "(%d, %d)"%(x, y), color=rgb_white)
    img.draw_rectangle(rect_tuple, color=rgb_white)

    print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected
                                    # to the IDE. The FPS should increase once disconnected.

效果展示

draw_rectangle_demo

绘制圆形

函数说明

image.draw_circle(x, y, radius, color=White)

参数

x

参数类型:整数

圆心x坐标

y

参数类型: 整数

圆心y坐标

radius

圆的半径

color

颜色,填入灰度值(0-255), 或者RGB值(r, g, b)`

样例代码

import sensor, image, time

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(30)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.


x = 150
y = 150
radius = 50

rgb_white = (255, 255, 255) # (r=255, g=255, b=255) -> white color

while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshotA()         # Take a picture and return the image.
    img.draw_string(x, y, "(%d, %d)"%(x, y), color=rgb_white)
    img.draw_circle(x, y, radius, color=rgb_white)

    print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected
                                    # to the IDE. The FPS should increase once disconnected.

效果展示

draw_circle_demo

绘制十字

函数说明

image.draw_cross(x, y, size=5, color=White)

参数

x

十字中心的x坐标

y

十字中心的y坐标

size

十字的长度

color

颜色,填入灰度值(0-255), 或者RGB值(r, g, b)

样例代码

import sensor, image, time

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(30)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.


x = 150
y = 150
size = 20

rgb_white = (255, 255, 255) # (r=255, g=255, b=255) -> white color

while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshotA()         # Take a picture and return the image.
    img.draw_string(x, y, "(%d, %d)"%(x, y), color=rgb_white)
    img.draw_cross(x, y, size=size, color=rgb_white)

    print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected
                                    # to the IDE. The FPS should increase once disconnected.

效果展示

size=10

draw_cross_demo_01

size=20

draw_cross_demo_02

绘制关键点

函数说明

image.draw_keypoints(keypoints, size=Auto, color=White)

用于在图像上绘制关键点。

keypoints

关键点列表

keypoints并不属于Python中的数据类型,底层是C语言里面自定义的一个struct,

打印效果
size:78 threshold:10 normalized:1
所属类
<class 'kp_desc'>

find_keypoints的返回对象即为keypoints

kpts2 = img.find_keypoints(threshold=10, scale_factor=1.1, max_keypoints=100, normalized=True)

size

默认为Auto

自适应大小, 也可以特别指定

color

颜色,填入灰度值(0-255), 或者RGB值(r, g, b)

Copyright 杭州云江科技有限公司 2017 all right reserved,powered by Gitbook该文件修订时间: 2019-04-06 01:14:21

results matching ""

    No results matching ""