pibooth-modnet 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pibooth_modnet-1.0.0/CHANGELOG.md +6 -0
- pibooth_modnet-1.0.0/LICENSE +21 -0
- pibooth_modnet-1.0.0/MANIFEST.in +1 -0
- pibooth_modnet-1.0.0/PKG-INFO +222 -0
- pibooth_modnet-1.0.0/README.md +175 -0
- pibooth_modnet-1.0.0/pibooth_modnet/__init__.py +667 -0
- pibooth_modnet-1.0.0/pibooth_modnet/__main__.py +7 -0
- pibooth_modnet-1.0.0/pibooth_modnet.egg-info/PKG-INFO +222 -0
- pibooth_modnet-1.0.0/pibooth_modnet.egg-info/SOURCES.txt +13 -0
- pibooth_modnet-1.0.0/pibooth_modnet.egg-info/dependency_links.txt +1 -0
- pibooth_modnet-1.0.0/pibooth_modnet.egg-info/entry_points.txt +5 -0
- pibooth_modnet-1.0.0/pibooth_modnet.egg-info/requires.txt +7 -0
- pibooth_modnet-1.0.0/pibooth_modnet.egg-info/top_level.txt +1 -0
- pibooth_modnet-1.0.0/pyproject.toml +49 -0
- pibooth_modnet-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pibooth-modnet contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
include LICENSE README.md CHANGELOG.md
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pibooth-modnet
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: pibooth plugin: AI background replacement and overlays using MODNet portrait matting (ONNX Runtime, CPU)
|
|
5
|
+
License: MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2026 pibooth-modnet contributors
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
|
|
27
|
+
Project-URL: Homepage, https://github.com/peteoheat/pibooth-modnet
|
|
28
|
+
Project-URL: Issues, https://github.com/peteoheat/pibooth-modnet/issues
|
|
29
|
+
Keywords: pibooth,photobooth,raspberry pi,background removal,modnet,onnx
|
|
30
|
+
Classifier: Development Status :: 4 - Beta
|
|
31
|
+
Classifier: Environment :: Other Environment
|
|
32
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
35
|
+
Classifier: Programming Language :: Python :: 3
|
|
36
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
37
|
+
Requires-Python: >=3.9
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
License-File: LICENSE
|
|
40
|
+
Requires-Dist: pibooth>=2.1.0
|
|
41
|
+
Requires-Dist: numpy
|
|
42
|
+
Requires-Dist: Pillow
|
|
43
|
+
Requires-Dist: onnxruntime!=1.21.*,>=1.16
|
|
44
|
+
Provides-Extra: opencv
|
|
45
|
+
Requires-Dist: opencv-python-headless; extra == "opencv"
|
|
46
|
+
Dynamic: license-file
|
|
47
|
+
|
|
48
|
+
# pibooth-modnet
|
|
49
|
+
|
|
50
|
+
AI background replacement and overlays for [pibooth](https://github.com/pibooth/pibooth) 2.1.x, using the
|
|
51
|
+
[MODNet](https://github.com/ZHKKKe/MODNet) portrait-matting model on the CPU with ONNX Runtime.
|
|
52
|
+
|
|
53
|
+
Built for a Raspberry Pi 5 (4GB) on Raspberry Pi OS Trixie with a Camera Module 3 capturing at full resolution
|
|
54
|
+
(4608×2592), but it works with any camera pibooth supports.
|
|
55
|
+
|
|
56
|
+
## How it works
|
|
57
|
+
|
|
58
|
+
1. **Each capture is processed as soon as it is taken**, in a background thread. The work overlaps the countdown
|
|
59
|
+
for the next shot, so by the time the last photo is taken most of the sequence is already done.
|
|
60
|
+
2. **MODNet runs at a small size** (short side 512 px by default, aspect ratio kept, no square stretching).
|
|
61
|
+
3. **The matte is upsampled with a fast guided filter**, which snaps its edges to the real edges in the
|
|
62
|
+
full-resolution photo instead of a blurry upscale.
|
|
63
|
+
4. **Full-resolution compositing** uses only C-level PIL/OpenCV operations. Backgrounds and overlays are resized once
|
|
64
|
+
per theme and cached.
|
|
65
|
+
5. The processed captures replace the originals in pibooth's final picture (and in the wait-screen animation). The
|
|
66
|
+
untouched originals are still saved in pibooth's `raw` folder.
|
|
67
|
+
|
|
68
|
+
Themes with only an overlay skip the AI step entirely. If the model cannot load, the booth keeps working and simply
|
|
69
|
+
leaves backgrounds unchanged.
|
|
70
|
+
|
|
71
|
+
## Install
|
|
72
|
+
|
|
73
|
+
On Raspberry Pi OS Trixie, pip refuses to install into the system Python (PEP 668), so choose one of the options below.
|
|
74
|
+
In both, OpenCV comes from apt so it matches the system numpy; it is optional, and without it edge refinement is
|
|
75
|
+
skipped.
|
|
76
|
+
|
|
77
|
+
### Option 1: virtual environment (recommended)
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
sudo apt install python3-opencv python3-picamera2 python3-venv
|
|
81
|
+
|
|
82
|
+
# --system-site-packages lets the venv see the apt-installed picamera2 and OpenCV
|
|
83
|
+
python3 -m venv --system-site-packages ~/pibooth-venv
|
|
84
|
+
source ~/pibooth-venv/bin/activate
|
|
85
|
+
|
|
86
|
+
pip install pibooth pibooth-modnet # skip "pibooth" if it is already in the venv
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Everything that runs pibooth must use this venv: start it with `~/pibooth-venv/bin/pibooth`, and in an autostart
|
|
90
|
+
entry or systemd service use that full path instead of `pibooth`. The model download command below needs the venv
|
|
91
|
+
too (`~/pibooth-venv/bin/pibooth-modnet --download`, or activate it first).
|
|
92
|
+
|
|
93
|
+
If pibooth is already installed in an existing venv, activate that one and run only `pip install pibooth-modnet`.
|
|
94
|
+
|
|
95
|
+
### Option 2: system Python, no venv
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
sudo apt install python3-opencv
|
|
99
|
+
pip install --break-system-packages pibooth-modnet
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
This is simpler but can clash with apt-managed packages. Use it only if your pibooth is already installed this way.
|
|
103
|
+
|
|
104
|
+
### Without the apt OpenCV
|
|
105
|
+
|
|
106
|
+
`pip install "pibooth-modnet[opencv]"` installs `opencv-python-headless` from PyPI instead. Do not install both.
|
|
107
|
+
|
|
108
|
+
pibooth discovers the plugin automatically; no `plugins =` line in `pibooth.cfg` is needed. Check the start-up log
|
|
109
|
+
for `Installed plugins: ... modnet-1.0.0`.
|
|
110
|
+
|
|
111
|
+
Download the model (about 26 MB) before your first event, so the booth never needs the internet:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
pibooth-modnet --download
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
It is saved to `~/.config/pibooth/models/modnet.onnx` and checked against a SHA-256 hash. If the download fails,
|
|
118
|
+
copy `modnet.onnx` from the photobooth-app repository (`src/photobooth/utils/rembg/models/`) to that path.
|
|
119
|
+
|
|
120
|
+
### Upgrading from the single-file plugin
|
|
121
|
+
|
|
122
|
+
If you used the old `pibooth-modnet.py` file, remove its path from `[GENERAL] plugins` in `pibooth.cfg` (otherwise
|
|
123
|
+
the plugin loads twice), then install from PyPI as above. Your `[MODNET]` settings are kept.
|
|
124
|
+
|
|
125
|
+
### Known issue: onnxruntime 1.21 on Raspberry Pi
|
|
126
|
+
|
|
127
|
+
onnxruntime 1.21 prints many `Schema error: Trying to register schema ... already registered` lines when the model
|
|
128
|
+
loads. They are harmless, but 1.20.1 is clean; the package therefore excludes 1.21.x. If pip left you on 1.21, run
|
|
129
|
+
`pip install onnxruntime==1.20.1`.
|
|
130
|
+
|
|
131
|
+
## Themes
|
|
132
|
+
|
|
133
|
+
Each sub-folder of `themes_path` is one theme. Underscores in folder names become spaces on screen.
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
~/.config/pibooth/themes/
|
|
137
|
+
├── Beach/
|
|
138
|
+
│ ├── background.jpg # replaces the background (needs AI)
|
|
139
|
+
│ └── overlay.png # drawn on top of each photo (transparent PNG)
|
|
140
|
+
├── Neon_Party/
|
|
141
|
+
│ └── background.jpg # background only
|
|
142
|
+
└── Wedding_Frame/
|
|
143
|
+
└── overlay.png # overlay only: no AI, very fast
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
* **Backgrounds** can be any size or aspect ratio; they are centre-cropped to fill the capture.
|
|
147
|
+
* **Overlays** are stretched to the capture size, so design them at the capture aspect ratio: **4608×2592 (16:9)**
|
|
148
|
+
for a Camera Module 3 at full resolution. Use a PNG with transparency.
|
|
149
|
+
* If `[PICTURE] captures_cropping = True`, pibooth crops captures to fit its layout slots, which can cut off the edges
|
|
150
|
+
of an overlay. Either keep important overlay content near the centre or turn cropping off.
|
|
151
|
+
* pibooth's own `[PICTURE] overlays` option still works too; it goes over the *whole* final picture, whereas theme
|
|
152
|
+
overlays go over *each capture*.
|
|
153
|
+
|
|
154
|
+
### Choosing a theme
|
|
155
|
+
|
|
156
|
+
| `theme_selection` | Behaviour |
|
|
157
|
+
|---|---|
|
|
158
|
+
| `manual` | Guests press **← / →** on the wait screen; the theme name shows in a bar at the top. |
|
|
159
|
+
| `cycle` | Each new guest gets the next theme. |
|
|
160
|
+
| `random` | A random theme per guest. |
|
|
161
|
+
|
|
162
|
+
On the wait screen, touch and the hardware buttons already mean capture/print in pibooth, so manual selection uses
|
|
163
|
+
the keyboard arrow keys (a small USB or Bluetooth keypad works well).
|
|
164
|
+
|
|
165
|
+
## Configuration
|
|
166
|
+
|
|
167
|
+
All options live in the `[MODNET]` section and are added to `pibooth.cfg` automatically on first start.
|
|
168
|
+
|
|
169
|
+
| Option | Default | Notes |
|
|
170
|
+
|---|---|---|
|
|
171
|
+
| `enabled` | `True` | Also in pibooth's settings menu. |
|
|
172
|
+
| `themes_path` | `~/.config/pibooth/themes` | Folder of theme folders. |
|
|
173
|
+
| `theme_selection` | `manual` | `manual`, `cycle` or `random`. |
|
|
174
|
+
| `include_no_theme` | `False` | Adds a "No theme" choice that keeps the original photo. |
|
|
175
|
+
| `show_theme_banner` | `True` | Theme name bar on the wait screen (manual only). |
|
|
176
|
+
| `model_path` | `~/.config/pibooth/models/modnet.onnx` | Downloaded automatically if missing. |
|
|
177
|
+
| `inference_size` | `512` | Model short side. 512 is what MODNet was trained for; 384 is faster; 640 can help wide group shots. |
|
|
178
|
+
| `threads` | `3` | Model CPU threads. 3 leaves one core for a smooth live preview; try 4 if the preview stays smooth. |
|
|
179
|
+
| `refine_edges` | `True` | Guided-filter edge refinement (needs OpenCV). |
|
|
180
|
+
|
|
181
|
+
## Test and benchmark on the Pi
|
|
182
|
+
|
|
183
|
+
Before an event, run a real capture through a theme:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
pibooth-modnet --test ~/Pictures/pibooth/raw/<date>/pibooth000.jpg ~/.config/pibooth/themes/Beach out.jpg
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
It prints the matte and composite times for three runs and saves the result. On a 2-core x86 test machine a
|
|
190
|
+
4608×2592 capture took about 0.9 s in total (0.5 s model, 0.08 s edge refinement, 0.07 s composite). Expect the Pi 5 to
|
|
191
|
+
be slower per capture; because each capture is processed during the next countdown, what matters is that one capture
|
|
192
|
+
finishes within your `[WINDOW] preview_delay`.
|
|
193
|
+
|
|
194
|
+
## Tips for clean cut-outs
|
|
195
|
+
|
|
196
|
+
* Light guests evenly from the front; avoid strong backlight.
|
|
197
|
+
* A plain backdrop a metre or more behind guests helps more than any setting. Busy patterns and colours close to skin
|
|
198
|
+
or hair are the hardest cases.
|
|
199
|
+
* MODNet is trained for people. Large props held away from the body may be partly removed.
|
|
200
|
+
|
|
201
|
+
## Credits and licences
|
|
202
|
+
|
|
203
|
+
* MODNet by Ke et al., Apache-2.0 — https://github.com/ZHKKKe/MODNet
|
|
204
|
+
* ONNX model file as packaged by photobooth-app, MIT — https://github.com/photobooth-app/photobooth-app
|
|
205
|
+
* Plugin: MIT
|
|
206
|
+
|
|
207
|
+
## Development and releasing
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
git clone https://github.com/peteoheat/pibooth-modnet && cd pibooth-modnet
|
|
211
|
+
pip install -e .
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
To publish a release to PyPI:
|
|
215
|
+
|
|
216
|
+
1. Bump `__version__` in `pibooth_modnet/__init__.py` and add an entry to `CHANGELOG.md`.
|
|
217
|
+
2. One-off setup: on pypi.org add a *trusted publisher* for the project (owner `peteoheat`, repository
|
|
218
|
+
`pibooth-modnet`, workflow `publish.yml`, environment `pypi`), and create a `pypi` environment in the GitHub
|
|
219
|
+
repository settings.
|
|
220
|
+
3. Create a GitHub release for the new tag. The `Publish to PyPI` workflow builds and uploads it.
|
|
221
|
+
|
|
222
|
+
To publish by hand instead: `pip install build twine && python -m build && twine upload dist/*`.
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# pibooth-modnet
|
|
2
|
+
|
|
3
|
+
AI background replacement and overlays for [pibooth](https://github.com/pibooth/pibooth) 2.1.x, using the
|
|
4
|
+
[MODNet](https://github.com/ZHKKKe/MODNet) portrait-matting model on the CPU with ONNX Runtime.
|
|
5
|
+
|
|
6
|
+
Built for a Raspberry Pi 5 (4GB) on Raspberry Pi OS Trixie with a Camera Module 3 capturing at full resolution
|
|
7
|
+
(4608×2592), but it works with any camera pibooth supports.
|
|
8
|
+
|
|
9
|
+
## How it works
|
|
10
|
+
|
|
11
|
+
1. **Each capture is processed as soon as it is taken**, in a background thread. The work overlaps the countdown
|
|
12
|
+
for the next shot, so by the time the last photo is taken most of the sequence is already done.
|
|
13
|
+
2. **MODNet runs at a small size** (short side 512 px by default, aspect ratio kept, no square stretching).
|
|
14
|
+
3. **The matte is upsampled with a fast guided filter**, which snaps its edges to the real edges in the
|
|
15
|
+
full-resolution photo instead of a blurry upscale.
|
|
16
|
+
4. **Full-resolution compositing** uses only C-level PIL/OpenCV operations. Backgrounds and overlays are resized once
|
|
17
|
+
per theme and cached.
|
|
18
|
+
5. The processed captures replace the originals in pibooth's final picture (and in the wait-screen animation). The
|
|
19
|
+
untouched originals are still saved in pibooth's `raw` folder.
|
|
20
|
+
|
|
21
|
+
Themes with only an overlay skip the AI step entirely. If the model cannot load, the booth keeps working and simply
|
|
22
|
+
leaves backgrounds unchanged.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
On Raspberry Pi OS Trixie, pip refuses to install into the system Python (PEP 668), so choose one of the options below.
|
|
27
|
+
In both, OpenCV comes from apt so it matches the system numpy; it is optional, and without it edge refinement is
|
|
28
|
+
skipped.
|
|
29
|
+
|
|
30
|
+
### Option 1: virtual environment (recommended)
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
sudo apt install python3-opencv python3-picamera2 python3-venv
|
|
34
|
+
|
|
35
|
+
# --system-site-packages lets the venv see the apt-installed picamera2 and OpenCV
|
|
36
|
+
python3 -m venv --system-site-packages ~/pibooth-venv
|
|
37
|
+
source ~/pibooth-venv/bin/activate
|
|
38
|
+
|
|
39
|
+
pip install pibooth pibooth-modnet # skip "pibooth" if it is already in the venv
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Everything that runs pibooth must use this venv: start it with `~/pibooth-venv/bin/pibooth`, and in an autostart
|
|
43
|
+
entry or systemd service use that full path instead of `pibooth`. The model download command below needs the venv
|
|
44
|
+
too (`~/pibooth-venv/bin/pibooth-modnet --download`, or activate it first).
|
|
45
|
+
|
|
46
|
+
If pibooth is already installed in an existing venv, activate that one and run only `pip install pibooth-modnet`.
|
|
47
|
+
|
|
48
|
+
### Option 2: system Python, no venv
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
sudo apt install python3-opencv
|
|
52
|
+
pip install --break-system-packages pibooth-modnet
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
This is simpler but can clash with apt-managed packages. Use it only if your pibooth is already installed this way.
|
|
56
|
+
|
|
57
|
+
### Without the apt OpenCV
|
|
58
|
+
|
|
59
|
+
`pip install "pibooth-modnet[opencv]"` installs `opencv-python-headless` from PyPI instead. Do not install both.
|
|
60
|
+
|
|
61
|
+
pibooth discovers the plugin automatically; no `plugins =` line in `pibooth.cfg` is needed. Check the start-up log
|
|
62
|
+
for `Installed plugins: ... modnet-1.0.0`.
|
|
63
|
+
|
|
64
|
+
Download the model (about 26 MB) before your first event, so the booth never needs the internet:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pibooth-modnet --download
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
It is saved to `~/.config/pibooth/models/modnet.onnx` and checked against a SHA-256 hash. If the download fails,
|
|
71
|
+
copy `modnet.onnx` from the photobooth-app repository (`src/photobooth/utils/rembg/models/`) to that path.
|
|
72
|
+
|
|
73
|
+
### Upgrading from the single-file plugin
|
|
74
|
+
|
|
75
|
+
If you used the old `pibooth-modnet.py` file, remove its path from `[GENERAL] plugins` in `pibooth.cfg` (otherwise
|
|
76
|
+
the plugin loads twice), then install from PyPI as above. Your `[MODNET]` settings are kept.
|
|
77
|
+
|
|
78
|
+
### Known issue: onnxruntime 1.21 on Raspberry Pi
|
|
79
|
+
|
|
80
|
+
onnxruntime 1.21 prints many `Schema error: Trying to register schema ... already registered` lines when the model
|
|
81
|
+
loads. They are harmless, but 1.20.1 is clean; the package therefore excludes 1.21.x. If pip left you on 1.21, run
|
|
82
|
+
`pip install onnxruntime==1.20.1`.
|
|
83
|
+
|
|
84
|
+
## Themes
|
|
85
|
+
|
|
86
|
+
Each sub-folder of `themes_path` is one theme. Underscores in folder names become spaces on screen.
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
~/.config/pibooth/themes/
|
|
90
|
+
├── Beach/
|
|
91
|
+
│ ├── background.jpg # replaces the background (needs AI)
|
|
92
|
+
│ └── overlay.png # drawn on top of each photo (transparent PNG)
|
|
93
|
+
├── Neon_Party/
|
|
94
|
+
│ └── background.jpg # background only
|
|
95
|
+
└── Wedding_Frame/
|
|
96
|
+
└── overlay.png # overlay only: no AI, very fast
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
* **Backgrounds** can be any size or aspect ratio; they are centre-cropped to fill the capture.
|
|
100
|
+
* **Overlays** are stretched to the capture size, so design them at the capture aspect ratio: **4608×2592 (16:9)**
|
|
101
|
+
for a Camera Module 3 at full resolution. Use a PNG with transparency.
|
|
102
|
+
* If `[PICTURE] captures_cropping = True`, pibooth crops captures to fit its layout slots, which can cut off the edges
|
|
103
|
+
of an overlay. Either keep important overlay content near the centre or turn cropping off.
|
|
104
|
+
* pibooth's own `[PICTURE] overlays` option still works too; it goes over the *whole* final picture, whereas theme
|
|
105
|
+
overlays go over *each capture*.
|
|
106
|
+
|
|
107
|
+
### Choosing a theme
|
|
108
|
+
|
|
109
|
+
| `theme_selection` | Behaviour |
|
|
110
|
+
|---|---|
|
|
111
|
+
| `manual` | Guests press **← / →** on the wait screen; the theme name shows in a bar at the top. |
|
|
112
|
+
| `cycle` | Each new guest gets the next theme. |
|
|
113
|
+
| `random` | A random theme per guest. |
|
|
114
|
+
|
|
115
|
+
On the wait screen, touch and the hardware buttons already mean capture/print in pibooth, so manual selection uses
|
|
116
|
+
the keyboard arrow keys (a small USB or Bluetooth keypad works well).
|
|
117
|
+
|
|
118
|
+
## Configuration
|
|
119
|
+
|
|
120
|
+
All options live in the `[MODNET]` section and are added to `pibooth.cfg` automatically on first start.
|
|
121
|
+
|
|
122
|
+
| Option | Default | Notes |
|
|
123
|
+
|---|---|---|
|
|
124
|
+
| `enabled` | `True` | Also in pibooth's settings menu. |
|
|
125
|
+
| `themes_path` | `~/.config/pibooth/themes` | Folder of theme folders. |
|
|
126
|
+
| `theme_selection` | `manual` | `manual`, `cycle` or `random`. |
|
|
127
|
+
| `include_no_theme` | `False` | Adds a "No theme" choice that keeps the original photo. |
|
|
128
|
+
| `show_theme_banner` | `True` | Theme name bar on the wait screen (manual only). |
|
|
129
|
+
| `model_path` | `~/.config/pibooth/models/modnet.onnx` | Downloaded automatically if missing. |
|
|
130
|
+
| `inference_size` | `512` | Model short side. 512 is what MODNet was trained for; 384 is faster; 640 can help wide group shots. |
|
|
131
|
+
| `threads` | `3` | Model CPU threads. 3 leaves one core for a smooth live preview; try 4 if the preview stays smooth. |
|
|
132
|
+
| `refine_edges` | `True` | Guided-filter edge refinement (needs OpenCV). |
|
|
133
|
+
|
|
134
|
+
## Test and benchmark on the Pi
|
|
135
|
+
|
|
136
|
+
Before an event, run a real capture through a theme:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
pibooth-modnet --test ~/Pictures/pibooth/raw/<date>/pibooth000.jpg ~/.config/pibooth/themes/Beach out.jpg
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
It prints the matte and composite times for three runs and saves the result. On a 2-core x86 test machine a
|
|
143
|
+
4608×2592 capture took about 0.9 s in total (0.5 s model, 0.08 s edge refinement, 0.07 s composite). Expect the Pi 5 to
|
|
144
|
+
be slower per capture; because each capture is processed during the next countdown, what matters is that one capture
|
|
145
|
+
finishes within your `[WINDOW] preview_delay`.
|
|
146
|
+
|
|
147
|
+
## Tips for clean cut-outs
|
|
148
|
+
|
|
149
|
+
* Light guests evenly from the front; avoid strong backlight.
|
|
150
|
+
* A plain backdrop a metre or more behind guests helps more than any setting. Busy patterns and colours close to skin
|
|
151
|
+
or hair are the hardest cases.
|
|
152
|
+
* MODNet is trained for people. Large props held away from the body may be partly removed.
|
|
153
|
+
|
|
154
|
+
## Credits and licences
|
|
155
|
+
|
|
156
|
+
* MODNet by Ke et al., Apache-2.0 — https://github.com/ZHKKKe/MODNet
|
|
157
|
+
* ONNX model file as packaged by photobooth-app, MIT — https://github.com/photobooth-app/photobooth-app
|
|
158
|
+
* Plugin: MIT
|
|
159
|
+
|
|
160
|
+
## Development and releasing
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
git clone https://github.com/peteoheat/pibooth-modnet && cd pibooth-modnet
|
|
164
|
+
pip install -e .
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
To publish a release to PyPI:
|
|
168
|
+
|
|
169
|
+
1. Bump `__version__` in `pibooth_modnet/__init__.py` and add an entry to `CHANGELOG.md`.
|
|
170
|
+
2. One-off setup: on pypi.org add a *trusted publisher* for the project (owner `peteoheat`, repository
|
|
171
|
+
`pibooth-modnet`, workflow `publish.yml`, environment `pypi`), and create a `pypi` environment in the GitHub
|
|
172
|
+
repository settings.
|
|
173
|
+
3. Create a GitHub release for the new tag. The `Publish to PyPI` workflow builds and uploads it.
|
|
174
|
+
|
|
175
|
+
To publish by hand instead: `pip install build twine && python -m build && twine upload dist/*`.
|