mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 14:36:35 +00:00
New threaded RTSP and AI image recognition.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user