Files
autopilot/tmp/opi_rtsp/aiengine.cpp
T
2024-07-01 14:36:55 +03:00

53 lines
1.5 KiB
C++

#include <QDebug>
#include <opencv2/highgui.hpp>
#include "aiengine.h"
#include "aiengineinference.h"
#include "aiengineinferenceonnx.h"
AiEngine::AiEngine(QString modelPath, QObject *parent)
: QObject{parent}
{
mRtspListener = new AiEngineRtspListener(this);
connect(mRtspListener, &AiEngineRtspListener::frameReceived, this, &AiEngine::frameReceivedSlot);
QThread *inferenceThread = new QThread(this);
mInference = new AiEngineInferenceOnnx(modelPath);
mInference->moveToThread(inferenceThread);
connect(mInference, &AiEngineInference::resultsReady, this, &AiEngine::inferenceResultsReceivedSlot, Qt::QueuedConnection);
connect(this, &AiEngine::inferenceFrame, mInference, &AiEngineInference::performInferenceSlot, Qt::QueuedConnection);
inferenceThread->start();
}
void AiEngine::start(void)
{
mRtspListener->startListening();
}
void AiEngine::stop(void)
{
mRtspListener->stopListening();
}
void AiEngine::inferenceResultsReceivedSlot(AiEngineInferenceResult results)
{
(void)results;
qDebug() << "AiEngine got inference results in thread: " << QThread::currentThreadId();
cv::imshow("Received Frame", results.frame);
}
void AiEngine::frameReceivedSlot(cv::Mat frame)
{
//qDebug() << "AiEngine got frame from RTSP listener in thread: " << QThread::currentThreadId();
//cv::imshow("Received Frame", frame);
if (mInference->isActive() == false) {
qDebug() << "AiEngine. Inference thread is free. Sending frame to it.";
emit inferenceFrame(frame.clone());
}
}