arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.12k stars 4.79k forks source link

ESP32-CAM in 12.0.2: AEC target level can't be controlled & WcAECLevel command is unknown #16135

Closed mrneutron42 closed 1 year ago

mrneutron42 commented 2 years ago

PROBLEM DESCRIPTION

A clear and concise description of what the problem is.

For sunlit scenes, the AEC (automatic exposure control) level that the camera seeks is too long and thus the image is too bright. After reading the command names from this file: https://github.com/arendst/Tasmota/blob/master/tasmota/tasmota_xdrv_driver/xdrv_81_esp32_webcam.ino I tried to adjust the target Automatic Exposure Control value using the "WcAECValue" command - no effect on image brightness.

11:32:33.212 CMD: wcaecvalue 50
11:32:33.220 RSL: RESULT = {"WCAECValue":50}

I tried to adjust the brightness with "WcAECLevel" command - the command is unknown.

10:20:06.517 CMD: wcaeclevel -2
10:20:06.522 RSL: RESULT = {"Command":"Unknown"}

After guessing the "WcAECLevel" command is spelled wrong, I tried the command "WcAELevel". It was accepted, but had no effect on the image brightness.

10:20:13.918 CMD: wcaelevel -2
10:20:13.923 RSL: RESULT = {"WCAELevel":-2}

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

10:36:14.842 CMD: Backlog Template; Module; GPIO 255 10:36:14.861 RSL: RESULT = {"NAME":"AITHINKER CAM","GPIO":[4992,1,672,1,416,5088,1,1,1,6720,736,704,1,1,5089,5090,0,5091,5184,5152,0,5120,5024,5056,0,0,0,0,4928,1,5094,5095,5092,0,0,5093],"FLAG":0,"BASE":2} 10:36:15.091 RSL: RESULT = {"Module":{"0":"AITHINKER CAM"}}


- [x] If using rules, provide the output of this command: `Backlog Rule1; Rule2; Rule3`:
```lua
13:20:22.428 CMD: Backlog Rule1; Rule2; Rule3
13:20:22.445 RSL: RESULT = {"Rule1":{"State":"ON","Once":"OFF","StopOnError":"OFF","Length":30,"Free":481,"Rules":"ON System#Boot DO WcInit ENDON"}}
13:20:22.679 RSL: RESULT = {"Rule2":{"State":"OFF","Once":"OFF","StopOnError":"OFF","Length":0,"Free":511,"Rules":""}}
13:20:22.929 RSL: RESULT = {"Rule3":{"State":"OFF","Once":"OFF","StopOnError":"OFF","Length":0,"Free":511,"Rules":""}}
- [x] Set `weblog` to 4 and then, when you experience your issue, provide the output of the Console log:
```lua
  Console output here:
10:58:24.774 CMD: wcaecvalue 15
10:58:24.775 SRC: WebConsole from 192.168.x.x
10:58:24.776 CMD: Grp 0, Cmd 'WCAECVALUE', Idx 1, Len 2, Pld 15, Data '15'
10:58:24.784 RSL: RESULT = {"WCAECValue":15}

10:57:06.571 CMD: wcaeclevel -2
10:57:06.572 SRC: WebConsole from 192.168.x.x
10:57:06.573 CMD: Grp 0, Cmd 'WCAECLEVEL', Idx 1, Len 2, Pld -2, Data '-2'
10:57:06.577 RSL: RESULT = {"Command":"Unknown"}

10:57:49.170 CMD: wcaelevel -2
10:57:49.171 SRC: WebConsole from 192.168.x.x
10:57:49.173 CMD: Grp 0, Cmd 'WCAELEVEL', Idx 1, Len 2, Pld -2, Data '-2'
10:57:49.177 RSL: RESULT = {"WCAELevel":-2}

TO REPRODUCE

Steps to reproduce the behavior:

In Command Window: make sure AEC is turned on with the command "WcAEC 1" enter WcAECValue command with various values from 1-1024 : example, "WcAECValue 10" (observe no change in image brightness) enter WcAECLevel command with various values from -2 to +2 : example, "WcAELevel -2" (see that command is unknown) enter WcAELevel command with various values from -2 to +2 : example, "WcAELevel -2" (observe no change in image brightness)

EXPECTED BEHAVIOUR

A clear and concise description of what you expected to happen. I expect to see a change in the brightness of the camera image when sending different values for WcAECValue and WcAECLevel (WcAELevel).

SCREENSHOTS

If applicable, add screenshots to help explain your problem.

ADDITIONAL CONTEXT

Add any other context about the problem here.

(Please, remember to close the issue when the problem has been addressed)

Jason2866 commented 2 years ago

@philrich Can you have a look? You added this features in a PR. THX!

philrich commented 2 years ago

I am currently on vacation but will have a look in 2 days.

Am 08.08.2022 um 13:38 schrieb Jason2866 @.***>:

 @philrich Can you have a look? You added this features in a PR. THX!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.

mrneutron42 commented 2 years ago

I was looking at the OV2640 datasheet, top of page 26. Download OV2640 Datasheet In the Table 13 registers, register 0x24 is called AEW. It's value sets the frame brightness level that triggers the AGC to reduce the exposure time. The data sheet says before you write to register 0x24, you must first write 0x01 to register 0xFF. I believe there needs to be a register write to register 0x24 in order to set this target brightness level for the AGC. I have searched through the Tasmota source code files and have not found any references to AEW or writes to register 0x24. I believe a new variable needs to be created to store this AEW value and write it to the OV2640's AEW register

mrneutron42 commented 2 years ago

From what I saw in the source code file (https://github.com/arendst/Tasmota/blob/development/tasmota/tasmota_xdrv_driver/xdrv_81_esp32_webcam.ino), the command name AECValue does not represent what it actually controls. The function of the AECValue command sets the MANUAL exposure value of the image sensor. This value only takes effect than AECMode is 0 (disabled) and the camera module is in Manual Exposure Mode. I suggest renaming the command to MECValue, to reflect the fact that it is for manual exposure mode control.

Further down in the same file, I see a code comment confirming that the variable .aec_value is actually a manual exposure control. Settings->webcam_config2.aec_value = 204; // manual exposure value Since this variable controls a manual exposure value, it would be more intuitive to rename it to mec_value.

Jason2866 commented 2 years ago

@mrneutron42 Does it work with the settings you found out? If, yes could you provide a PR?

mrneutron42 commented 2 years ago

@Jason2866, I don't think I'm the right one to change the code. I don't have a code compiling environment set up. I'm primarily a hardware engineer (circuit design, PCB layout) and have been having a hard time following the control flow of the code. I'm not even sure of all the files to look in to get this changed. It would be better if someone more familiar with this code make the necessary changes. Has @philrich had a look yet?

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it hasn't any activity in last few weeks. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 1 year ago

This issue was automatically closed because of being stale. Feel free to open a new one if you still experience this problem.

mrneutron42 commented 7 months ago

This WcAECLevel command is still not valid in 13.4.0.

sfromis commented 7 months ago

What is valid is the spelling WcAELevel already mentioned in the first post.

mrneutron42 commented 7 months ago
  1. "WcAECLevel" is an unknown command.
  2. "WcAELevel" is a valid command.
  3. Sending new values with the "WcAELevel" command has no effect on the image brightness.
sfromis commented 7 months ago

I saw a clear difference with WcAELevel values 0/1/2. Test case was the camera pointed at a lamp, with significant difference in the captured glare around the lamp.

mrneutron42 commented 7 months ago

With Tasmota 13.4.0 (webcam), I do not see any image brightness difference between WcAELevel -2, 0, or 2. What is the output when you enter the wc command in the console?

sfromis commented 7 months ago
{"WC":{"Stream":1,"Resolution":8,"Mirror":0,"Flip":0,"Saturation":0,"Brightness":0,"Contrast":0,"SpecialEffect":0,"AWB":1,"WBMode":0,"AWBGain":1,"AEC":1,"AECValue":204,"AELevel":2,"AECDSP":1,"AGC":1,"AGCGain":5,"GainCeiling":0,"GammaCorrect":1,"LensCorrect":1,"WPC":1,"DCW":1,"BPC":0,"Colorbar":0,"Feature":0,"Auth":0,"Rtsp":0}}

Did you try my specific test case?

More generally, you should not expect a difference from just setting a different auto exposure level, only in circumstances pushing the boundaries of the automatic control.

mrneutron42 commented 7 months ago

My expectation is that the AELevel variable is setting the target auto exposure level of the camrea (the target brightness). Thus, we should expect the brightness of the whole frame to change when the AELevel numbers are changed.

My brightness and exposure settings are mostly the same as yours, except that you have an AGCgain of 5, and mine is 0. Your resolution is 8 and mine is 12, but that should be irrelivant to frame brightness. {"WC":{"Stream":1,"Resolution":12,"Mirror":0,"Flip":0,"Saturation":0,"Brightness":-2,"Contrast":0,"SpecialEffect":0,"AWB":1,"WBMode":0,"AWBGain":1,"AEC":1,"AECValue":204,"AELevel":-2,"AECDSP":1,"AGC":1,"AGCGain":0,"GainCeiling":0,"GammaCorrect":1,"LensCorrect":1,"WPC":1,"DCW":1,"BPC":0,"Colorbar":0,"Feature":0,"Auth":0,"Rtsp":0}}

sfromis commented 7 months ago

Again, did you try my specific test case?

And I disagree that you should always see the whole frame change.

mrneutron42 commented 7 months ago

With fixed iris cameras, the target automatic exposure value sets the target brightness of the frame, which controls how bright the image is. That is how cameras work.

OK. I input your settings: RESULT = {"WC":{"Stream":1,"Resolution":8,"Mirror":0,"Flip":0,"Saturation":0,"Brightness":0,"Contrast":0,"SpecialEffect":0,"AWB":1,"WBMode":0,"AWBGain":1,"AEC":1,"AECValue":204,"AELevel":2,"AECDSP":1,"AGC":1,"AGCGain":5,"GainCeiling":0,"GammaCorrect":1,"LensCorrect":1,"WPC":1,"DCW":1,"BPC":0,"Colorbar":0,"Feature":0,"Auth":0,"Rtsp":0}}

I pointed the camera at a bright ceiling light so that the light was in the center of the image.
The center of the image sensor is mainly where the automatic exposure routine looks to determine what the frame exposure time should be. If the center of the image is bright, the exposure time is shortened to make the image less bright. Nothing in the camera image changed brightness when different values (-2,-1,0,1,2) were entered with wcaelevel command.

As stated, there is no visible effect from entering different values with the WcAELevel command.

sfromis commented 7 months ago

Well, I saw very clear differences, meaning that there can be an effect. 0/1/2: image

mrneutron42 commented 7 months ago

Thank you for posting the pictures @sfromis.
Now, I can see that the adjustment is VERY little and it's only makes a difference with unusually bright objects.

My use of the ESP32-CAMS is for my Weewx weather station.
I have several cameras in several windows grabbing images of the current weather.
The default ESP32-CAM Automatic Exposure levels are brighter than I want. I want to be able to set the target average brightness of the scene. The current amount of Automatic Exposure adjustment with WcAECLevel is NOT enough to reduce the over exposure from a sunny day. I need MORE adjustment range!

mrneutron42 commented 4 months ago

I made a discovery!
The AECDSP control is key to allowing the AECLevel variable to be effective.

When AECDSP is active (WcAECDSP set to 1), the AECLevel variable is mostly ignored or counteracted! With sunlit outdoor scenes, the image is overexposed and has washed out colors levels when AECDSP is on. Turning off AECDSP (WcAECDSP set to 0) allows AECLevel to actually control the automatic exposure target level! The same scene is not overexposed and has good color saturation when AECDSP is off.