Files
autopilot/tmp/opi_rtsp/src-onnx/aiengineinferenceonnx.cpp
T
2024-07-09 20:34:21 +02:00

46 lines
1.7 KiB
C++

#include <QDebug>
#include <QThread>
#include "aiengineinferenceonnx.h"
AiEngineInferenceOnnx::AiEngineInferenceOnnx(QString modelPath, QObject *parent)
: AiEngineInference{modelPath, parent}
{
//qDebug() << "TUOMAS test mModelPath=" << mModelPath;
mEngine = new InferenceEngine(modelPath.toStdString());
}
void AiEngineInferenceOnnx::performInferenceSlot(cv::Mat frame)
{
//qDebug() << "performInferenceSlot() in thread: " << QThread::currentThreadId();
mActive = true;
int orig_width = frame.cols;
int orig_height = frame.rows;
std::vector<float> input_tensor_values = mEngine->preprocessImage(frame);
std::vector<float> results = mEngine->runInference(input_tensor_values);
float confidence_threshold = 0.4;
std::vector<Detection> detections = mEngine->filterDetections(results, confidence_threshold, mEngine->input_shape[2], mEngine->input_shape[3], orig_width, orig_height);
AiEngineInferenceResult result;
for (uint32_t i = 0; i < detections.size(); i++) {
const Detection &detection = detections[i];
AiEngineObject object;
object.classId = detection.class_id;
object.propability = detection.confidence;
object.rectangle.top = detection.bbox.y;
object.rectangle.left = detection.bbox.x;
object.rectangle.bottom = detection.bbox.y + detection.bbox.height;
object.rectangle.right = detection.bbox.x + detection.bbox.width;
result.objects.append(object);
}
result.frame = mEngine->draw_labels(frame.clone(), detections);
emit resultsReady(result);
mActive = false;
}