9、读写内存卡实验
小于 1 分钟
例程代码
import sensor, image, time
sensor.reset() # 复位并初始化摄像头
sensor.set_pixformat(sensor.RGB565) # 设置摄像头输出格式为 RGB565(也可以是GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # 设置摄像头输出大小为 QVGA (320x240)
sensor.skip_frames(time = 2000) # 跳过2000帧
clock = time.clock() # 创建一个clock对象,用来计算帧率
print("You're on camera!")
img = sensor.snapshot() # 拍照,获取一张图像
# 保存图片为jpg,或者是bmp,或者是其他格式
img.save("/sd/example.jpg") # or "example.bmp" (or others)
print("Done! Reset the camera to see the saved image.")
实验准备
- 准备一张TF卡,并将TF卡插入K210中。
- 通过usb线将K210与电脑连接。
- 打开CanMV IDE,执行上面的例程代码。
实验结果
- 运行之后,K210将会把摄像头捕捉到的画面记录下来,保存在TF卡中。查看TF卡会发现example.jpg,打开此jpg文件即是刚才拍摄的画面。
例程代码讲解
略,详见例程代码注释。