最近入手了个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)
下面简单画个矩形
样例代码
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来做色彩追踪
喜欢就关注我吧!
相关代码可以在公众号后台获取。