eloquentarduino / EloquentEsp32cam

Use your Esp32-cam like an expert
GNU General Public License v3.0
111 stars 20 forks source link

it is not an issue but a question #20

Closed philippedc closed 5 months ago

philippedc commented 9 months ago

Hi @eloquentarduino, sorry, I'm not an expert in C programming, nor in ESP32, no more in using github; however I have a question:

I want to make a cam project which stream video on demand and take a photo with the motion detection feature. Before taking a very long time to try to understand how I could make both jobs on a single code, I can see 2 deposits that propose video streaming and motion detection: this deposit EloquentEsp32cam and this one: https://github.com/eloquentarduino/EloquentSurveillance As they are quite different.... Why keeping both on github? Which one should I better use (the simplest)?

Thanks,

eloquentarduino commented 9 months ago

Hi Philipp, EloquentEsp32Cam is the reference library. I archived just now the EloquentSurveillance repository to make it clear that it is no longer manteined.

To do what you want, you have to combine 2 sketches:

  1. MJPEG streaming: https://github.com/eloquentarduino/EloquentEsp32cam/blob/2/examples/MJPEG_Stream/MJPEG_Stream.ino
  2. Motion detection: https://github.com/eloquentarduino/EloquentEsp32cam/blob/2/examples/Motion_Detection/Motion_Detection.ino

MJPEG streaming happens in the background, so the "merged" loop will be the loop from the motion detection sketch. You may try to remove the block

// capture picture
if (!camera.capture().isOk()) {
    Serial.println(camera.exception.toString());
    return;
}

since the MJPEG daemon is already taking frames in background. Not tested, so try both options (with and without).

You don't actually take a photo when motion is detected, since the photo is already be taken to detect motion. You can access the camera_frame_t object with camera.frame->buf and camera.frame->len to do what you need (e.g. save to SD card).

philippedc commented 9 months ago

Many thanks for your explanation. I will test soon ;)