Matchboxscope / matchboxscope-simplecamera

Expanded version of the Espressif ESP webcam
https://hackaday.io/project/168563-7-esp32-cam-example-expanded
GNU Lesser General Public License v2.1
2 stars 1 forks source link

Recording "HDR" image series not working #2

Closed beniroquai closed 1 year ago

beniroquai commented 1 year ago

@ethanjli, thanks for the input today. First homework: Hdr. i thought this might be easy - it's not. the value is properly transmitted, but it seems the camera settings won't be updated. Any idea why this is - it works in the http-server/GUi with the same function calls.. hmpf..weird!

The relevant code: https://github.com/Matchboxscope/matchboxscope-simplecamera/blob/matchboxscope/main/main.ino#L1210

Perhaps @KillerInk you have an idea, too? ;)

Idea: Capture over/under/correctly exposed image for later processing

ethanjli commented 1 year ago

How certain are you that aec_value is the parameter to adjust for manual exposure control? Based on the name, and without having read any documentation for the camera, I would assume that it's a parameter used as part of auto-exposure-control functionality (which I believe you've disabled)

beniroquai commented 1 year ago

Thanks! I have fixed it. Should do its job now.

One thing that surprises me is the mean intensity - it stays the same for all images (e.g. 1, 5, 10, 50, 100, 500 ms exposure time). Not plausible:


Lamp: 0%, pwm = 0
[  1135][D][main.ino:932] setup(): PWM pin: 12
Lamp: 20%, pwm = 54
Lamp: 0%, pwm = 0
internal files System found and mounted
In timelapse anglerfish mode.
Lamp: 255%, pwm = 5672
Is Acquire Stack is: 0
Resetting Camera Sensor Settings...
[  1519][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 0
Mean intensity: 135
[  1583][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 1
Mean intensity: 139
[  1632][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 2
Mean intensity: 136
[  1682][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 3
Mean intensity: 139
[  1732][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 4
Mean intensity: 136
[  1782][D][app_httpd.cpp:1373] saveImage(): Setting PWM Value
Current: 0%, pwm = 0
Capture Requested for SD card save
Lamp: 255%, pwm = 5672
Lamp: 0%, pwm = 0
Saved /data_Apr_20_2023_172951_timelapse_image_anglerfish_4492texp_1
Lamp: 0%, pwm = 0
Resetting Camera Sensor Settings...
[  3007][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 0
Mean intensity: 136
[  3014][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 1
Mean intensity: 139
[  3132][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 2
Mean intensity: 136
[  3182][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 3
Mean intensity: 139
[  3232][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 4
Mean intensity: 136
[  3282][D][app_httpd.cpp:1373] saveImage(): Setting PWM Value
Current: 0%Lamp: 0%, pwm = 0
Saved /data_Apr_20_2023_172951_timelapse_image_anglerfish_4492texp_5
Lamp: 0%, pwm = 0
Resetting Camera Sensor Settings...
[  4498][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 0
Mean intensity: 136
[  4505][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 1
Mean intensity: 139
[  4582][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 2
Mean intensity: 135
[  4632][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 3
Mean intensity: 139
[  4682][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 4
Mean intensity: 135
[  4732][D][app_httpd.cpp:1373] saveImage(): Setting PWM Value
Current: 0%, pwm = 0
Capture Requested for SD card save
Lamp: 255%, pwm = 5672
Lamp: 0%, pwm = 0
Saved /data_Apr_20_2023_172951_timelapse_image_anglerfish_4492texp_10
Lamp: 0%, pwm = 0
Resetting Camera Sensor Settings...
[  5946][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 0
Mean intensity: 136
[  5953][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 1
Mean intensity: 139
[  5982][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 2
Mean intensity: 135
[  6032][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 3
Mean intensity: 138
[  6082][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 4
Mean intensity: 135
[  6132][D][app_httpd.cpp:1373] saveImage(): Setting PWM Value
Current: 0%, pwm = 0
Capture Requested for SD card save
Lamp: 255%, pwm = 5672
Lamp: 0%, pwm = 0
Saved /data_Apr_20_2023_172951_timelapse_image_anglerfish_4492texp_50
Lamp: 0%, pwm = 0
Resetting Camera Sensor Settings...
[  7328][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 0
Mean intensity: 135
[  7335][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 1
Mean intensity: 138
[  7432][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 2
Mean intensity: 135
[  7482][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 3
Mean intensity: 138
[  7532][D][main.ino:1221] loadAnglerfishCamSettings(): Capturing dummy frame 4
Mean intensity: 135
[  7582][D][app_httpd.cpp:1373] saveImage(): Setting PWM Value

I compute it using this formula:

int get_mean_intensity(camera_fb_t *fb)
{
    uint8_t *pixels = fb->buf;
    int num_pixels = fb->width * fb->height;

    int sum_intensity = 0;
    for (int i = 0; i < num_pixels; i++)
    {
        sum_intensity += pixels[i];
    }
    int mean_intensity = sum_intensity / num_pixels;

    return mean_intensity;
}

I guess int sum_intensity = 0; should be long?

ethanjli commented 1 year ago

Out of curiosity, what changes did you make to fix the exposure control start working, and what observations did you see which led you to conclude that it's working?

For calculating the mean intensity, I would recommend using a floating-point data type (preferably double, or else float if you find that double is too computationally expensive) in order to avoid integer overflow issues. I'm not totally sure whether integer overflow is the root case of your observation that mean intensity appears to remain constant independently of the exposure time; I think it's worth taking the time to identify the root cause, and as two next steps I suggest:

  1. Visually inspecting the images saved at different exposure times to ensure that they appear to have different brightnesses - if you observe this, then it's more likely that the problem is with your algorithm to compute mean intensity
  2. Comparing the outputs of your mean intensity algorithm when you declare sum_intensity as an int vs. a long (i.e. you had a good intuition, so go ahead and test it out 😉 ).
beniroquai commented 1 year ago

Curiosity is good! Actually, there was another loadPref() inside the saveImage()-function, which loaded the settings from the flash. tütüm.. Now it's all set and running.

Visually, the exposure series seems to be working. Need to test it in the dark-room tomorrow :D Thanks again! :)