mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 21:46:33 +00:00
ba810592b5
Gimbal camera can be enabled and used for example with command: qmake6 CONFIG+=gimbal && make && ./rtsp_ai_player ~/azaion/models/onnx/yolov8m.onnx
139 lines
5.0 KiB
C++
139 lines
5.0 KiB
C++
#include <QDebug>
|
|
#include <QThread>
|
|
#include <QVector>
|
|
#include "aienginegimbalclient.h"
|
|
#include "aiengineinference.h"
|
|
|
|
AiEngineGimbalClient::AiEngineGimbalClient(QObject *parent)
|
|
: QObject{parent}
|
|
{
|
|
// Create server and run it in the new thread.
|
|
// Connect all signal and slots here. No need to do the same in AiEngineGimbalServer class.
|
|
|
|
mGimbalServer = new AiEngineGimbalServer();
|
|
QThread *gimbalServerThread = new QThread(this);
|
|
mGimbalServer->moveToThread(gimbalServerThread);
|
|
|
|
// Client -> Server communication. Only zoomToAiTarget() signal is emitted ATM.
|
|
connect(this, &AiEngineGimbalClient::setDronePosition, mGimbalServer, &AiEngineGimbalServer::dronePositionSlot, Qt::QueuedConnection);
|
|
connect(this, &AiEngineGimbalClient::zoomToAiTarget, mGimbalServer, &AiEngineGimbalServer::zoomToAiTargetSlot, Qt::QueuedConnection);
|
|
connect(this, &AiEngineGimbalClient::setCameraPosition, mGimbalServer, &AiEngineGimbalServer::cameraPositionSlot, Qt::QueuedConnection);
|
|
|
|
// Server -> Client communication
|
|
connect(mGimbalServer, &AiEngineGimbalServer::aiTargetZoomed, this, &AiEngineGimbalClient::aiTargetZoomedSlot, Qt::QueuedConnection);
|
|
connect(mGimbalServer, &AiEngineGimbalServer::newCameraPosition, this, &AiEngineGimbalClient::cameraPositionSlot, Qt::QueuedConnection);
|
|
|
|
gimbalServerThread->start();
|
|
}
|
|
|
|
|
|
void AiEngineGimbalClient::aiTargetZoomedSlot(AiEngineTargetPosition targetPosition)
|
|
{
|
|
qDebug() << "AiEngineGimbalClient::aiTargetZoomedSlot() Server zoomed to index:"
|
|
<< targetPosition.targetIndex
|
|
<< "Geopos:"
|
|
<< targetPosition.position.lat
|
|
<< targetPosition.position.lon
|
|
<< targetPosition.position.alt;
|
|
}
|
|
|
|
|
|
void AiEngineGimbalClient::cameraPositionSlot(AiEngineCameraPosition cameraPosition)
|
|
{
|
|
qDebug() << "AiEngineGimbalClient::cameraPositionSlot() Camera moved to:"
|
|
<< cameraPosition.pitch
|
|
<< cameraPosition.yaw
|
|
<< cameraPosition.zoom;
|
|
}
|
|
|
|
|
|
AiEngineRectangle AiEngineGimbalClient::getGroupCoordinates(QVector<AiEngineObject> &objects)
|
|
{
|
|
AiEngineRectangle groupRectangle;
|
|
groupRectangle.top = 1000000;
|
|
groupRectangle.left = 1000000;
|
|
groupRectangle.bottom = 0;
|
|
groupRectangle.right = 0;
|
|
|
|
for (int i = 0; i < objects.size(); i++) {
|
|
const AiEngineRectangle &objectRectangle = objects[i].rectangle;
|
|
|
|
if (objectRectangle.top < groupRectangle.top) {
|
|
groupRectangle.top = objectRectangle.top;
|
|
}
|
|
if (objectRectangle.left < groupRectangle.left) {
|
|
groupRectangle.left = objectRectangle.left;
|
|
}
|
|
if (objectRectangle.bottom > groupRectangle.bottom) {
|
|
groupRectangle.bottom = objectRectangle.bottom;
|
|
}
|
|
if (objectRectangle.right > groupRectangle.right) {
|
|
groupRectangle.right = objectRectangle.right;
|
|
}
|
|
}
|
|
|
|
return groupRectangle;
|
|
}
|
|
|
|
|
|
void AiEngineGimbalClient::inferenceResultSlot(AiEngineInferenceResult result)
|
|
{
|
|
if (result.objects.size() == 0) {
|
|
return;
|
|
}
|
|
|
|
// TODO!! Just increasing number for testing purposes ATM.
|
|
static int index = 0;
|
|
|
|
// Find best possible target ...
|
|
int bestObjectIndex = -1;
|
|
float bestObjectProb = -1;
|
|
for (int i = 0; i < result.objects.size(); i++) {
|
|
const AiEngineObject &object = result.objects[i];
|
|
if (object.propability > bestObjectProb) {
|
|
bestObjectIndex = i;
|
|
bestObjectProb = object.propability;
|
|
}
|
|
}
|
|
|
|
// ... if found, then ask camera to zoom to it.
|
|
if (bestObjectIndex >= 0) {
|
|
const AiEngineObject &object = result.objects[bestObjectIndex];
|
|
|
|
AiEngineCameraTarget target;
|
|
target.rectangle = object.rectangle;
|
|
target.index = index++;
|
|
|
|
qDebug() << "Found best target from index" << bestObjectIndex
|
|
<< "Name:" << object.classStr
|
|
<< "Probability:" << bestObjectProb;
|
|
|
|
if (mGimbalServer->isAvailable()) {
|
|
emit zoomToAiTarget(target);
|
|
}
|
|
}
|
|
|
|
/*
|
|
// We got list of all recognized objects, but at least for now we will zoom to all objects at
|
|
// once and not for each invidually. Got minimal coordinates which contains the all objects.
|
|
AiEngineRectangle groupRect = getGroupCoordinates(result.objects);
|
|
|
|
if (groupRect.top > 600 || groupRect.bottom > 600) {
|
|
qDebug() << "ERROR! inferenceResultSlot() groupRect.top > 600 || groupRect.bottom > 600";
|
|
return;
|
|
}
|
|
|
|
if (groupRect.left > 600 || groupRect.right > 600) {
|
|
qDebug() << "ERROR! inferenceResultSlot() groupRect.left > 600 || groupRect.right > 600";
|
|
return;
|
|
}
|
|
|
|
if ((groupRect.bottom <= groupRect.top) || (groupRect.right <= groupRect.left)) {
|
|
qDebug() << "ERROR! (groupRect.bottom <= groupRect.top) || (groupRect.right <= groupRect.left)";
|
|
return;
|
|
}
|
|
|
|
qDebug() << "inferenceResultSlot() Zooming to square top=" << groupRect.top << "x" << groupRect.left << "and bottom:" << groupRect.bottom << "x" << groupRect.right;
|
|
*/
|
|
}
|