mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 22:06:34 +00:00
71 lines
2.2 KiB
C++
71 lines
2.2 KiB
C++
#include <QDebug>
|
|
#include <QVector>
|
|
#include "aienginegimbalcontrol.h"
|
|
|
|
AiEngineGimbalControl::AiEngineGimbalControl(QObject *parent)
|
|
: QObject{parent}
|
|
{}
|
|
|
|
|
|
AiEngineRectangle AiEngineGimbalControl::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 AiEngineGimbalControl::inferenceResultSlot(AiEngineInferenceResult result)
|
|
{
|
|
if (result.objects.size() == 0) {
|
|
return;
|
|
}
|
|
|
|
// 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);
|
|
|
|
// AI did inference with 640x360 resolution. Scale back to A8's 1280x720 resolution.
|
|
groupRect.top *= 2;
|
|
groupRect.left *= 2;
|
|
groupRect.bottom *= 2;
|
|
groupRect.right *= 2;
|
|
|
|
if (groupRect.top > 720 || groupRect.bottom > 720) {
|
|
return;
|
|
}
|
|
|
|
if (groupRect.left > 1280 || groupRect.right > 1280) {
|
|
return;
|
|
}
|
|
|
|
if ((groupRect.bottom <= groupRect.top) || (groupRect.right <= groupRect.left)) {
|
|
return;
|
|
}
|
|
|
|
qDebug() << "TUOMAS!! Zooming to square" << groupRect.top << "x" << groupRect.left << "and" << groupRect.bottom << "x" << groupRect.right;
|
|
|
|
mRemoteControl.sendData(groupRect.top, groupRect.left, groupRect.left, groupRect.right);
|
|
}
|