openmv学习之旅-1

最近入手了个OpenMv。
装IDE这种小事就不说了。说说真正入门的操作吧。对Python也没啥要求。我也是这样子马上上手的,当然在过程我是学习了Python的。

1:绘制矩形

函数说明

image.draw_rectangle(rect_tuple,颜色=白色)

参数

rect_tuple

格式(x,y,w,h)

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

w:矩形的宽度

h:矩形的高度

x,y,w,h均为整数

颜色

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

下面简单画个矩形

openmv-1-openmv

样例代码

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 = 100
width = 100
height = 100

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

这就是简单画矩形的图像,想要改变矩形位置就改变的x,y(图像左上角起点)

想要改变矩形面积就改变宽度,高度(图像宽&高)改变线条颜色就改变 rgb_white

2:绘制十字

函数说明

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

参数

X

十字中心的 X 坐标

Y

十字中心的 y 坐标

尺寸

十字的长度

颜色

颜色,填入灰度值(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

学会简单画图,就可以使用 openmv 来做色彩追踪了。

未完待续……下篇用openmv来做色彩追踪

喜欢就关注我吧!

欢迎关注我公众号

相关代码可以在公众号后台获取。


  转载请注明: 杰杰的博客 openmv学习之旅-1

 上一篇
openmv学习之旅-2 openmv学习之旅-2
大家好,我是杰杰。 从上一篇openmv的学习中openmv学习之旅-1 我们可以很简单运用micropython在openmv上做我们想做的事情。 Python这个东西用起来是很简单的,,下面来说说改善色块追踪的算法 先做个改善前的分析吧
2019-08-31
下一篇 
单片机C语言知识用法之#define 单片机C语言知识用法之#define
#define的定义:#define是C语言中的一个预处理指令,其中的“#”表示这是一条预处理命令·。凡是以“#”开头的均为预处理命令,“define”为宏定义命令,“标识符”为所定义的宏名。 #define TIME_NUM 1000
2019-08-31
  目录