例程讲解-06-gif录制动图

本例程为 06-Video_Recording-gif.py
本例程的目标是利用openmv录制动图。

# GIF Video Recording Example
#
# Note: You will need an SD card to run this example.
#
# 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.

import sensor, image, time, gif, pyb

RED_LED_PIN = 1
BLUE_LED_PIN = 3

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(10) # Let new settings take affect.
clock = time.clock() # Tracks 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() returns the milliseconds between frames - gif delay is in
    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.")

星瞳科技OpenMV官方中文文档函数讲解:

results matching ""

    No results matching ""