mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 22:16:33 +00:00
69 lines
1.9 KiB
C++
69 lines
1.9 KiB
C++
#include <QDebug>
|
|
#include <opencv2/highgui.hpp>
|
|
#include "aiengine.h"
|
|
#include "aiengineinference.h"
|
|
|
|
#ifdef OPI5_BUILD
|
|
#include "src-opi5/aiengineinferenceopi5.h"
|
|
#else
|
|
#include "src-onnx/aiengineinferenceonnx.h"
|
|
#endif
|
|
|
|
AiEngine::AiEngine(QString modelPath, QObject *parent)
|
|
: QObject{parent}
|
|
{
|
|
mRtspListener = new AiEngineRtspListener(this);
|
|
connect(mRtspListener, &AiEngineRtspListener::frameReceived, this, &AiEngine::frameReceivedSlot);
|
|
|
|
#ifdef OPI5_BUILD
|
|
mInference = new AiEngineInferenceOpi5(modelPath);
|
|
#else
|
|
mInference = new AiEngineInferenceOnnx(modelPath);
|
|
#endif
|
|
|
|
QThread *inferenceThread = new QThread(this);
|
|
mInference->moveToThread(inferenceThread);
|
|
connect(mInference, &AiEngineInference::resultsReady, this, &AiEngine::inferenceResultsReceivedSlot, Qt::QueuedConnection);
|
|
connect(this, &AiEngine::inferenceFrame, mInference, &AiEngineInference::performInferenceSlot, Qt::QueuedConnection);
|
|
inferenceThread->start();
|
|
|
|
mGimbalControl = new AiEngineGimbalControl(this);
|
|
}
|
|
|
|
|
|
void AiEngine::start(void)
|
|
{
|
|
mRtspListener->startListening();
|
|
}
|
|
|
|
|
|
void AiEngine::stop(void)
|
|
{
|
|
mRtspListener->stopListening();
|
|
}
|
|
|
|
|
|
void AiEngine::inferenceResultsReceivedSlot(AiEngineInferenceResult result)
|
|
{
|
|
//qDebug() << "AiEngine got inference results in thread: " << QThread::currentThreadId();
|
|
|
|
mGimbalControl->inferenceResultSlot(result);
|
|
cv::imshow("Received Frame", result.frame);
|
|
|
|
//#ifndef OPI5_BUILD
|
|
//cv::imshow("Received Frame", result.frame);
|
|
//#endif
|
|
}
|
|
|
|
|
|
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());
|
|
}
|
|
}
|