Skip to content

Commit d196df4

Browse files
authored
Merge pull request #186 from saeugetier/182-yolo-image-segmentation
182 yolo image segmentation
2 parents 37a520b + 117e5c0 commit d196df4

13 files changed

Lines changed: 995 additions & 44 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
build
22
software/build*
3-
3+
libs
44
*.user

models/coco.names

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
person
2+
bicycle
3+
car
4+
motorbike
5+
aeroplane
6+
bus
7+
train
8+
truck
9+
boat
10+
traffic light
11+
fire hydrant
12+
stop sign
13+
parking meter
14+
bench
15+
bird
16+
cat
17+
dog
18+
horse
19+
sheep
20+
cow
21+
elephant
22+
bear
23+
zebra
24+
giraffe
25+
backpack
26+
umbrella
27+
handbag
28+
tie
29+
suitcase
30+
frisbee
31+
skis
32+
snowboard
33+
sports ball
34+
kite
35+
baseball bat
36+
baseball glove
37+
skateboard
38+
surfboard
39+
tennis racket
40+
bottle
41+
wine glass
42+
cup
43+
fork
44+
knife
45+
spoon
46+
bowl
47+
banana
48+
apple
49+
sandwich
50+
orange
51+
broccoli
52+
carrot
53+
hot dog
54+
pizza
55+
donut
56+
cake
57+
chair
58+
sofa
59+
pottedplant
60+
bed
61+
diningtable
62+
toilet
63+
tvmonitor
64+
laptop
65+
mouse
66+
remote
67+
keyboard
68+
cell phone
69+
microwave
70+
oven
71+
toaster
72+
sink
73+
refrigerator
74+
book
75+
clock
76+
vase
77+
scissors
78+
teddy bear
79+
hair drier
80+
toothbrush

models/yolo11n-seg.onnx

11.2 MB
Binary file not shown.

prepare_onnx.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
VERSION="1.21.0"
4+
TARGET_DIR="libs/onnxruntime"
5+
6+
mkdir -p "$TARGET_DIR"
7+
8+
FILE_NAME="onnxruntime-linux-x64-${VERSION}.tgz"
9+
DOWNLOAD_URL="https://github.com/microsoft/onnxruntime/releases/download/v${VERSION}/${FILE_NAME}"
10+
11+
echo "Downloading ONNX Runtime version $VERSION from $DOWNLOAD_URL..."
12+
13+
curl -L -o "$FILE_NAME" "$DOWNLOAD_URL"
14+
15+
if [ $? -ne 0 ]; then
16+
echo "Error: Failed to download ONNX Runtime version $VERSION."
17+
exit 1
18+
fi
19+
20+
echo "Extracting $FILE_NAME to $TARGET_DIR..."
21+
tar -xzf "$FILE_NAME" -C "$TARGET_DIR" --strip-components=1
22+
23+
if [ $? -ne 0 ]; then
24+
echo "Error: Extraction failed."
25+
rm -f "$FILE_NAME"
26+
exit 1
27+
fi
28+
29+
echo "Cleaning up..."
30+
rm -f "$FILE_NAME"
31+
32+
echo "ONNX Runtime version $VERSION successfully downloaded and extracted to $TARGET_DIR."
33+

qml.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,7 @@
9494
<file>shaders/fisheye.frag.qsb</file>
9595
<file>shaders/previewshader.frag</file>
9696
<file>shaders/previewshader.frag.qsb</file>
97+
<file>models/yolo11n-seg.onnx</file>
98+
<file>models/coco.names</file>
9799
</qresource>
98100
</RCC>

qml/SnapshotMenu.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ SnapshotMenuForm {
123123
failureAnimation.start()
124124
}
125125

126-
cameraRenderer.backgroundFilter.method: snapshotSettings.chromaKeyEnabled ? "Chroma" : "None"
127-
cameraRenderer.backgroundFilterEnabled: snapshotSettings.chromaKeyEnabled
126+
cameraRenderer.backgroundFilter.method: snapshotSettings.chromaKeyEnabled ? "Chroma" : "Neural"
127+
cameraRenderer.backgroundFilterEnabled: snapshotSettings.backgroundFilterEnabled
128128
cameraRenderer.backgroundFilter.keyColor: snapshotSettings.chromaKeyColor
129129

130130
SequentialAnimation

qml/SnapshotSettings.qml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ SnapshotSettingsForm {
66
property alias viewFinderBrightness: settings.viewFinderBrightness
77
property alias flashBrightness: settings.flashBrightness
88
property alias countdown: settings.countdown
9+
property alias backgroundFilterEnabled: settings.backgroundFilterEnabled
910
property alias chromaKeyEnabled: settings.chromaKeyEnabled
10-
//property alias chromaKeyStrength: settings.chromaKeyEnabled
1111
property alias chromaKeyColor: settings.chromaKeyColor
1212

1313
Settings
@@ -18,8 +18,8 @@ SnapshotSettingsForm {
1818
property real viewFinderBrightness: 0.1
1919
property real flashBrightness: 1.0
2020
property int countdown: 1
21+
property bool backgroundFilterEnabled: false
2122
property bool chromaKeyEnabled: false
22-
//property real chromaKeyStrength: 0.5
2323
property real chromaKeyColor: 0.5
2424
}
2525

@@ -67,18 +67,18 @@ SnapshotSettingsForm {
6767
settings.countdown = spinBoxCountdownTime.value
6868
}
6969

70+
switchBackgroundFilterEnable.checked: settings.backgroundFilterEnabled
71+
switchBackgroundFilterEnable.onCheckedChanged:
72+
{
73+
settings.backgroundFilterEnabled = switchBackgroundFilterEnable.checked
74+
}
75+
7076
switchChromaKeyEnable.checked: settings.chromaKeyEnabled
7177
switchChromaKeyEnable.onCheckedChanged:
7278
{
7379
settings.chromaKeyEnabled = switchChromaKeyEnable.checked
7480
}
7581

76-
/* sliderChromaKeyFilterStrength.value: settings.chromaKeyStrength
77-
sliderChromaKeyFilterStrength.onValueChanged:
78-
{
79-
settings.chromaKeyStrength = sliderChromaKeyFilterStrength.value
80-
}*/
81-
8282
sliderChromaKeyFilterColor.value: settings.chromaKeyColor
8383
sliderChromaKeyFilterColor.onValueChanged:
8484
{

qml/SnapshotSettingsForm.ui.qml

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Pane {
1212
property alias sliderViewfinderBrightness: sliderViewfinderBrightness
1313
property alias sliderFlashBrightness: sliderFlashBrightness
1414
property alias switchFlashEnable: switchFlashEnable
15+
property alias switchBackgroundFilterEnable: switchBackgroundFilterEnable
1516
property alias switchChromaKeyEnable: switchChromaKeyEnable
16-
//property alias sliderChromaKeyFilterStrength: sliderChromaKeyFilterStrength
1717
property alias sliderChromaKeyFilterColor: sliderChromaKeyFilterColor
1818
opacity: 0.5
1919
spacing: 5
@@ -233,7 +233,7 @@ Pane {
233233

234234
RowLayout
235235
{
236-
id: chromaKey
236+
id: backgroundFilterLabel
237237

238238
spacing: 15
239239

@@ -245,63 +245,56 @@ Pane {
245245
}
246246

247247
Label {
248-
id: labelChromaKey
248+
id: labelBackgroundFilter
249249
font.pixelSize: 32
250-
text: qsTr("Chroma Key")
250+
text: qsTr("Background Filter")
251251
font.family: "DejaVu Serif"
252252
}
253253
}
254254

255255
RowLayout
256256
{
257257
Label {
258-
id: labelChromaKeyFilterEnable
258+
id: labelBackgroundFilterEnable
259259
font.pixelSize: 32
260260
text: "Filter: "
261261
}
262262

263263
Switch {
264-
id: switchChromaKeyEnable
264+
id: switchBackgroundFilterEnable
265265
text: checked ? qsTr("enabled") : qsTr("disabled")
266266
font.pixelSize: 32
267267
font.family: "DejaVu Serif"
268268
width: 250
269269
}
270-
271270
}
272271

273-
274-
/* RowLayout {
275-
id: rowChromaKeyFilterStrength
276-
spacing: 20
272+
RowLayout
273+
{
274+
visible: switchBackgroundFilterEnable.checked
277275

278276
Label {
279-
id: labelChromaKeyFilterStrengthLow
277+
id: labelChromaKeyFilterEnable
280278
font.pixelSize: 32
281-
text: "\uE814"
282-
font.family: "fontello"
279+
text: "Type: "
283280
}
284281

285-
Slider {
286-
id: sliderChromaKeyFilterStrength
287-
value: 0.5
288-
from: 0.5
289-
to: 10.0
282+
Switch {
283+
id: switchChromaKeyEnable
284+
text: checked ? qsTr("chroma") : qsTr("neural")
285+
font.pixelSize: 32
286+
font.family: "DejaVu Serif"
290287
width: 250
291288
}
292289

293-
Label {
294-
id: labelChromaKeyFilterStrengthHigh
295-
font.pixelSize: 32
296-
text: "\uE813"
297-
font.family: "fontello"
298-
}
299-
} */
290+
}
300291

301292
RowLayout {
302293
id: rowChromaKeyFilterColor
303294
spacing: 20
304295

296+
visible: switchChromaKeyEnable.checked & switchBackgroundFilterEnable.checked
297+
305298
Rectangle
306299
{
307300
color: "Green"

qtbooth.pro

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ SOURCES += src/collageiconmodel.cpp \
2424
src/selphyprinter.cpp \
2525
src/standardprinter.cpp \
2626
src/system.cpp \
27-
src/translationhelper.cpp
27+
src/translationhelper.cpp \
28+
src/yolo11seg.cpp
2829

2930
RESOURCES += qml.qrc
3031

@@ -47,7 +48,8 @@ DISTFILES += \
4748
android/gradlew.bat \
4849
android/res/values/libs.xml
4950

50-
INCLUDEPATH += src/
51+
INCLUDEPATH += src/ \
52+
libs/onnxruntime/include/ \
5153

5254
HEADERS += \
5355
src/abstractprinter.h \
@@ -66,11 +68,14 @@ HEADERS += \
6668
src/selphyprinter.h \
6769
src/standardprinter.h \
6870
src/system.h \
69-
src/translationhelper.h
71+
src/translationhelper.h \
72+
src/yolo11seg.h
7073

7174
contains(ANDROID_TARGET_ARCH,x86) {
7275
ANDROID_PACKAGE_SOURCE_DIR = \
7376
$$PWD/android
7477
}
7578

7679
DEFINES += GIT_CURRENT_SHA1="$(shell git -C \""$$_PRO_FILE_PWD_"\" describe)"
80+
81+
LIBS += -L"$$PWD/libs/onnxruntime/lib" -lonnxruntime

src/replacebackgroundvideofilter.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void ReplaceBackgroundVideoFilter::setMethod(QString method)
3636
{
3737
mFilterMethod = FilterMethod::CHROMA;
3838
}
39-
else if(method.contains("Neural Net"))
39+
else if(method.contains("Neural"))
4040
{
4141
mFilterMethod = FilterMethod::NEURAL;
4242
}
@@ -66,7 +66,7 @@ QString ReplaceBackgroundVideoFilter::getMethod() const
6666
}
6767
else if(mFilterMethod == FilterMethod::NEURAL)
6868
{
69-
return QString("Neural Net");
69+
return QString("Neural");
7070
}
7171
else
7272
{
@@ -100,7 +100,7 @@ void ReplaceBackgroundVideoFilter::onProcessingFinished(const QImage& maskImage)
100100
mProcessing = false;
101101
}
102102

103-
ReplaceBackgroundFilterRunable::ReplaceBackgroundFilterRunable(ReplaceBackgroundVideoFilter* filter) : mFilter(filter)
103+
ReplaceBackgroundFilterRunable::ReplaceBackgroundFilterRunable(ReplaceBackgroundVideoFilter* filter) : mFilter(filter), mYoloSegmentor(":/models/yolo11n-seg.onnx", ":/models/coco.names" , false)
104104
{
105105
}
106106

@@ -156,7 +156,22 @@ void ReplaceBackgroundFilterRunable::run(const QVideoFrame& input)
156156
break;
157157

158158
case ReplaceBackgroundVideoFilter::FilterMethod::NEURAL:
159-
break;
159+
{
160+
std::vector<Segmentation> results = mYoloSegmentor.segment(mMat, 0.2f, 0.45f);
161+
162+
cv::Mat mask = cv::Mat::zeros(mMat.size(), CV_8UC1);
163+
164+
std::vector<int> objectFilter = {0};
165+
166+
mYoloSegmentor.drawSegmentationMask(mask, results, objectFilter);
167+
168+
std::vector<cv::Mat> channels;
169+
split(mMat, channels);
170+
channels.push_back(mask);
171+
cv::merge(channels, mMat);
172+
}
173+
174+
break;
160175

161176
case ReplaceBackgroundVideoFilter::FilterMethod::NONE:
162177
break;

0 commit comments

Comments
 (0)