Skip to content

Commit 29a3ed0

Browse files
authored
Merge pull request #224 from saeugetier/220-reduced-resolution-neural-network-for-preview
220 reduced resolution neural network for preview
2 parents c019440 + 71cd33b commit 29a3ed0

5 files changed

Lines changed: 29 additions & 7 deletions

File tree

qml/SettingsMenuForm.ui.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ Item {
242242
id: comboBoxNeuralNetworkRuntime
243243
textRole: "text"
244244
valueRole: "value"
245-
model: [{text: "ONNX Runtime", value: "ONNX"}, {text: "NCNN Runtime", value: "NCNN"}]
246-
Layout.preferredWidth: 200
245+
model: [{text: "ONNX Runtime", value: "ONNX"}, {text: "NCNN Runtime", value: "NCNN"}, {text: "NCNN Runtime (faster preview)", value: "NCNN_LOW_RES"} ]
246+
Layout.preferredWidth: 250
247247
}
248248
}
249249
}

src/replacebackgroundvideofilter.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ void ReplaceBackgroundVideoFilter::setNeuralNetworkRuntime(QString runtime)
5757
{
5858
newRuntime = NeuralNetworkRuntime::ONNX;
5959
}
60+
else if (runtime.contains("NCNN_LOW_RES"))
61+
{
62+
newRuntime = NeuralNetworkRuntime::NCNN_LOW_RES;
63+
}
6064
else if (runtime.contains("NCNN"))
6165
{
6266
newRuntime = NeuralNetworkRuntime::NCNN;
@@ -111,6 +115,10 @@ QString ReplaceBackgroundVideoFilter::getNeuralNetworkRuntime() const
111115
{
112116
return QString("NCNN");
113117
}
118+
else if (mNeuralNetworkRuntime == NeuralNetworkRuntime::NCNN_LOW_RES)
119+
{
120+
return QString("NCNN_LOW_RES");
121+
}
114122
else
115123
{
116124
return QString("Unknown");
@@ -317,6 +325,12 @@ void ReplaceBackgroundFilterRunable::changeNeuralNetworkRuntime(const NeuralNetw
317325
mYoloSegmentorPreview.reset(new YOLOv11SegDetectorNcnn("yolo11n-seg_ncnn_model", "coco.names", false));
318326
mYoloSegmentorHighRes.reset(new YOLOv11SegDetectorNcnn("yolo11x-seg_ncnn_model", "coco.names", false));
319327
}
328+
else if (runtime == NeuralNetworkRuntime::NCNN_LOW_RES)
329+
{
330+
qDebug() << "[INFO] Change YOLOv11Segmentation runtime to NCNN_LOW_RES";
331+
mYoloSegmentorPreview.reset(new YOLOv11SegDetectorNcnn("yolo11n-seg_ncnn_model_320", "coco.names", false, true));
332+
mYoloSegmentorHighRes.reset(new YOLOv11SegDetectorNcnn("yolo11x-seg_ncnn_model", "coco.names", false));
333+
}
320334
}
321335

322336
void ReplaceBackgroundFilterRunable::prepareBackground(cv::Mat &bg, cv::Size size)

src/replacebackgroundvideofilter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class ReplaceBackgroundFilterRunable;
1717
enum class NeuralNetworkRuntime
1818
{
1919
ONNX,
20-
NCNN
20+
NCNN,
21+
NCNN_LOW_RES
2122
};
2223

2324
class ReplaceBackgroundVideoFilter : public QVideoFrameInput

src/yolo11segncnn.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
YOLOv11SegDetectorNcnn::YOLOv11SegDetectorNcnn(const std::string &modelPath,
1111
const std::string &labelsPath,
12-
bool useGPU) : Yolo11Segementation(labelsPath)
12+
bool useGPU, bool use320x320input) : Yolo11Segementation(labelsPath)
1313
{
1414
QString ressourcePathGeneric = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "models", QStandardPaths::LocateDirectory);
1515
QString ressourcePathApp = QStandardPaths::locate(QStandardPaths::AppDataLocation, "models", QStandardPaths::LocateDirectory);
@@ -48,7 +48,14 @@ YOLOv11SegDetectorNcnn::YOLOv11SegDetectorNcnn(const std::string &modelPath,
4848
numOutputNodes = net.output_names().size();
4949

5050
isDynamicInputShape = false; // Assume static input shape by default. NCNN models typically have fixed input shapes.
51-
inputImageShape = cv::Size(640, 640); // Default shape. This is fixed for YOLOv11SegNCNN
51+
52+
if(use320x320input) {
53+
inputImageShape = cv::Size(320, 320);
54+
}
55+
else
56+
{
57+
inputImageShape = cv::Size(640, 640); // Default shape. This is fixed for YOLOv11SegNCNN
58+
}
5259

5360
// Input
5461
if (numInputNodes != 1)
@@ -277,7 +284,7 @@ std::vector<Segmentation> YOLOv11SegDetectorNcnn::segment(const cv::Mat &image,
277284
cv::Scalar(114, 114, 114), /*auto_=*/false,
278285
/*scaleFill=*/false, /*scaleUp=*/true, /*stride=*/32);
279286

280-
ncnn::Mat in = ncnn::Mat::from_pixels_resize(letterboxImage.data, ncnn::Mat::PIXEL_BGR2RGB, letterboxImage.cols, letterboxImage.rows, 640, 640);
287+
ncnn::Mat in = ncnn::Mat::from_pixels_resize(letterboxImage.data, ncnn::Mat::PIXEL_BGR2RGB, letterboxImage.cols, letterboxImage.rows, inputImageShape.width, inputImageShape.height);
281288

282289
const float norm_vals[3] = {1 / 255.f, 1 / 255.f, 1 / 255.f};
283290
in.substract_mean_normalize(0, norm_vals);

src/yolo11segncnn.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class YOLOv11SegDetectorNcnn : public Yolo11Segementation {
3030
public:
3131
YOLOv11SegDetectorNcnn(const std::string &modelPath,
3232
const std::string &labelsPath,
33-
bool useGPU = false);
33+
bool useGPU = false, bool use320x320input = false);
3434

3535
// Main API
3636
std::vector<Segmentation> segment(const cv::Mat &image,

0 commit comments

Comments
 (0)