Improving Esp32-CAM Image Quality
by meinello engineer in Circuits > Electronics
476 Views, 3 Favorites, 0 Comments
Improving Esp32-CAM Image Quality
The esp32 cam module offers a cheap but powerful way to capture images and video streams. It thus has become widely used. This Instructable shall summarize some best practices when it comes to getting high quality image streams from this module. These will be important to be aware of - regardless of your specific project.
Also refer to the video which goes along with this instructable.
Supplies
It is expected that you already have an esp32-cam module set up and got it running e.g. by hosting a webserver. Setting up a webserver stream is the standard application for which there are many trouble shooting guides and tutorials out there.
Power Supply
Keep it simple: Just use a 5V Power supply and nothing else.
The module can also be powered with 3.3V but this is known to cause an unreliable connection.
Higher Voltages will decrease the connection stability as well and cause the board to heat up quickly as the built in voltage regulator will dissipate more electrcity to heat.
Antenna
An external antenna will improve the WiFi connection which allows for higher frame rates and less horizontal flickering. It is not enough to just attach the antenna! A resistor on the board has to be moved as shown in the picture.
Use a soldering iron with a pointy tip for best results. Larger tips will work too. Heat guns will heat up the entire board and might destroy it entirely when done without care (yep, happend to me...)
The source of the image above is this wonderful tutorial.
If you are using a mobile hotspot to transmit the images and you are experiencing major limitations in the data bandwith: connect to your router and compare the results. Depending on your devices, the mobile hotspot might have been the bottleneck that caused the issues.
Lens
Attaching other Lenses to your board will influence the field of view amount of light that gets to the sensor. I bought the OV2640 with 160 degrees Night Vision for 6 € (left image) and you can see the direct comparison to the standard lens for 3.5 €. (right image).
(When buying these other lenses, you'll always get a whole new image sensor with it.)
A variety of matching lenses are available and some creators have developed methods for attaching other lenses to the original sensor.
Results: Not only the field of view and distortion has changed with the attached lens (as expected), also the clarity of the image has decreased. As a reason for this effect, a low quality of the lens is suspected however, this is not proven to be the actual reason.
Image Sensor
The image sensor which is typically included in the esp32-CAM bundle is the OV2640 with a resolution of 2 MP. For improving the image quality further, you can get the OV5640 which is a sensor with 5 MP. I got one with a 160 degrees wide angle for 9 €. No adjustments in the example code of the webserver are needed. The OV5640 allows for more setting adjustments than the OV2640.
Higher resolution does not automatically mean that it's a better sensor:
- The OV5640 heats up quickly. A small and fully enclosed casing is thus not recommended. Attaching a small heat sink will improve the camera performance.
- With the OV5640, I only received images with resolutions up to HD. As soon as I increased the resolution more, the video stream stopped immediately. I am planning to buy a new one some other day; try again and edit this section.
- In the meantime, refer to this tutorial for a complete comparison. You'll see that larger images have a significant delay and come at a lower frequency, which would be a major disadvantage in many real time applications.
--> Consider wisely whether or not you actually need the 5MP sensor.
Casing
A casing does not only protect the electronic components but also keep the image sensor in a fixed position. Without a casing, the flexibility of the flat band wire causes the sensor to wiggle around and it never actually points in the direction you want it to.
I used this fee casing 3D model from the user jauler but you will find many other versions out there. [The intermediate quality of this specific casing is just a result of the intermediate 3D printer I have.]
Depending on the lens that you are using, you might need different casings even though the sensor always keeps the same size.
Processing With Python
You can use python to fetch images from the url that you are streaming to. In the classical Webserver example this url is "your_webserver_ip:81/stream". Having the opportunity to bring the images into your python environment in real time can be super helpful.
For demonstration, I am using image manipulation functions of the openCV and pillow libraries which work in real time. Just download the attached .py file to take a look at the code.
In my eyes, python is definately the way to go but just for having it mentioned: Instead of fetching the images from the url, you can also extend the capabilities of the webserver and directly process the images in javascript - also by using openCV like they did in this tutorial.
Downloads
Other
I'd also appreceate any donation to support my projects.