Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions qml/SettingsMenuForm.ui.qml
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ Item {
id: comboBoxNeuralNetworkRuntime
textRole: "text"
valueRole: "value"
model: [{text: "ONNX Runtime", value: "ONNX"}, {text: "NCNN Runtime", value: "NCNN"}]
Layout.preferredWidth: 200
model: [{text: "ONNX Runtime", value: "ONNX"}, {text: "NCNN Runtime", value: "NCNN"}, {text: "NCNN Runtime (faster preview)", value: "NCNN_LOW_RES"} ]
Layout.preferredWidth: 250
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/replacebackgroundvideofilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ void ReplaceBackgroundVideoFilter::setNeuralNetworkRuntime(QString runtime)
{
newRuntime = NeuralNetworkRuntime::ONNX;
}
else if (runtime.contains("NCNN_LOW_RES"))
{
newRuntime = NeuralNetworkRuntime::NCNN_LOW_RES;
}
else if (runtime.contains("NCNN"))
{
newRuntime = NeuralNetworkRuntime::NCNN;
Expand Down Expand Up @@ -111,6 +115,10 @@ QString ReplaceBackgroundVideoFilter::getNeuralNetworkRuntime() const
{
return QString("NCNN");
}
else if (mNeuralNetworkRuntime == NeuralNetworkRuntime::NCNN_LOW_RES)
{
return QString("NCNN_LOW_RES");
}
else
{
return QString("Unknown");
Expand Down Expand Up @@ -317,6 +325,12 @@ void ReplaceBackgroundFilterRunable::changeNeuralNetworkRuntime(const NeuralNetw
mYoloSegmentorPreview.reset(new YOLOv11SegDetectorNcnn("yolo11n-seg_ncnn_model", "coco.names", false));
mYoloSegmentorHighRes.reset(new YOLOv11SegDetectorNcnn("yolo11x-seg_ncnn_model", "coco.names", false));
}
else if (runtime == NeuralNetworkRuntime::NCNN_LOW_RES)
{
qDebug() << "[INFO] Change YOLOv11Segmentation runtime to NCNN_LOW_RES";
mYoloSegmentorPreview.reset(new YOLOv11SegDetectorNcnn("yolo11n-seg_ncnn_model_320", "coco.names", false, true));
mYoloSegmentorHighRes.reset(new YOLOv11SegDetectorNcnn("yolo11x-seg_ncnn_model", "coco.names", false));
}
}

void ReplaceBackgroundFilterRunable::prepareBackground(cv::Mat &bg, cv::Size size)
Expand Down
3 changes: 2 additions & 1 deletion src/replacebackgroundvideofilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class ReplaceBackgroundFilterRunable;
enum class NeuralNetworkRuntime
{
ONNX,
NCNN
NCNN,
NCNN_LOW_RES
};

class ReplaceBackgroundVideoFilter : public QVideoFrameInput
Expand Down
13 changes: 10 additions & 3 deletions src/yolo11segncnn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

YOLOv11SegDetectorNcnn::YOLOv11SegDetectorNcnn(const std::string &modelPath,
const std::string &labelsPath,
bool useGPU) : Yolo11Segementation(labelsPath)
bool useGPU, bool use320x320input) : Yolo11Segementation(labelsPath)
{
QString ressourcePathGeneric = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "models", QStandardPaths::LocateDirectory);
QString ressourcePathApp = QStandardPaths::locate(QStandardPaths::AppDataLocation, "models", QStandardPaths::LocateDirectory);
Expand Down Expand Up @@ -48,7 +48,14 @@ YOLOv11SegDetectorNcnn::YOLOv11SegDetectorNcnn(const std::string &modelPath,
numOutputNodes = net.output_names().size();

isDynamicInputShape = false; // Assume static input shape by default. NCNN models typically have fixed input shapes.
inputImageShape = cv::Size(640, 640); // Default shape. This is fixed for YOLOv11SegNCNN

if(use320x320input) {
inputImageShape = cv::Size(320, 320);
}
else
{
inputImageShape = cv::Size(640, 640); // Default shape. This is fixed for YOLOv11SegNCNN
}

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

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

const float norm_vals[3] = {1 / 255.f, 1 / 255.f, 1 / 255.f};
in.substract_mean_normalize(0, norm_vals);
Expand Down
2 changes: 1 addition & 1 deletion src/yolo11segncnn.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class YOLOv11SegDetectorNcnn : public Yolo11Segementation {
public:
YOLOv11SegDetectorNcnn(const std::string &modelPath,
const std::string &labelsPath,
bool useGPU = false);
bool useGPU = false, bool use320x320input = false);

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