mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 22:06:34 +00:00
Add compile option to use YOLOv8 ONNX models for testing.
- added qmake option yolo_onnx to use normal YOLOv8 ONNX models. This makes possible to test gimbals camera inside without real model. - reduced confidence threshold requirement in AiEngineInferencevOnnxRuntime from 0.5 to 0.2 - make printing prettier with ONNX Runtime - removed unnecessary cv::Mat::clone() Type: Improvement Issue: https://denyspopov.atlassian.net/browse/AZ-39
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
#include "aiengineinferenceonnxruntime.h"
|
||||
|
||||
|
||||
static const float confThreshold = 0.4f;
|
||||
static const float confThreshold = 0.2f;
|
||||
static const float iouThreshold = 0.4f;
|
||||
static const float maskThreshold = 0.5f;
|
||||
|
||||
@@ -15,21 +15,7 @@ AiEngineInferencevOnnxRuntime::AiEngineInferencevOnnxRuntime(QString modelPath,
|
||||
{
|
||||
qDebug() << "TUOMAS AiEngineInferencevOnnxRuntime() mModelPath=" << mModelPath;
|
||||
|
||||
/*
|
||||
mClassNames = {
|
||||
"Armoured vehicle",
|
||||
"Truck",
|
||||
"Vehicle",
|
||||
"Artillery",
|
||||
"Shadow artillery",
|
||||
"Trenches",
|
||||
"Military man",
|
||||
"Tyre tracks",
|
||||
"Additional protection tank",
|
||||
"Smoke"
|
||||
};
|
||||
*/
|
||||
|
||||
#ifdef YOLO_ONNX
|
||||
mClassNames = {
|
||||
"person",
|
||||
"bicycle",
|
||||
@@ -112,6 +98,20 @@ AiEngineInferencevOnnxRuntime::AiEngineInferencevOnnxRuntime(QString modelPath,
|
||||
"hair drier",
|
||||
"toothbrush"
|
||||
};
|
||||
#else
|
||||
mClassNames = {
|
||||
"Armoured vehicle",
|
||||
"Truck",
|
||||
"Vehicle",
|
||||
"Artillery",
|
||||
"Shadow artillery",
|
||||
"Trenches",
|
||||
"Military man",
|
||||
"Tyre tracks",
|
||||
"Additional protection tank",
|
||||
"Smoke"
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -122,28 +122,31 @@ cv::Mat AiEngineInferencevOnnxRuntime::drawLabels(const cv::Mat &image, const st
|
||||
for (const auto &detection : detections)
|
||||
{
|
||||
cv::rectangle(result, detection.box, cv::Scalar(0, 255, 0), 2);
|
||||
std::string label = mClassNames[detection.classId].toStdString() + ": " + std::to_string(detection.conf);
|
||||
|
||||
int confidence = roundf(detection.conf * 100);
|
||||
std::string label = mClassNames[detection.classId].toStdString() + ": " + std::to_string(confidence) + "%";
|
||||
|
||||
int baseLine;
|
||||
cv::Size labelSize = cv::getTextSize(label, cv::FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
|
||||
cv::Size labelSize = cv::getTextSize(label, cv::FONT_HERSHEY_COMPLEX, 0.5, 1, &baseLine);
|
||||
cv::Point labelOrigin(detection.box.x, detection.box.y - labelSize.height - baseLine);
|
||||
|
||||
cv::rectangle(
|
||||
result,
|
||||
cv::Point(detection.box.x, detection.box.y - labelSize.height),
|
||||
cv::Point(detection.box.x + labelSize.width, detection.box.y + baseLine),
|
||||
labelOrigin,
|
||||
cv::Point(detection.box.x + labelSize.width, detection.box.y),
|
||||
cv::Scalar(255, 255, 255),
|
||||
cv::FILLED);
|
||||
|
||||
cv::putText(
|
||||
result,
|
||||
label,
|
||||
cv::Point(
|
||||
detection.box.x,
|
||||
detection.box.y),
|
||||
cv::FONT_HERSHEY_SIMPLEX,
|
||||
cv::Point(detection.box.x, detection.box.y - baseLine + 2),
|
||||
cv::FONT_HERSHEY_COMPLEX,
|
||||
0.5,
|
||||
cv::Scalar(0, 0, 0),
|
||||
1);
|
||||
1,
|
||||
cv::LINE_AA);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -152,15 +155,14 @@ cv::Mat AiEngineInferencevOnnxRuntime::drawLabels(const cv::Mat &image, const st
|
||||
|
||||
void AiEngineInferencevOnnxRuntime::performInferenceSlot(cv::Mat frame)
|
||||
{
|
||||
//qDebug() << __PRETTY_FUNCTION__;
|
||||
qDebug() << __PRETTY_FUNCTION__;
|
||||
|
||||
try {
|
||||
mActive = true;
|
||||
cv::Mat scaledImage = resizeAndPad(frame);
|
||||
//cv::imwrite("/tmp/frame.png", scaledImage);
|
||||
|
||||
std::vector<Yolov8Result> detections = mPredictor.predict(scaledImage);
|
||||
|
||||
#ifdef YOLO_ONNX
|
||||
// Only keep following detected objects.
|
||||
// car = 2
|
||||
// train = 6
|
||||
@@ -174,6 +176,7 @@ void AiEngineInferencevOnnxRuntime::performInferenceSlot(cv::Mat frame)
|
||||
result.classId != 46;
|
||||
});
|
||||
detections.erase(it, detections.end());
|
||||
#endif
|
||||
|
||||
AiEngineInferenceResult result;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user