Skip to content

capture returns None while camera is initialised and crashes on next init #31

@FredrikMorstad

Description

@FredrikMorstad

Describe the bug
Camera becomes None or cannot init properly after multiple attempt to capture image

I have this endpoint using microdot

@app.route('/picture')
async def picture(request):
    # try:
    start_time = time.time()
    cam.init()
    # print(dir(cam))
    buff = None
    if cam is not None:
        while buff is None:
            buff = cam.capture()
            print(buff)
            cam.free_buffer()
    else:
        return 500

    cam.deinit()
    if buff is None:
        return 500

    end_time = time.time()

    elapsed = end_time-start_time
    print(f"capture time: {elapsed:.3f}")
    return buff, 200, {'Content-Type': 'image/jpeg', 'Content-Length': len(buff)}

and every time I run the server the capture method randomly returns None from the capture method. I used
this driver and had no problems where the capture method could not capture an image. Generally the capture method returns an image but randomly it returns none. After retrying for about 8 seconds it returns an image but the next request always fails with this exception

Traceback (most recent call last):
  File "microdot/microdot.py", line 1394, in dispatch_request
  File "microdot/microdot.py", line 45, in invoke_handler
  File "<stdin>", line 50, in picture
OSError: (-261, 'ESP_ERR_NOT_FOUND')

To Reproduce
Code to reproduce

from microdot import Microdot
from camera import Camera, PixelFormat, Version

app = Microdot()

cam = Camera(
    pixel_format=PixelFormat.JPEG,
    data_pins=[5,18,19,21,36,39,34,35],
    vsync_pin=25,
    href_pin=23,
    sda_pin=26,
    scl_pin=27,
    pclk_pin=22,
    xclk_pin=0,
    xclk_freq=20000000,
    powerdown_pin=32,
    reset_pin=-1,
)

@app.route('/picture')
async def picture(request):
    cam.init()
    buff = None
    if cam is not None:
        while buff is None:
            buff = cam.capture()
            cam.free_buffer()
    else:
        return 500

    cam.deinit()
    if buff is None:
        return 500
    return buff, 200, {'Content-Type': 'image/jpeg', 'Content-Length': len(buff)}

app.run(debug=True)

Expected behavior
A clear and concise description of what you expected to happen.
capture method should be consistent when camera is initialised

Environment:

  • Board: e.g. ESP32-CAM
  • Camera drivers version: 28035e0

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions