-
Notifications
You must be signed in to change notification settings - Fork 642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Photos with green/blue dark tint after restart? #314
Comments
|
Found some clues, hope these can help:
Setup info: Ai-Thinker ESP32-CAM w/ OV2640, ESPHome 2021.9.0, config: esp32_camera:
external_clock:
pin: GPIO0
frequency: 20MHz
i2c_pins:
sda: GPIO26
scl: GPIO27
data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
vsync_pin: GPIO25
href_pin: GPIO23
pixel_clock_pin: GPIO22
power_down_pin: GPIO32
name: Camara
resolution: 1600x1200
jpeg_quality: 10
max_framerate: 1 fps |
Is it possible that you expect the first frames to be good? when the camera is initialized, the first few frames will be bad, until WB and Gain can be adjusted by the sensor. |
Nope, the green tint/contrast persists in time, seemingly until the sky is less bright. And it very consistently doesn't happen when using a lower resolution. |
This issue appears to be stale. Please close it if its no longer valid. |
Let me know if I can do any more testing, I'd love to be able to use the maximum resolution without having these tint issues. |
This issue appears to be stale. Please close it if its no longer valid. |
Hi Stepnolab and CarlosGS, |
Thanks Knilft for reporting and Stepno for the very defailed insight! 🙏 @Stepnolab I did keep trying, increasing the intervals between frames (+ testing soo many settings) but so far couldn't use 1600x1200 reliably. Would you mind sharing your working sketch? It would really help me pinpoint the differences 🥲 |
@Stepnolab how do you wait for the AGC to stabilize? I didn't find out how to read the current AGC value. Also - what difference value can be considered as "stabilized"? |
Well, I stumble upon this issue are few days ago.
Not entirely sure it is correct, but after 3-5 frames green tint is basically gone, for JPEG 1600x1200. However, it's still greenish in bad conditions, like in a very dim light. Not planning to further investigate issue, because have no use to encoded JPEG in my project. |
I am designing a camera that needs to take a picture within one second after power-up. Is there a way to overcome this agc calculating delay, maybe by using a manual setting? If not, is there some alternative to the ov2640 that doesn't have this delay? |
Additionally, size of first vs subsequent images generated after a camera restart, with gain set to automatic, are as follows.
|
If anyone is still struggling with this, if you disable all of the auto functions except lenc, and set the sensor settings after initialisation to white balance mode 3 or 4, it should get rid of the green tint. The sensor initialises with AGC and AWB enabled so you need to disable them and fix the white balance before taking a picture. |
That sounds promising @ymich9963, do you have a code snippet showing the specific settings? |
I tried @ymich9963's solution but it didn't solve the problem. It seems to work, but only because he deliberately set the awb mode to 3 (office) or 4 (home), which slightly balances out the blue tint. |
@jamienz yes of course. The WULPSC repo on my account uses the esp-camera driver |
@TheLongRunSmoke you can try setting wb mode to 0 instead, or at least set it to another mode and then back to 0 to refresh the white balance. Have you tried refreshing the image by capturing and returning the frame buffer? |
@ymich9963 yes. Your code used same trick with recapturing that I mentioned early. I look at WULPSC and there few other interesting things, like you initialy set aec to a small value. I'm linking your code here, it might be helpful. |
@TheLongRunSmoke it's set to 20 since that was found to be best for room light level pictures. Maybe try my settings and see what you find. |
Thanks for the pointer @ymich9963. That did indeed resolve the issue! I know @TheLongRunSmoke pasted links to code above, but for the convenience of those using Rui Santos's ESP32Cam code samples (or those unknowingly using derivatives of them), below is a snippet of code showing how the fix by @ymich9963 would fit into that. Note that he sets those settings prior to each image captured. Also note that because most of the camera's auto settings are now disabled, set_aec_value(..) becomes very important - set this according to the amount of light the camera receives. Inside on a dull rainy day with the lights off, 400 worked for me. @ymich9963 had this set to 20, so he may have been sitting next to a supernova.
|
@jamienz lol yeah these cameras are very sensitive. Glad to hear your issue has been resolved. WB Mode 3 can add a bit of a blue tint so you could try taking a frame buffer really quickly with one set of settings to help it adjust and get a clearer image on the next frame. This type of procedure would only be needed as soon as the camera would be initialised and then it should be good for subsequent pictures. |
I returned to this issue and check @ymich9963 solution as its used in WULPSC…and it works great! To make it work.
Next captured frame has almost no tint in almost any conditions. Snippet from my tests. init(){
…
Normal init section finished with esp_camera_init()
…
sensor_t* s = esp_camera_sensor_get();
s->set_brightness(s, 1); // I want image about 1 stop brighter (-2 to 2)
s->set_contrast(s, 0);
s->set_saturation(s, 0);
s->set_gain_ctrl(s, 0); // Auto gain off
s->set_exposure_ctrl(s, 0); // Auto exposure off
s->set_aec_value(s, 100); // Set aec to a small initial value.
s->set_awb_gain(s, 1); // Auto White Balance enable (0 or 1)
s->set_wb_mode(s, 0); // If awb_gain enabled (0-Auto,1-Sunny,2-Cloudy,3-Office,4-Home)
s->set_aec2(s, 1); // AEC DSP
s->set_bpc(s, 1); // Black point control
s->set_wpc(s, 1); // White point control
s->set_lenc(s, 1); // Lens correction
// Due board position, rotate image 180 degrees.
s->set_hmirror(s, 1);
s->set_vflip(s, 1);
}
camera_fb_t* capture() {
if (!ok) return nullptr;
// Skip first frame.
esp_camera_fb_return(_frameBuffer);
_frameBuffer = esp_camera_fb_get();
esp_camera_fb_return(_frameBuffer);
// Enable auto exposure.
sensor_t* s = esp_camera_sensor_get();
s->set_gain_ctrl(s, 1); // Auto gain on
s->set_exposure_ctrl(s, 1); // Auto exposure on
// Skip 2 frames.
for (int i = 0; i < 2; i++) {
_frameBuffer = esp_camera_fb_get();
esp_camera_fb_return(_frameBuffer);
}
return esp_camera_fb_get();
} |
@TheLongRunSmoke Very interesting solution! I wonder why you need to execute those processes in that sequence but it's good to hear that it works! I would think skipping steps 4 and 5 entirely would also work but I guess it may depend on your implementation. |
@me-no-dev |
@AxelLin I'm not sure exactly, I think it depends on the settings and actual environment. Maybe you can use some "safe" value, like skip 10 frames? |
Thank you for the "10 frame" suggestion. I have been struggling for over a year to get a snapshot after coming out of deepsleep or lightsleep using the firmware at: |
I was taking photos in a loop of sequence of 4, then changed to 15 and it didn't make any difference. The first 4 photos that I saved after the sequence were bad. I believe it is question of time and it can be enough to take 4 photos with 2 seconds delays between each other, then the following images will be good. |
After a month's testing taking 5 frames with 100ms delays works much better. 4 * 2 seconds the intruder is long-gone! Even this appears to work well (Micropython): # throw-away two images, this sets
# the camera up for a proper picture
unwanted_img = camera.capture()
time.sleep_ms(100)
unwanted_img = camera.capture()
time.sleep_ms(100)
img = camera.capture() |
this worked for me! |
I've recently set up my ESP32-CAM to take a jpeg every 5 minutes and send to a webservice. Additionally, I use ESP.restart() once every 24 hours as I have found that it helps keep the thing from hanging up (I have not yet found the root cause for hanging up).
The issue I'm having is that after restarting, the pictures will sometimes have a green/blue tint to them. This does not happen every time a restart occurs, but if it does, the tint will persist until at least another restart happens. Pictures below for a comparison.
Am I missing something crucial in the camera configuration that controls this? Something with the sensor?
Also, I have noticed this with several different ESP32 cams, so I know it's not a faulty module.
BEFORE RESTART:
AFTER RESTART:
The text was updated successfully, but these errors were encountered: