Skip to content

Commit 9a8a981

Browse files
authored
Merge pull request #210 from saeugetier/feature/190-execute-interference-via-ncnnopenvino
Feature/190 execute interference via ncnnopenvino
2 parents 8ff521f + f9815d3 commit 9a8a981

22 files changed

Lines changed: 1514 additions & 834 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ flatpak/build-dir
88
flatpak/repo
99
flatpak/.flatpak-builder
1010
*.user
11+
models/*.bin
12+
models/*.param
13+
logs

io.github.saeugetier.photobooth.json

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
],
4646
"cleanup": [
4747
"/bin/*",
48-
"/share/opencv4/*"
48+
"/share/*"
4949
]
5050
},
5151
{
@@ -75,6 +75,25 @@
7575
}
7676
]
7777
},
78+
{
79+
"name": "ncnn",
80+
"buildsystem": "cmake-ninja",
81+
"builddir": true,
82+
"config-opts": [
83+
"-DNCNN_BUILD_TESTS=OFF",
84+
"-DNCNN_BUILD_EXAMPLES=OFF",
85+
"-DNCNN_BUILD_TOOLS=OFF",
86+
"-DNCNN_BUILD_BENCHMARK=OFF",
87+
"-DNCNN_SHARED_LIB=ON"
88+
],
89+
"sources": [
90+
{
91+
"type": "archive",
92+
"url": "https://github.com/Tencent/ncnn/archive/refs/tags/20250503.tar.gz",
93+
"sha256": "3afea4cf092ce97d06305b72c6affbcfb3530f536ae8e81a4f22007d82b729e9"
94+
}
95+
]
96+
},
7897
{
7998
"name": "qtvirtualkeyboard",
8099
"buildsystem": "cmake-ninja",
@@ -92,6 +111,38 @@
92111
"rmdir ${FLATPAK_DEST}/lib/${FLATPAK_ARCH}-linux-gnu"
93112
]
94113
},
114+
{
115+
"name": "yolo-models",
116+
"buildsystem": "simple",
117+
"build-options": {
118+
"build-args": [
119+
"--share=network"
120+
]
121+
},
122+
"build-commands": [
123+
"python3 -m venv yolo-venv",
124+
". yolo-venv/bin/activate && pip install --no-cache-dir numpy==1.26.4",
125+
". yolo-venv/bin/activate && pip install --no-cache-dir torch==2.4.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu",
126+
". yolo-venv/bin/activate && pip install --no-cache-dir ultralytics==8.3.168 onnxruntime onnx==1.16.1 onnxslim==0.1.59 ncnn==1.0.20250503 rknn-toolkit2==2.3.2",
127+
". yolo-venv/bin/activate && yolo export model=yolo11n-seg.pt format=onnx",
128+
". yolo-venv/bin/activate && yolo export model=yolo11x-seg.pt format=onnx",
129+
". yolo-venv/bin/activate && yolo export model=yolo11n-seg.pt format=ncnn",
130+
". yolo-venv/bin/activate && yolo export model=yolo11x-seg.pt format=ncnn",
131+
"rm -rf yolo-venv"
132+
],
133+
"post-install": [
134+
"rm *.pt",
135+
"rm *.torchscript",
136+
"mkdir ${FLATPAK_DEST}/share/models",
137+
"mv * ${FLATPAK_DEST}/share/models"
138+
],
139+
"sources": [
140+
{
141+
"type": "file",
142+
"path": "models/coco.names"
143+
}
144+
]
145+
},
95146
{
96147
"name": "qtbooth",
97148
"buildsystem": "qmake",

io.github.saeugetier.photobooth.metainfo.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
</screenshots>
3737

3838
<releases>
39+
<release version="0.7.1" date="2025-07-22">
40+
<description translate="no">
41+
<p>NCNN as secondary neural network runtime for accelerated execution on Raspberry Pi. Several bugfixes for better user experience with flatpak build.</p>
42+
</description>
43+
</release>
3944
<release version="0.7.0" date="2025-05-25">
4045
<description translate="no">
4146
<p>Initial release with flatpak. New implementation of background removal filter. Port from Qt5 to Qt6.</p>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from ultralytics import YOLO
2+
3+
# Load a model
4+
model_n = YOLO("yolo11n-seg.pt") # load an official model
5+
model_x = YOLO("yolo11x-seg.pt") # load an official model
6+
7+
# Export the model
8+
model_n.export(format="onnx")
9+
model_n.export(format="ncnn")
10+
11+
model_x.export(format="onnx")
12+
model_x.export(format="ncnn")
13+

qml/Application.qml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ ApplicationWindow {
153153
console.log("Camera orientation changed to: " + applicationSettings.cameraOrientation)
154154
}
155155

156+
settingsMenu.comboBoxNeuralNetworkRuntime.onCurrentValueChanged:
157+
{
158+
applicationSettings.neuralNetworkRuntime = String(settingsMenu.comboBoxNeuralNetworkRuntime.currentValue)
159+
console.log("Neural network runtime changed to: " + applicationSettings.neuralNetworkRuntime)
160+
}
161+
156162
mainMenu.printerBusy: printer ? printer.busy : false
157163
}
158164

@@ -174,6 +180,7 @@ ApplicationWindow {
174180
property bool printFromGallery: true
175181
property bool enableSettingsPassword: true
176182
property int cameraOrientation: 0
183+
property string neuralNetworkRuntime: "ONNX"
177184

178185
Component.onCompleted:
179186
{
@@ -190,6 +197,7 @@ ApplicationWindow {
190197
flow.collageMenu.multiplePrints = multiplePrints
191198
flow.snapshotMenu.hideSnapshotSettingsPane = disableSnapshotSettingsPane
192199
flow.imagePreview.effectButton.visible = !disableEffectPopup
200+
flow.settingsMenu.comboBoxNeuralNetworkRuntime.currentIndex = flow.settingsMenu.comboBoxNeuralNetworkRuntime.indexOfValue(neuralNetworkRuntime)
193201
}
194202

195203
onPrinterNameChanged:

qml/SettingsMenuForm.ui.qml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Item {
2727
property alias switchEnableSettingsPassword: switchEnableSettingsPassword
2828
property alias versionText: labelVersionText.text
2929
property alias comboBoxCameraOrientation: comboBoxCameraOrientation
30+
property alias comboBoxNeuralNetworkRuntime: comboBoxNeuralNetworkRuntime
3031

3132
ColumnLayout {
3233
anchors.fill: parent
@@ -191,6 +192,27 @@ Item {
191192
}]
192193
}
193194
}
195+
196+
RowLayout
197+
{
198+
spacing: 10
199+
Label
200+
{
201+
text: qsTr("Neuroal Network Runtime")
202+
}
203+
Item
204+
{
205+
Layout.fillWidth: true
206+
}
207+
ComboBox
208+
{
209+
id: comboBoxNeuralNetworkRuntime
210+
textRole: "text"
211+
valueRole: "value"
212+
model: [{text: "ONNX Runtime", value: "ONNX"}, {text: "NCNN Runtime", value: "NCNN"}]
213+
Layout.preferredWidth: 200
214+
}
215+
}
194216
}
195217
}
196218

qml/SnapshotMenu.qml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ SnapshotMenuForm {
126126
cameraRenderer.backgroundFilter.method: snapshotSettings.backgroundFilterEnabled ? (snapshotSettings.chromaKeyEnabled ? "Chroma" : "Neural") : "None"
127127
cameraRenderer.backgroundFilterEnabled: snapshotSettings.backgroundFilterEnabled
128128
cameraRenderer.backgroundFilter.keyColor: snapshotSettings.chromaKeyColor
129+
cameraRenderer.backgroundFilter.neuralNetworkRuntime: applicationSettings.neuralNetworkRuntime
129130
cameraRenderer.backgroundImage: snapshotSettings.backgroundImage
130131

131132
SequentialAnimation

qtbooth.pro

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ SOURCES += src/collageiconmodel.cpp \
2121
src/noprinter.cpp \
2222
src/printerfactory.cpp \
2323
src/replacebackgroundvideofilter.cpp \
24+
src/segmentation.cpp \
2425
src/selphyprinter.cpp \
2526
src/standardprinter.cpp \
2627
src/system.cpp \
2728
src/translationhelper.cpp \
28-
src/yolo11seg.cpp
29+
src/yolo11segncnn.cpp \
30+
src/yolo11segonnx.cpp
2931

30-
RESOURCES += qml.qrc \
31-
yolomodel.large.qrc \
32-
yolomodel.small.qrc
32+
RESOURCES += qml.qrc
3333

3434
# Additional import path used to resolve QML modules in Qt Creator's code model
3535
QML_IMPORT_PATH =
@@ -52,6 +52,7 @@ DISTFILES += \
5252

5353
INCLUDEPATH += src/ \
5454
libs/onnxruntime/include/ \
55+
libs/ncnn/include/ \
5556

5657
HEADERS += \
5758
src/abstractprinter.h \
@@ -67,11 +68,14 @@ HEADERS += \
6768
src/noprinter.h \
6869
src/printerfactory.h \
6970
src/replacebackgroundvideofilter.h \
71+
src/segmentation.h \
7072
src/selphyprinter.h \
7173
src/standardprinter.h \
7274
src/system.h \
7375
src/translationhelper.h \
74-
src/yolo11seg.h
76+
src/yolo11segncnn.h \
77+
src/yolo11segonnx.h \
78+
src/yolobackend.h
7579

7680
contains(ANDROID_TARGET_ARCH,x86) {
7781
ANDROID_PACKAGE_SOURCE_DIR = \
@@ -81,6 +85,7 @@ contains(ANDROID_TARGET_ARCH,x86) {
8185
DEFINES += GIT_CURRENT_SHA1="$(shell git -C \""$$_PRO_FILE_PWD_"\" describe)"
8286

8387
LIBS += -L"$$PWD/libs/onnxruntime/lib" -lonnxruntime
88+
LIBS += -L"$$PWD/libs/ncnn/lib" -lncnn
8489

8590
!isEmpty(PREFIX) {
8691
INSTALLS += target

src/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ int main(int argc, char *argv[])
111111
if (QFontDatabase::addApplicationFont(":/font/DejaVuSerif/DejaVuSerif.ttf") == -1)
112112
qWarning() << "Failed to load DejaVuSerif.ttf";
113113

114+
qDebug() << "Standard path: " << QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
115+
qDebug() << "Standard path: " << QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
116+
114117
qmlRegisterType<CollageModelFactory>("CollageModel", 1, 0, "CollageModelFactory");
115118
qmlRegisterUncreatableType<CollageIconModel>("CollageModel", 1, 0, "CollageIconModel", "CollageIconModel can only be created via CollageModeFactory");
116119
qmlRegisterUncreatableType<CollageImageModel>("CollageModel", 1, 0, "CollageImageModel", "CollageImageModel can only be created via CollageModeFactory");

0 commit comments

Comments
 (0)