脚本结构 ================ 现在让我们学习如何编程您的OpenMV!请注意,这个教程假设你知道python语言是如何工作的。 如果你不知道python是如何工作的,请研究它。有很多关于如何编写python代码的网上教程 (最后,如果你知道任何其他类似C的编程语言,你可以轻松地使用python,因为它非常相似)。 无论如何,你写的任何脚本将有三个不同的部分:: import ... ... 一次设置 ... ... while(True): # Loop ... OpenMV Cam代码的第一部分应该包含一些头部注释,将模块引入到代码,最后是代码中的常量和全局变量。 接下来,你将要做一次性的设置代码。这包括创建I / O引脚对象,设置摄像头,定义辅助函数等。 最后,你将创建一个 ``while(True):`` 循环,在这个循环之下,你放进去的全部代码将会在循环中重复调用,知道关闭电源。 这是一个例子:: ### 头部注释,导入语句等 # Hello World Example # Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script! # 欢迎使用OpenMV IDE!点击下面绿色的运行箭头按钮来运行脚本! import sensor, image, time ### 一次设置 sensor.reset() # Reset and initialize the sensor. 复位并初始化传感器。 sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE) 设置像素格式为RGB565(或灰度) sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240) 设置图像大小为QVGA (320x240 sensor.skip_frames(time = 2000) # Wait for settings take effect. 等待设置生效。 clock = time.clock() # Create a clock object to track the FPS. 创建一个时钟对象来跟踪FPS。 ### 无限循环 while(True): clock.tick() # Update the FPS clock. 更新FPS时钟。 img = sensor.snapshot() # Take a picture and return the image. 拍照并返回图像。 print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected 注意:OpenMV Cam连接ide后的运行速度大约是原来的一半 # to the IDE. The FPS should increase once disconnected. 一旦断开ide,FPS应该增加。 请注意,如果您的代码中没有无限的while循环,那么一旦您的OpenMV Cam完成运行脚本,它将停在那里,什么都不做。