mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 05:16:33 +00:00
Small fixes to AI Controller
- removed QtSerialPort from the Qt CONFIG parameters - remove compiler warnings - reduced logging - fixed FPS to show what AI really analyzed - RTSP reader tries to connect to the stream once per second until it succeeds
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
QT += core network serialport
|
||||
QT += core network
|
||||
QT -= gui
|
||||
CONFIG += concurrent console c++17
|
||||
MOC_DIR = moc
|
||||
|
||||
+13
-18
@@ -3,7 +3,9 @@
|
||||
|
||||
#include "aiengine.h"
|
||||
#include "aiengineinference.h"
|
||||
#ifdef SAVE_IMAGES
|
||||
#include "aiengineimagesaver.h"
|
||||
#endif
|
||||
|
||||
#if defined(OPI5_BUILD)
|
||||
#include "src-opi5/aiengineinferenceopi5.h"
|
||||
@@ -17,8 +19,11 @@
|
||||
|
||||
|
||||
|
||||
AiEngine::AiEngine(QString modelPath, QObject *parent)
|
||||
: QObject{parent}
|
||||
AiEngine::AiEngine(QString modelPath, QObject *parent) :
|
||||
QObject{parent},
|
||||
mRtspFrameCounter(0),
|
||||
mInferenceFrameCounter(0)
|
||||
|
||||
{
|
||||
mRtspListener = new AiEngineRtspListener(this);
|
||||
connect(mRtspListener, &AiEngineRtspListener::frameReceived, this, &AiEngine::frameReceivedSlot);
|
||||
@@ -69,7 +74,7 @@ AiEngine::AiEngine(QString modelPath, QObject *parent)
|
||||
void AiEngine::start(void)
|
||||
{
|
||||
mRtspListener->startListening();
|
||||
mElapsedTimer.start();
|
||||
mRtspElapsedTimer.start();
|
||||
}
|
||||
|
||||
|
||||
@@ -81,16 +86,15 @@ void AiEngine::stop(void)
|
||||
|
||||
void AiEngine::inferenceResultsReceivedSlot(AiEngineInferenceResult result)
|
||||
{
|
||||
mFrameCounter++;
|
||||
qDebug() << "FPS = " << (mFrameCounter / (mElapsedTimer.elapsed()/1000.0f));
|
||||
//qDebug() << "DEBUG. inference frame counter:" << mFrameCounter;
|
||||
mInferenceFrameCounter++;
|
||||
float fps =mRtspElapsedTimer.elapsed() == 0 ? 0 : (mInferenceFrameCounter / (mRtspElapsedTimer.elapsed()/1000.0f));
|
||||
printf("Analyzed %d/%d frames with AI. FPS=%.1f\n", mInferenceFrameCounter, mRtspFrameCounter, fps);
|
||||
|
||||
//qDebug() << "AiEngine got inference results in thread: " << QThread::currentThreadId();
|
||||
if (mGimbalClient != nullptr) {
|
||||
mGimbalClient->inferenceResultSlot(result);
|
||||
}
|
||||
|
||||
cv::imshow("Received Frame", result.frame);
|
||||
cv::imshow("AI Engine", result.frame);
|
||||
|
||||
#ifdef SAVE_IMAGES
|
||||
static int imageCounter = 0;
|
||||
@@ -103,26 +107,17 @@ void AiEngine::inferenceResultsReceivedSlot(AiEngineInferenceResult result)
|
||||
|
||||
void AiEngine::frameReceivedSlot(cv::Mat frame)
|
||||
{
|
||||
//qDebug() << "AiEngine got frame from RTSP listener in thread: " << QThread::currentThreadId();
|
||||
//cv::imshow("Received Frame", frame);
|
||||
static int framecounter = 0;
|
||||
//qDebug() << "DEBUG. RTSP frame counter:" << framecounter;
|
||||
mRtspFrameCounter++;
|
||||
|
||||
if (mInference->isActive() == false) {
|
||||
//qDebug() << "AiEngine. Inference thread is free. Sending frame to it.";
|
||||
emit inferenceFrame(frame);
|
||||
framecounter++;
|
||||
}
|
||||
#ifdef OPI5_BUILD
|
||||
else if (mInference2->isActive() == false) {
|
||||
//qDebug() << "AiEngine. Inference thread is free. Sending frame to it.";
|
||||
emit inferenceFrame2(frame);
|
||||
framecounter++;
|
||||
}
|
||||
else if (mInference3->isActive() == false) {
|
||||
//qDebug() << "AiEngine. Inference thread is free. Sending frame to it.";
|
||||
emit inferenceFrame3(frame);
|
||||
framecounter++;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QElapsedTimer>
|
||||
#include <QObject>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include "aienginertsplistener.h"
|
||||
@@ -26,8 +26,9 @@ signals:
|
||||
void inferenceFrame3(cv::Mat frame);
|
||||
|
||||
private:
|
||||
QElapsedTimer mElapsedTimer;
|
||||
uint32_t mFrameCounter = 0;
|
||||
uint32_t mRtspFrameCounter;
|
||||
uint32_t mInferenceFrameCounter;
|
||||
QElapsedTimer mRtspElapsedTimer;
|
||||
AiEngineRtspListener *mRtspListener;
|
||||
AiEngineInference *mInference;
|
||||
AiEngineInference *mInference2;
|
||||
|
||||
@@ -82,7 +82,11 @@ void AiEngineRtspListener::listenLoop(void)
|
||||
#else
|
||||
qDebug() << "AiEngineRtspListener loop running in thread: " << QThread::currentThreadId();
|
||||
|
||||
mCap.open(rtspVideoUrl.toStdString());
|
||||
while (mCap.open(rtspVideoUrl.toStdString()) == false) {
|
||||
qDebug() << "AiEngineRtspListener can't open video stream:" << rtspVideoUrl;
|
||||
QThread::msleep(1000);
|
||||
}
|
||||
|
||||
cv::Mat frame;
|
||||
|
||||
while (mIsListening) {
|
||||
|
||||
@@ -13,7 +13,7 @@ AiEngineInferencevOnnxRuntime::AiEngineInferencevOnnxRuntime(QString modelPath,
|
||||
AiEngineInference{modelPath, parent},
|
||||
mPredictor(modelPath.toStdString(), confThreshold, iouThreshold, maskThreshold)
|
||||
{
|
||||
qDebug() << "TUOMAS AiEngineInferencevOnnxRuntime() mModelPath=" << mModelPath;
|
||||
qDebug() << "AiEngineInferencevOnnxRuntime() mModelPath=" << mModelPath;
|
||||
qDebug() << "AiEngineInferencevOnnxRuntime() mClassNames.size() =" << mClassNames.size();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ cv::Mat AiEngineInferencevOnnxRuntime::drawLabels(const cv::Mat &image, const st
|
||||
cv::Scalar(0, 0, 0),
|
||||
1,
|
||||
cv::LINE_AA);
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -58,8 +57,6 @@ cv::Mat AiEngineInferencevOnnxRuntime::drawLabels(const cv::Mat &image, const st
|
||||
|
||||
void AiEngineInferencevOnnxRuntime::performInferenceSlot(cv::Mat frame)
|
||||
{
|
||||
qDebug() << __PRETTY_FUNCTION__;
|
||||
|
||||
try {
|
||||
mActive = true;
|
||||
cv::Mat scaledImage = resizeAndPad(frame);
|
||||
@@ -106,11 +103,8 @@ void AiEngineInferencevOnnxRuntime::performInferenceSlot(cv::Mat frame)
|
||||
result.objects.append(object);
|
||||
}
|
||||
|
||||
if (result.objects.empty() == false) {
|
||||
result.frame = drawLabels(scaledImage, detections);
|
||||
emit resultsReady(result);
|
||||
}
|
||||
|
||||
result.frame = drawLabels(scaledImage, detections);
|
||||
emit resultsReady(result);
|
||||
mActive = false;
|
||||
}
|
||||
catch (const cv::Exception& e) {
|
||||
|
||||
Reference in New Issue
Block a user