mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 06:56:33 +00:00
8e88cb6fe1
Functionality has been written to rtsp_ai_player. TODO!! - move functionality of camera module misc/rtsp_ai_player/aienginegimbalserver.cpp - implement all signals in AiEngineGimbalClient - get drone position from autopilot and send it to AiEngineGimbalServer
114 lines
4.2 KiB
C++
114 lines
4.2 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(this);
|
|
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;
|
|
|
|
// 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;
|
|
|
|
AiEngineCameraTarget target;
|
|
target.rectangle = groupRect;
|
|
target.index = index++;
|
|
emit zoomToAiTarget(target);
|
|
}
|