Skip to content

Commit 7c8240b

Browse files
committed
Update documentation and include mp_jpeg in the build
1 parent ccf93da commit 7c8240b

File tree

3 files changed

+65
-15
lines changed

3 files changed

+65
-15
lines changed

.github/workflows/ESP32.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,21 @@ jobs:
7676
if: steps.cache_esp_idf.outputs.cache-hit != 'true'
7777
run: |
7878
cd ~
79-
# git clone --depth 1 --branch release/v5.2 https://github.com/espressif/esp-idf.git
80-
git clone --depth 1 --branch ${{ env.IDF_VER }} https://github.com/espressif/esp-idf.git
79+
git clone --depth 1 --branch release/v5.3 https://github.com/espressif/esp-idf.git
80+
# git clone --depth 1 --branch ${{ env.IDF_VER }} https://github.com/espressif/esp-idf.git
8181
git -C esp-idf submodule update --init --recursive --filter=tree:0
8282
cd esp-idf
8383
./install.sh all
8484
cd components
8585
# latest_cam_driver=$(curl -s https://api.github.com/repos/espressif/esp32-camera/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
8686
# git clone --depth 1 --branch $latest_cam_driver https://github.com/espressif/esp32-camera.git
8787
git clone https://github.com/cnadler86/esp32-camera.git
88+
git clone https://github.com/espressif/esp-adf-libs.git
8889
cd ~/esp-idf/
8990
source ./export.sh
91+
# cd ~
92+
# git clone https://github.com/espressif/esp-adf-libs.git
93+
# cp -r ~/esp-adf-libs/esp_new_jpeg ~/esp-idf/components/
9094
9195
# Dynamically create jobs for each board
9296
build:
@@ -151,6 +155,7 @@ jobs:
151155
# Build MicroPython for each board
152156
- name: Build MicroPython
153157
run: |
158+
git clone https://github.com/cnadler86/mp_jpeg.git
154159
cd ~/esp-idf/components/esp32-camera
155160
CAM_DRIVER=$(git describe --tags --always --dirty)
156161
cd ~/micropython/ports/esp32

README.md

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
[![ESP32 Port](https://github.com/cnadler86/micropython-camera-API/actions/workflows/ESP32.yml/badge.svg)](https://github.com/cnadler86/micropython-camera-API/actions/workflows/ESP32.yml)
44

5-
This project aims to support various cameras (e.g. OV2640, OV5640) on different MicroPython ports, starting with the ESP32 port. The project implements a general API, has precompiled FW images and supports a lot of cameras out of the box. Defaults are set to work with the OV2640.
5+
This project aims to support various cameras (e.g. OV2640, OV5640) on different MicroPython ports, starting with the ESP32 port. The project implements a general API, has precompiled firmware images and supports a lot of cameras out of the box. Defaults are set to work with the OV2640.
66
At the moment, this is a micropython user module, but it might get in the micropython repo in the future.
77
The API is stable, but it might change without previous announce.
88

99
## Content
1010

11-
- [Precomiled FW (the easy way)](#precomiled-fw-the-easy-way)
11+
- [Precompiled firmware (the easy way)](#Precompiled-firmware-the-easy-way)
1212
- [Using the API](#using-the-api)
1313
- [Importing the camera module](#importing-the-camera-module)
1414
- [Creating a camera object](#creating-a-camera-object)
@@ -17,7 +17,7 @@ The API is stable, but it might change without previous announce.
1717
- [Camera reconfiguration](#camera-reconfiguration)
1818
- [Additional methods](#additional-methods)
1919
- [Additional information](#additional-information)
20-
- [Build your custom FW](#build-your-custom-fw)
20+
- [Build your custom firmware](#build-your-custom-firmware)
2121
- [Setting up the build environment (DIY method)](#setting-up-the-build-environment-diy-method)
2222
- [Add camera configurations to your board (optional, but recommended)](#add-camera-configurations-to-your-board-optional-but-recommended)
2323
- [Build the API](#build-the-api)
@@ -26,18 +26,28 @@ The API is stable, but it might change without previous announce.
2626
- [Troubleshooting](#troubleshooting)
2727
- [Donate](#donate)
2828

29-
## Precomiled FW (the easy way)
29+
## Precompiled firmware (the easy way)
3030

3131
If you are not familiar with building custom firmware, visit the [releases](https://github.com/cnadler86/micropython-camera-API/releases) page to download firmware that suits your board. **There are over 20 precompiled board images with the latest micropython!**
3232

33+
This firmware binaries also include the (mp_jpeg module)[https://github.com/cnadler86/mp_jpeg] to encode/decode JPEGs.
34+
3335
## Using the API
3436

3537
### Importing the camera module
3638

39+
There general way of using the api is as follow:
40+
3741
```python
3842
from camera import Camera, GrabMode, PixelFormat, FrameSize, GainCeiling
3943
```
4044

45+
There is also a camera class with asyncio support! To use it, you need to import from the acamera package:
46+
47+
```python
48+
from acamera import Camera, GrabMode, PixelFormat, FrameSize, GainCeiling
49+
```
50+
4151
### Creating a camera object
4252

4353
Camera construction using defaults. This is the case if you are using a **non-generic** precompiled firmware or if you specified the camera model or pins in mpconfigboard.h during your build. Then you can just call the construction without any keyword arguments.
@@ -117,10 +127,22 @@ cam.init()
117127

118128
### Capture image
119129

130+
The general way of capturing an image is calling the `capture` method:
131+
120132
```python
121133
img = cam.capture()
122134
```
123135

136+
Each time you call the method, you will receive a new frame.
137+
138+
The probably better way of capturing an image would be in an asyncio-loop:
139+
140+
```python
141+
img = await cam.acapture() #To access this method, you need to import from acamera
142+
```
143+
144+
Please consult the [asyncio documentation](https://docs.micropython.org/en/latest/library/asyncio.html), if you have questions on this.
145+
124146
### Camera reconfiguration
125147

126148
```python
@@ -150,9 +172,10 @@ while not cam.frame_available():
150172
<do some other stuff>
151173
print('The frame is available now. You can grab the image by the capture method =)')
152174
```
153-
This enables the possibility to create async applications
154175

155-
### Additional methods
176+
This gives you the possibility of creating an asynchronous application
177+
178+
### Additional methods and examples
156179

157180
Here are just a few examples:
158181

@@ -163,9 +186,11 @@ camera.set_vflip(True) #Enable vertical flip
163186
```
164187

165188
See autocompletions in Thonny in order to see the list of methods.
166-
If you want more insides in the methods and what they actually do, you can find a very good documentation [here](https://docs.circuitpython.org/en/latest/shared-bindings/espcamera/index.html).
189+
If you want more insights in the methods and what they actually do, you can find a very good documentation [here](https://docs.circuitpython.org/en/latest/shared-bindings/espcamera/index.html).
167190
Note that each method requires a "get_" or "set_" prefix, depending on the desired action.
168191

192+
Take also a look in the examples folder.
193+
169194
To get the version of the camera driver used:
170195

171196
```python
@@ -175,17 +200,17 @@ vers = camera.Version()
175200

176201
### Additional information
177202

178-
The FW images support the following cameras out of the box, but is therefore big: OV7670, OV7725, OV2640, OV3660, OV5640, NT99141, GC2145, GC032A, GC0308, BF3005, BF20A6, SC030IOT
203+
The firmware images support the following cameras out of the box, but is therefore big: OV7670, OV7725, OV2640, OV3660, OV5640, NT99141, GC2145, GC032A, GC0308, BF3005, BF20A6, SC030IOT
179204

180-
## Build your custom FW
205+
## Build your custom firmware
181206

182207
### Setting up the build environment (DIY method)
183208

184209
To build the project, follow these instructions:
185210

186211
- [ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/v5.2.3/esp32/get-started/index.html): I used version 5.2.3, but it might work with other versions (see notes).
187212
- Clone the micropython repo and this repo in a folder, e.g. "MyESPCam". MicroPython version 1.24 or higher is required (at least commit 92484d8).
188-
- You will have to add the ESP32-Camera driver (I used v2.0.15). To do this, add the following to the respective idf_component.yml file (e.g. in micropython/ports/esp32/main_esp32s3/idf_component.yml):
213+
- You will have to add the ESP32-Camera driver from my fork. To do this, add the following to the respective idf_component.yml file (e.g. in micropython/ports/esp32/main_esp32s3/idf_component.yml):
189214

190215
```yml
191216
espressif/esp32-camera:
@@ -258,7 +283,11 @@ Example for Xiao sense:
258283
```
259284
#### Customize additional camera settings
260285

261-
If you want to customize additional camera setting or reduce the FW size by removing support for unused camera sensors, then take a look at the kconfig file of the esp32-camera driver and specify these on the sdkconfig file of your board.
286+
If you want to customize additional camera setting or reduce the firmware size by removing support for unused camera sensors, then take a look at the kconfig file of the esp32-camera driver and specify these on the sdkconfig file of your board.
287+
288+
#### (Optional) Add the mp_jpeg module
289+
290+
If you also want to include the [mp_jpeg module](https://github.com/cnadler86/mp_jpeg) in your build, clone the mp_jpeg repo at the same level and folder as the mp_camera_api repo and meet the requirements from the mp_jpeg repo.
262291

263292
### Build the API
264293

@@ -286,8 +315,8 @@ If you experience problems, visit [MicroPython external C modules](https://docs.
286315

287316
## Benchmark
288317

289-
I didn't use a calibrated osziloscope, but here is a FPS benchmark with my ESP32S3 (xclck_freq = 20MHz, GrabMode=LATEST, fb_count = 1, jpeg_quality=85%) and OV2640.
290-
Using fb_count=2 theoretically can double the FPS (see JPEG with fb_count=2). This might also aplly for other PixelFormats.
318+
I didn't use a calibrated oscilloscope, but here is a FPS benchmark with my ESP32S3 (xclk_freq = 20MHz, GrabMode=LATEST, fb_count = 1, jpeg_quality=85%) and OV2640.
319+
Using fb_count=2 theoretically can double the FPS (see JPEG with fb_count=2). This might also apply for other PixelFormats.
291320

292321
| Frame Size | GRAYSCALE | RGB565 | YUV422 | JPEG | JPEG (fb=2) |
293322
|------------|-----------|--------|--------|--------|-------------|

src/micropython.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ else()
4848
endif()
4949
endif()
5050

51+
# Check if MP_JPEG_DIR is set or if mp_jpeg directory exists two levels up
52+
if(DEFINED MP_JPEG_DIR AND EXISTS "${MP_JPEG_DIR}")
53+
message(STATUS "Using user-defined MP_JPEG_DIR: ${MP_JPEG_DIR}")
54+
set(MP_JPEG_SRC "${MP_JPEG_DIR}/src/jpeg_esp.c")
55+
elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../../mp_jpeg")
56+
message(STATUS "Found mp_jpeg directory two levels up")
57+
set(MP_JPEG_SRC "${CMAKE_CURRENT_LIST_DIR}/../../mp_jpeg/src/jpeg_esp.c")
58+
endif()
59+
60+
# Add MP_JPEG_SRC to target_sources if it is defined
61+
if(DEFINED MP_JPEG_SRC AND EXISTS "${MP_JPEG_SRC}")
62+
target_sources(usermod_mp_camera INTERFACE ${MP_JPEG_SRC})
63+
else()
64+
message(WARNING "MP_JPEG_SRC not found or not defined!")
65+
endif()
66+
5167
# Define MICROPY_CAMERA_MODEL if specified
5268
if (MICROPY_CAMERA_MODEL)
5369
target_compile_definitions(usermod_mp_camera INTERFACE

0 commit comments

Comments
 (0)