#include #include #include "aienginegimbalcontrol.h" AiEngineGimbalControl::AiEngineGimbalControl(QObject *parent) : QObject{parent} {} AiEngineRectangle AiEngineGimbalControl::getGroupCoordinates(QVector &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) { qDebug() << "ERROR! inferenceResultSlot() groupRect.top > 720 || groupRect.bottom > 720"; return; } if (groupRect.left > 1280 || groupRect.right > 1280) { qDebug() << "ERROR! inferenceResultSlot() groupRect.left > 1280 || groupRect.right > 1280"; return; } if ((groupRect.bottom <= groupRect.top) || (groupRect.right <= groupRect.left)) { qDebug() << "ERROR! (groupRect.bottom <= groupRect.top) || (groupRect.right <= groupRect.left)"; return; } qDebug() << "TUOMAS!! Zooming to square top=" << groupRect.top << "x" << groupRect.left << "and bottom:" << groupRect.bottom << "x" << groupRect.right; mRemoteControl.sendData(groupRect.top, groupRect.left, groupRect.bottom, groupRect.right); }