Take a snap and save image in while loop,the ide report error

import sensor, image, pyb,time

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.FHD) # or sensor.QQVGA (or others)
#设置图像像素大小

sensor.skip_frames(time = 2000) # 让新的设置生效

wuphoto = sensor.snapshot()

def mytest1():
    pyb.LED(RED_LED_PIN).on()
    #sensor.skip_frames(time = 2000) # 给用户一个时间来准备

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

    print("You're on camera!")
    img = sensor.snapshot()

   
    pyb.LED(BLUE_LED_PIN).off()
    print("Done! Reset the camera to see the saved image.")
    wuphoto=img
    return
clock = time.clock()                # Create a clock object to track the FPS.

while(True):

    time_start = pyb.millis()
    mytest1()
    duration = pyb.elapsed_millis(time_start)
    print("/*****拍照时间为 %d 毫秒******/" % duration)
    #img = sensor.snapshot()         # Take a picture and return the image.

    time_start = pyb.millis()
    wuphoto.save("aaaa.jpg")
    duration = pyb.elapsed_millis(time_start)
    print("/*****save时间为 %d 毫秒******/" % duration)
    time.sleep_ms(850)

win7+ide3+openmv H7 plus 4.4.2,without sd card.

if delete just one code line of while (1), the ide have no error report.

i just want to save photo in loop. how to correct that?

Try changing:

def mytest1():
    pyb.LED(RED_LED_PIN).on()
    #sensor.skip_frames(time = 2000) # 给用户一个时间来准备

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

    print("You're on camera!")
    img = sensor.snapshot()

   
    pyb.LED(BLUE_LED_PIN).off()
    print("Done! Reset the camera to see the saved image.")
    wuphoto=img
    return

To:

def mytest1(): 
    global wuphoto
    pyb.LED(RED_LED_PIN).on()
    #sensor.skip_frames(time = 2000) # 给用户一个时间来准备

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

    print("You're on camera!")
    img = sensor.snapshot()

   
    pyb.LED(BLUE_LED_PIN).off()
    print("Done! Reset the camera to see the saved image.")
    wuphoto=img
    return

thank for your reply. i add that global wuphoto and run the whole.this is result:

:sob:
openmv has stopped

Yeah… it’s pretty crazy you are crashing the IDE. I see that you are sending a corrupt JPEG to the IDE.

Question, do you have an SD card plugged into the camera.

Anyway, can you run the bellow world example with RGB565 and FHD resolution? I don’t know how you are crashing the IDE as this should not be possible. However, a corrupted JPEG being sent to the IDE could.

i have no sd card plugged into the camera for that code。

when i put the img.save code out of while(1), the ide have no error report.

If you don’t have an SD card then you are probably overflowing the internal flash of the camera when you try to save an image. It has a very small disk onboard which is just meant really for read only files. It’s not meant to save images to.

The H7 plus has 32MB of Flash though. So, it can save some pictures. However, it depends on if the disk is already full of stuff. I would use an SD card though to save pictures.

The H7 plus has 32MB of Flash though. So, it can save some pictures. However, it depends on if the disk is already full of stuff.
-----------------yes,the flash has 30MB at lesat ,my code size is not more than 50Kb.
i wonder what wrong with my code.

I guess check the disk size and amount of space used. FAT doesn’t give you the whole 32MB.


if i can’t find the bug ,i have to delete the save code.
i think the bug has no relation with the save code,maybe the 64 MB is ok