logo

运行gif录制动图时,每次都会自动断开连接,并且录制出来的gif打不开

2021-07-29 20:18
M
q14z
# 录制动图例程
#
# 注意:您将需要SD卡来运行此示例。
#
# You can use your OpenMV Cam to record gif files. You can either feed the
# recorder object RGB565 frames or Grayscale frames. Use photo editing software
# like GIMP to compress and optimize the Gif before uploading it to the web.
# 你可以用你的OpenMV摄像头来记录gif文件。您可以提供记录器对象RGB565帧或灰度帧。
# 使用像GIMP这样的照片编辑软件来压缩和优化Gif,然后再上传到web。

import sensor, image, time, gif, pyb

RED_LED_PIN = 1
BLUE_LED_PIN = 3

sensor.reset() # 初始化sensor

sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
#设置图像色彩格式,有RGB565色彩图和GRAYSCALE灰度图两种

sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
#设置图像像素大小

sensor.skip_frames(time = 2000) # 让新的设置生效
clock = time.clock() # 跟踪FPS帧率

pyb.LED(RED_LED_PIN).on()
sensor.skip_frames(30) # Give the user time to get ready.
#程序开始时,先等待30帧图像,让用户有时间准备

pyb.LED(RED_LED_PIN).off()
pyb.LED(BLUE_LED_PIN).on()

g = gif.Gif("example.gif", loop=True)
#gif.Gif(filename, width=Auto, height=Auto, color=Auto, loop=True)创建一个gif对象,filename为保存gif动图的文件路径

print("You're on camera!")
for i in range(100):
    clock.tick()
    # clock.avg()返回帧与帧之间的毫秒数,其中包含gif延迟
    g.add_frame(sensor.snapshot(), delay=10) # centiseconds.
    #gif.add_frame(image, delay=10),向gif动图中添加图片,delay=10指每隔
    #10分秒添加一张图。
    print(clock.fps())

g.close()
pyb.LED(BLUE_LED_PIN).off()
print("Done! Reset the camera to see the saved recording.")

用的是openmvh7 plus 最新的固件版本

2021-07-29 20:25
M
q14z

好了问题已经解决了,是因为没有插SD卡