[原创] openmv学习之旅①
1154 查看
3 回复
 楼主 | 发布于 2018-03-07 | 只看楼主
分享到:
最近入手了个OpenMv,还要感谢二姨家的平台啊。感谢
装IDE这种小事就不说了。说说真正入门的操作吧。对python也没啥要求。我也是这样子马上上手的,当然在过程我是学习了python的。

1:绘制矩形
绘制矩形
函数说明
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 = 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



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

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


2绘制十字

函数说明

image.draw_crossxysize = 5color = White

参数

X

十字中心的 X 坐标

ÿ

十字中心的 ÿ 坐标

尺寸

十字的长度

颜色

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

样例代码

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()) 


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

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




(1 ) (0 )

嵌入式学习

回复 举报

回复于 2018-03-07 沙发

(0 )
评论 (0) 举报

回复于 2018-03-08 2#

感谢分享
(0 )
评论 (0) 举报

回复于 2018-03-08 3#

不错,感谢分享经验;
(0 )
评论 (0) 举报
  • 发表回复
    0/3000





    举报

    请选择举报类别

    • 广告垃圾
    • 违规内容
    • 恶意灌水
    • 重复发帖

    全部板块

    返回顶部