-
Notifications
You must be signed in to change notification settings - Fork 805
feature: support manual and auto focus on OV5640 #3504
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
base: main
Are you sure you want to change the base?
Conversation
|
@SybexX Can I please get your thoughts on whether this is going to play nicely with your camera deep sleep changes? |
|
can this also be implemented as a function? e.g. like this: show codeDo you always have to set the focus before taking the picture, or can you only do this once when starting the ESP32 and it is retained? |
|
Here I have combined deep sleep with your auto focus: |
For our use case, I do not recommend retaining the focus constantly. Technically, we could set the focus once and retain the focus for subsequent image captures, but the focus VCM circuit will constantly draw 100mA, which will heat up the camera module. The way the focus is adjusted is by driving the VCM coil to generate magnetic field to repel against a permanent magnet, therefore moving the focus lens. If we turn off the power to the VCM coil, the lens snaps back to the resting position. Long story short, yes, we should set the focus on each capture and release focus after the capture. This applies to both manual and auto focus.
Yes, pretty much with the option of manually adjusting the focus level determined by autofocus. The autofocus sometimes gets it wrong, so may require a bit of manual adjustment. |
|
hast du die angepasste firmware schon getestet? |
|
@SybexX Thanks for integrating the focus stuff into your deep sleep code. I'll rebase my branch to your
Sorry, I haven't tested your test branch where you included the focus code into your deep sleep support. I'll test it as soon as possible and report back. |
|
My test fork is only intended as an example to show what I meant by “Can this also be implemented as a function?” This is the main code for deep sleep + auto focus: show code |
|
@SybexX I've added focus control to the "create new reference" page and configuration page. I've tested it and it's working as expected.
Any reason why you closed your deep sleep PR? Did you discover problems with it? I'm thinking of adding deep sleep to this PR based on your deep sleep PR. |
|
@jasaw I made some adjustments that should solve the first problem: |
|
@SybexX Thanks for your code adjustment. Both issues that I mentioned are solved now. |
|
@SybexX I've added camera deep sleep based on your deep sleep function. It appears to be working properly with autofocus. Can you please test this branch with your non-autofocus OV5640? |
|
@jasaw AI-on-the-edge-device/sd-card/html/edit_reference.html >>> Line 959 >>> WriteParameter(param, category, "TakeImage", "CamFocusManualLevel", false, true); causes an error. |
|
@jasaw What do you think about adding a debug output during deep sleep so that you can follow the functionality better? |
|
@jasaw I have prepared something, maybe you would like to include it in your PR. then you can e.g. add something like this: |
|
@SybexX Thanks. I've added hiding of focus control when camera does not support focus control. |
|
@jasaw Something does not fit with the initialization of the focus, although my camera does not have one, it is successfully initialized and also displayed on the reference page ^^ When I try it with an OV2640, it successfully hides on the reference page. |
|
@SybexX Unfortunately, there is no way to identify whether the focus VCM coil is physically attached or not. The only difference between autofocus and non-autofocus OV5640 is the presence of external VCM coil. |
From my experience with ov5640, the stable value for jpeg quality depends on the complexity of the captured image. Again, from my limited experience, jpeg quality 16 appears to work in all configurations that I've tested (colour, denoise, etc). If I do grey scale, it's safe to run with jpeg quality 12. |
|
@SybexX This is just my observation, further investigation is needed. It looks like hitting the |
|
@SybexX Another theory is after waking up from deepsleep, the camera needs a few frames to adjust the auto exposure and auto white balance. I'm testing with this code to see whether the resulting capture is more stable. |
|
I don't know if that brings something, because this problem should actually eliminate with "WaitBeforePicture". change this: to: In the functions: So that "WaitBeforePicture" has the desired effect again. |
|
@SybexX I have moved the wifi back to core 0 because the camera task is running on core 1 and we want to minimize interruption to the camera SCCB running on I2C1 interface. You are right that moving Regarding the corrupted image that I get occasionally, it happens regardless of I've also increased the minimum quality value for ov5640 to 16 just to make sure that I avoid the corrupted jpeg issue when quality value is set too low. All these 3 changes on still on my local branch. I'll continue to monitor and report back as usual. ps: I found a bug in the CPU frequency config handling code. |
|
@SybexX A quick update: On my local branch, I have re-incorporated the 5 seconds I have also reduced the |
@jasaw: Interesting :-) |
|
Now I highly suspect some OV5640 camera modules are more susceptible to electrical noise than others and therefore some are not stable at 20MHz xclk. Best workaround that I've found is to run it at 10 MHz. I've been testing both my OV5640 at 10MHz for 1 week now and I haven't seen a single corrupted image. @SybexX @Slider0007 Have you guys seen any corrupted image running at 10 MHz? The better image quality when running at 10 MHz is a mystery but I'll happily accept better quality image with lower camera temperature. That's win-win for me :-) The other problem that I was observing on one of my ov5640 was caused by high temperature. On extremely hot days, under direct sunlight, my ov5640 gets overheated and I ended up the web interface saying "Flow not yet created", so that's my hardware fault for running it too hot. I need better heat management on my hardware. I believe the occasional corrupted image mystery is solved now. I'll continue to monitor it and do a full test with my ov5640+AF camera module. I'm going to re-test without the 5s |
I haven't any issues so far while operating OV5640 with 10Mhz. All my devices (not all with OV5640, though) are operated either with 8Mhz or 10Mhz. Going lower than 8Mhz, the image quality is decreasing somehow (artifacts, disturbing lines, etc.). Not every camera module behaves the same in this respect either, regardless of whether it's an OV2640 or OV5640.
Fully agree. |
|
@SybexX I've been testing without the 5s
I'm pretty happy with the stability of the set up now. @SybexX @Slider0007 Question is, how do we want to proceed wrt the issues below:
|
It is necessary because some digital meters need some time to wake up from standby mode (have to be illuminated with a light source for a certain time).
I asked @jomjol and @caco3 because of that. |
|
Hi. I tried the stable 16.0.0 but autofocus (with manual soldered 3,3V) does not work. Even is there an chance to make the livestream in full resolution instead of 640? |
@Teleftaios autofocus support has not been released yet, so 16.0.0 does not support autofocus. If you want to try autofocus, you'll have to compile the firmware from this branch with the @SybexX I've been testing this PR with 10MHz
|
|
would love to see the ov5640 supported |
|
Very cool, thanks for implementing it! I will add auto-focus power to Ai-On-The-Edge-Cam boards next revision (#2963). |
Some OV5640 modules have the auto focus circuit. There are 3 common variants on the market, but they all should have the same registers. The only difference is the AF-VDD and AF-GND pins on the flat connector. More info here: #2162 (comment)
This is the one that I have: https://www.aliexpress.com/item/1005004072836395.html
The auto focus circuit is normally not wired up and requires soldering AF-VDD to the ESP32 module's 2.8V LDO, and AF-GND to ground. This is another variant of ESP32 + OV5640 with auto focus AF-VDD and AF-GND already hooked up properly, so no need for any soldering. See #2162 (comment)
This PR adds support for manual focus and auto focus. The idea is to allow users to set focus level during "create reference image" and we use manual focus with the preconfigured focus level on each image capture. Alternatively, users can just use auto focus and not worry about manually adjusting it.
This is my manual focus test. Focus near vs far.

