Ejemplo 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
Ejemplo n.º 2
0
def runIt():
    print("make_movie")
    cam5procs.logLine("make_movie")
    cam5procs.rcv_type = cam5procs.old_rcv_type
    sensor.reset()  # Initialize the camera sensor.
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA)
    sensor.skip_frames(10)  # Let new settings take affect.
    clock = time.clock()  # Tracks FPS.

    cam5procs.ledShowColour([0, 255, 0])
    sensor.skip_frames(30)  # Give the user time to get ready.

    cam5procs.ledShowColour([0, 0, 0])
    cam5procs.ledShowColour([0, 255, 0])

    try:
        m = mjpeg.Mjpeg(cam5procs.fileNamePrefix %
                        (cam5procs.fileNameCounter) + ".mjpeg",
                        loop=True)
        cam5procs.fileNameCounter += 1
    except:
        cam5procs.logLine("Error creating movie file")
        return 1

    for i in range(75):
        if (cam5procs.receive_packet() == 0):
            clock.tick()
            m.add_frame(sensor.snapshot())
        else:
            m.close(clock.fps())
            cam5procs.ledShowColour([0, 0, 0])
            return 1
        #print(clock.fps())

    m.close(clock.fps())
    cam5procs.ledShowColour([0, 0, 0])
    return 0
Ejemplo n.º 3
0
    sensor.skip_frames(60)  # 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  # We'll say we detected motion after 10 frames of motion.
    while (diff):
        img = sensor.snapshot()
        img.difference("temp/bg.bmp")
        stats = img.statistics()
        # Stats 5 is the max of the lighting color channel. The below code
        # triggers when the lighting max for the whole image goes above 20.
        # The lighting difference maximum should be zero normally.
        if (stats[5] > 20):
            diff -= 1

    m = mjpeg.Mjpeg("example-%d.mjpeg" % pyb.rng())

    clock = time.clock()  # Tracks FPS.
    print("You're on camera!")
    for i in range(200):
        clock.tick()
        m.add_frame(sensor.snapshot())
        print(clock.fps())

    m.close(clock.fps())
    pyb.LED(BLUE_LED_PIN).off()
    print("Restarting...")
Ejemplo n.º 4
0
# You can use your OpenMV Cam to record mjpeg files. You can either feed the
# recorder object JPEG frames or RGB565/Grayscale frames. Once you've finished
# recording a Mjpeg file you can use VLC to play it. If you are on Ubuntu then
# the built-in video player will work too.

import sensor, image, time, mjpeg, pyb

RED_LED_PIN = 1
BLUE_LED_PIN = 3

sensor.reset()  # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB525)
sensor.set_framesize(sensor.QVGA)  # or sensor.QQVGA (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=1000)  # Give the user time to get ready.

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

m = mjpeg.Mjpeg("example.mjpeg")

for i in range(300):
    clock.tick()
    m.add_frame(sensor.snapshot())

m.close(clock.fps())
pyb.LED(BLUE_LED_PIN).off()
Ejemplo n.º 5
0
    ch = uart.write(command)
    ch = uart.read(2)
    #print(ch)
    MSByteDist = ch[0]
    LSByteDist = ch[1]
    cmDist = round((MSByteDist * 256 + LSByteDist) / 10)
    return cmDist


while (True):
    while (recording == False):
        pyb.LED(RED_LED_PIN).off()
        #check for switch being pressed to start recording
        if (pin0.value() == 1):
            strrecordingsequence = str(recordingsequence)
            m = mjpeg.Mjpeg("recording" + strrecordingsequence + ".mjpeg")
            recordingsequence += 1
            pyb.LED(RED_LED_PIN).on()
            recording = True
            print("Recording....")
            pyb.delay(2000)

    while (recording == True):
        #for i in range(240):

        oor = False
        distance = get_distance()

        strdistance = str(distance)
        #print(distancearray[1])
        clock.tick()
Ejemplo n.º 6
0
     if menu_flag == 1:
         if menu_pos == 0:
             menu_flag = 2
             menu_pos = 0
         if menu_pos == 1:
             para.para_read(para_temp, 18)
             img.draw_string(tft_posx + 96, tft_posy + 110, "ok!")
         if menu_pos == 2:
             para.para_write(para_temp, 18)
             img.draw_string(tft_posx + 96, tft_posy + 120, "ok!")
         if menu_pos == 3:
             menu_flag = 4
             menu_pos = 0
         if menu_pos == 4:
             if rec_flag == 0:
                 img_rec = mjpeg.Mjpeg("test.mjpeg")
                 rec_flag = 1
 if key_res == 4:
     if menu_flag == 1:
         menu_pos = menu_pos + 1
         if menu_pos == 5:
             menu_pos = 0
     if menu_flag == 2:
         menu_pos = menu_pos + 1
         if menu_pos == 3:
             menu_pos = 0
     if menu_flag == 3:
         if state == 0:
             menu_pos = menu_pos + 1
             if menu_pos == 6:
                 menu_pos = 0