Esempio n. 1
0
def saveVideo(save_start=1, frames=100000, format="mjpeg"):
    global save_flag
    if save_flag:
        global FRAMES
        if format == "mjpeg":
            global m
        else:
            global g
        if save_start == 0:
            pyb.LED(3).on()
            if format == "mjpeg":
                m = mjpeg.Mjpeg("test_%s.mjpeg" % pyb.rng())
            else:
                g = gif.Gif("test_%s.gif" % pyb.rng())
            FRAMES = frames
        elif save_start == 1:
            global img
            # 记录帧
            if record_pin.value() and FRAMES > 0:
                if format == "mjpeg":
                    m.add_frame(img, quality=30)
                else:
                    g.add_frame(img, delay=6)  # 10FPS
                FRAMES -= 1
            else:
                saveVideo(2)
        else:
            pyb.LED(3).off()
            if format == "mjpeg":
                m.close(clock.fps())
            else:
                g.close()
            save_flag = 0
Esempio n. 2
0
def set_url(bot, update, user_data):
    logger.info("set_url")

    video.clear_user_files('output', str(update.effective_user.id))
    url = update.message.text
    user_data["gif"] = gif.Gif(str(update.effective_user.id))

    try:
        user_data["gif"].url = url
    except ValueError:
        bot.send_message(
            chat_id=update.message.chat_id,
            text=
            "please enter a secure youtube url like (https://www.youtube.com...)"
        )
        return 0

    output_path = "output/" + str(update.effective_user.id)
    user_data["gif"].set_metadata(video.dl_youtube_url(url, False,
                                                       output_path))

    bot.send_message(chat_id=update.message.chat_id,
                     text="start time? (%H:%M:%S.xxx)")

    return 1
Esempio n. 3
0
def imagefy(json):
    direction = json['direction']
    size = get_image_size(direction)
    width, height = size['width'], size['height']
    data, colors = json_to_data(json['colors'], direction, width, height)
    print(colors)
    gif_image = gif.Gif(data, width, height, colors)

    return gif_image.to_bytes()
Esempio n. 4
0
def test_start_time():
    a = gif.Gif("0")
    a.set_start_time("00:00:03")
    a.set_stop_time("00:00:05")

    try:
        a.set_stop_time("00:00:02")
    except ValueError:
        assert True
    sensor.skip_frames(time=2000)  # Give the user time to get ready.

    pyb.LED(RED_LED_PIN).off()
    sensor.snapshot().save("temp/bg.bmp")
    print("Saved background image - Now detecting motion!")
    pyb.LED(BLUE_LED_PIN).on()

    diff = 10  # 连续测试10帧,减少误判.
    while (diff):
        img = sensor.snapshot()
        img.difference("temp/bg.bmp")
        stats = img.statistics()
        #下面Stats[5] 返回RGB5656 LAB 中L的最大值(0-255) (int),大于20判定为图片变化,即物体移动.
        if (stats[5] > 20):
            diff -= 1

    g = gif.Gif("example-%d.gif" % pyb.rng(), loop=True)

    clock = time.clock()  # Tracks FPS.
    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=int(clock.avg() / 10))  # centiseconds.
        print(clock.fps())

    g.close()
    pyb.LED(BLUE_LED_PIN).off()
    print("Restarting...")
Esempio n. 6
0
#sensor.skip_frames(time = 2000)

#m = mjpeg.Mjpeg('openmv_video.mjpeg')

#clock = time.clock()
#start = pyb.millis()
#record_time=5000
#while(pyb.elapsed_millis(start) < record_time):
#clock.tick()
#m.add_frame(sensor.snapshot())
#print('closed record')
#m.close(clock.fps())

import sensor, gif

# Setup camera.
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames()

# Create the gif object.
g = gif.Gif("example.gif")

# Add frames.
for i in range(100):
    g.add_frame(sensor.snapshot())
    #print('saved')
# Finalize.
g.close()
Esempio n. 7
0
import gif
import os
import pickle
import configparser
import time
import subprocess

ACCOUNTS_FILE = 'accounts.zoomgtadonotopenverysecret'
CONFIG_FILE = 'config.zoomgta.ini'
gif = gif.Gif()
cfg = configparser.ConfigParser()
current_account = 0
if os.path.exists(CONFIG_FILE) and os.path.getsize(CONFIG_FILE) > 0:
    cfg.read(CONFIG_FILE)
    def_gif = cfg['General']['DefaultGifPath']
    def_delay = cfg['General']['DefaultDelay']
else:
    def_gif = None
    def_delay = 1

if os.path.exists(ACCOUNTS_FILE) and os.path.getsize(ACCOUNTS_FILE) > 0:
    accounts = pickle.load(open(ACCOUNTS_FILE, 'rb'))
else:
    accounts = []
# start_gui = input('Start GUI? (y/n)')
# if start_gui == 'y':
#     import gui
#     exit(0)
# TODO: GUI
print('If you like this program, please, consider donating:\n'
      'https://donatepay.ru/don/pozhiloyenotik\n'
Esempio n. 8
0
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(time = 2000) # Let new settings take affect.
clock = time.clock() # Tracks FPS.

pyb.LED(RED_LED_PIN).on()
sensor.skip_frames(time = 2000) # Give the user time to get ready.

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

g = gif.Gif("example.gif", loop=True)

print("You're on camera!")
for i in range(100):
    clock.tick()
    # clock.avg() returns the milliseconds between camera - gif delay is in
    g.add_frame(sensor.snapshot(), delay=int(clock.avg()/10)) # centiseconds.
    print(clock.fps())

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