#include #include #include "aiengine.h" #include "aiengineinference.h" #if defined(OPI5_BUILD) #include "src-opi5/aiengineinferenceopi5.h" #elif defined(OPENCV_BUILD) #include "src-opencv-onnx/aiengineinferenceopencvonnx.h" #else #include "src-onnx-runtime/aiengineinferenceonnxruntime.h" #endif AiEngine::AiEngine(QString modelPath, QObject *parent) : QObject{parent} { mRtspListener = new AiEngineRtspListener(this); connect(mRtspListener, &AiEngineRtspListener::frameReceived, this, &AiEngine::frameReceivedSlot); #if defined(OPI5_BUILD) mInference = new AiEngineInferenceOpi5(modelPath); #elif defined(OPENCV_BUILD) mInference = new AiEngineInferenceOpencvOnnx(modelPath); #else mInference = new AiEngineInferencevOnnxRuntime(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(); #ifdef OPI5_BUILD mGimbalControl->inferenceResultSlot(result); #endif cv::imshow("Received Frame", result.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()); } }