Skip to content

Commit

Permalink
Merge pull request #51 from AIRLegend/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
AIRLegend committed Sep 11, 2020
2 parents d36ecca + 3e0ce44 commit 7649c3c
Show file tree
Hide file tree
Showing 19 changed files with 262 additions and 29 deletions.
17 changes: 16 additions & 1 deletion AITracker/src/PositionSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ void PositionSolver::solve_rotation(FaceData* face_data)
for (int i = 0; i < 3; i++)
{
face_data->rotation[i] = rvec.at<double>(i, 0);
face_data->translation[i] = tvec.at<double>(i, 0);
face_data->translation[i] = tvec.at<double>(i, 0) * 10;
}

correct_rotation(*face_data);

}

void PositionSolver::set_prior_pitch(float new_pitch)
Expand Down Expand Up @@ -135,3 +137,16 @@ void PositionSolver::get_euler(cv::Mat& rvec, cv::Mat& tvec)

}

void PositionSolver::correct_rotation(FaceData& face_data)
{
float distance = -(face_data.translation[2]);
float lateral_offset = face_data.translation[1];
float verical_offset = face_data.translation[0];

float correction_yaw = std::atan(std::tan(lateral_offset / distance)) * TO_DEG;
float correction_pitch = std::atan(std::tan(verical_offset / distance)) * TO_DEG;

face_data.rotation[1] += correction_yaw;
face_data.rotation[0] += correction_pitch;
}

7 changes: 7 additions & 0 deletions AITracker/src/PositionSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class PositionSolver

private:
static const int NB_CONTOUR_POINTS = 18;
const double TO_DEG = (180.0 / 3.14159265);

cv::Mat mat3dface;
cv::Mat mat3dcontour;
Expand All @@ -52,5 +53,11 @@ class PositionSolver
Gets euler angles from rotation matrix.
*/
void get_euler(cv::Mat& rvec, cv::Mat& tvec);

/**
* Lateral/Vertical offset adds an error to the calculated rotation.
* This method corrects them.
*/
void correct_rotation(FaceData& face_data);
};

5 changes: 4 additions & 1 deletion Client/Client.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
</ItemDefinitionGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
<QtInstall>$(QTDIR)</QtInstall>
<QtModules>core;uitools;widgets;quick</QtModules>
<QtModules>core;uitools;widgets;quick;</QtModules>
<QtBuildConfig>debug</QtBuildConfig>
<QtLibrarySearchPath>$(QTDIR)\lib;$(QtLibrarySearchPath)</QtLibrarySearchPath>
<QtHeaderSearchPath>$(QTDIR)\include</QtHeaderSearchPath>
Expand Down Expand Up @@ -179,6 +179,7 @@
<ClCompile Include="src\camera\CameraFactory.cpp" />
<ClCompile Include="src\model\Config.cpp" />
<ClCompile Include="src\camera\Ps3Camera.cpp" />
<ClCompile Include="src\model\UpdateChecker.cpp" />
<ClCompile Include="src\presenter\presenter.cpp" />
<ClCompile Include="src\Main.cpp" />
<ClCompile Include="src\model\UDPSender.cpp" />
Expand All @@ -200,8 +201,10 @@
<ClInclude Include="src\camera\CameraFactory.h" />
<ClInclude Include="Include\ps3eye.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="src\version.h" />
<ClInclude Include="src\model\Config.h" />
<ClInclude Include="src\camera\Ps3Camera.h" />
<QtMoc Include="src\model\UpdateChecker.h" />
<ClInclude Include="src\presenter\i_presenter.h" />
<ClInclude Include="src\presenter\presenter.h" />
<ClInclude Include="src\model\UDPSender.h" />
Expand Down
9 changes: 9 additions & 0 deletions Client/Client.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<ClCompile Include="src\view\ConfigWindow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\model\UpdateChecker.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Include\ps3eye.h" />
Expand Down Expand Up @@ -68,12 +71,18 @@
<ClInclude Include="src\camera\CameraSettings.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\version.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<QtMoc Include="src\view\WindowMain.h" />
<QtMoc Include="src\view\ConfigWindow.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="src\model\UpdateChecker.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<QtRcc Include="res\Resource.qrc">
Expand Down
4 changes: 4 additions & 0 deletions Client/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include "spdlog/sinks/basic_file_sink.h"


#include "model/UpdateChecker.h"



int main(int argc, char *argv[])
{

Expand Down
16 changes: 9 additions & 7 deletions Client/src/camera/OCVCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ OCVCamera::OCVCamera(int width, int height, int fps, int index) :
if (fps < 0)
this->fps = cam_native_fps;


cap.set(cv::CAP_PROP_FRAME_WIDTH, this->width);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, this->height);
cap.set(cv::CAP_PROP_FPS, this->fps);

exposure, gain = -1;
}

Expand All @@ -55,7 +50,7 @@ bool OCVCamera::is_camera_available()

cam_native_width = (int)cap.get(cv::CAP_PROP_FRAME_WIDTH);
cam_native_height = (int)cap.get(cv::CAP_PROP_FRAME_HEIGHT);
cam_native_fps = (int)cap.get(cv::CAP_PROP_FPS);
cam_native_fps = std::max(30, (int)cap.get(cv::CAP_PROP_FPS));
cap.release();
}
return available;
Expand All @@ -68,6 +63,13 @@ void OCVCamera::start_camera()
{
throw std::runtime_error("No compatible camera found.");
}

// Force its properties each time we start the camera
// because if we force them with the device switched off
// bugs will occur (tiling, for example).
cap.set(cv::CAP_PROP_FRAME_WIDTH, this->width);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, this->height);
cap.set(cv::CAP_PROP_FPS, this->fps);
}

void OCVCamera::stop_camera()
Expand All @@ -89,7 +91,7 @@ void OCVCamera::set_settings(CameraSettings& settings)
{
this->width = settings.width > 0 ? settings.width : this->cam_native_width;
this->height = settings.height > 0 ? settings.height : this->cam_native_height;
this->fps = settings.fps > 0 ? settings.fps : this->cam_native_fps;
this->fps = settings.fps >= 30 ? settings.fps : this->cam_native_fps;

// Disabled for the moment because of the different ranges in generic cameras.
//exposure = settings.exposure < 0 ? -1.0F : (float)settings.exposure/255;
Expand Down
3 changes: 3 additions & 0 deletions Client/src/model/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ConfigData ConfigData::getGenericConfig()
conf.video_height = -1;
conf.video_fps = -1;
conf.use_landmark_stab = true;
conf.autocheck_updates = true;
conf.x, conf.y, conf.z, conf.pitch, conf.yaw, conf.roll = 0;
conf.cam_exposure = -1;
conf.cam_gain = -1;
Expand Down Expand Up @@ -55,6 +56,7 @@ void ConfigMgr::updateConfig(const ConfigData& data)
conf.setValue("cam_exposure", data.cam_exposure);
conf.setValue("cam_gain", data.cam_gain);
conf.setValue("selected_camera", data.selected_camera);
conf.setValue("autocheck_updates", data.autocheck_updates);
}

ConfigData ConfigMgr::getConfig()
Expand All @@ -74,6 +76,7 @@ ConfigData ConfigMgr::getConfig()
c.video_fps = conf.value("fps", 30).toInt();
c.cam_exposure= conf.value("cam_exposure", -1).toInt();
c.cam_gain = conf.value("cam_gain", -1).toInt();
c.autocheck_updates = conf.value("autocheck_updates", 1).toBool();
return c;
}

1 change: 1 addition & 0 deletions Client/src/model/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct ConfigData
double prior_pitch, prior_yaw, prior_distance;
bool show_video_feed;
bool use_landmark_stab;
bool autocheck_updates;

float x, y, z, yaw, pitch, roll;

Expand Down
52 changes: 52 additions & 0 deletions Client/src/model/UpdateChecker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "UpdateChecker.h"


#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <iostream>
#include <QObject>


UpdateChecker::UpdateChecker(std::string& version, IUpdateSub *obs):
request(),
manager(),
current_version(version)
{
this->observer = obs;
}

void UpdateChecker::callback(QNetworkReply* reply)
{
if (reply->error()) {
qDebug() << reply->errorString();
return;
}
QString answer = reply->readAll();
QJsonDocument doc = QJsonDocument::fromJson(answer.toUtf8());
QJsonArray json_array = doc.array();
QJsonObject latest_update = json_array[0].toObject();

Version v(latest_update["tag_name"].toString().toStdString());

qDebug() << latest_update["tag_name"].toString();

this->observer->on_update_check_completed((current_version < v));
}


void UpdateChecker::get_latest_update(std::string& repo)
{
QObject::connect(
&manager,
SIGNAL(finished(QNetworkReply*)),
this,
SLOT(callback(QNetworkReply*))
);

std::cout << " REQUEST "<<std::endl;

QString url = QString("https://api.github.com/repos/%1/releases").arg(QString::fromStdString(repo));
request.setUrl(QUrl(url));
manager.get(request);
}
86 changes: 86 additions & 0 deletions Client/src/model/UpdateChecker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#pragma once

#include <string>
#include <QNetworkAccessManager>
#include <QNetworkReply>


class Version
{
public:
int stage; // alpha, beta or normal
std::string ver;

Version(std::string version): ver(), stage(10)
{
int index_dash = -1;

for (int i = 0; i < version.size(); i++)
{
if (version.at(i) == *".")
continue;
if (version.at(i) == *"-")
{
index_dash = i;
break;
}
ver.push_back(version.at(i));
}

if (index_dash > 0)
{
// Version id contains alpha/beta
if (version.at(index_dash + 1) == *"a") // alpha
stage = 0;
if (version.at(index_dash + 1) == *"b") // beta
stage = 1;
// Else, its a normal version
}
};

bool operator<(Version const& rhs) const
{
int numbers_comparison = rhs.ver.compare(ver);
if (numbers_comparison == 0)
{
return stage < rhs.stage;
}
else
{
return numbers_comparison > 0;
}
}
};

class IUpdateSub
{
public:
/*
* Callback to check whether a newer version is available.
*/
virtual void on_update_check_completed(bool update_exists) = 0;
};



class UpdateChecker : public QObject
{
Q_OBJECT

private:
QNetworkRequest request;
QNetworkAccessManager manager;
IUpdateSub* observer;
Version current_version;

public:
UpdateChecker(std::string &version, IUpdateSub *obs);
void get_latest_update(std::string &repo);


private slots:
void callback(QNetworkReply* reply);
};



28 changes: 25 additions & 3 deletions Client/src/presenter/presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "../camera/CameraFactory.h"

#include "../version.h"


Presenter::Presenter(IView& view, std::unique_ptr<TrackerFactory>&& t_factory, std::unique_ptr<ConfigMgr>&& conf_mgr)
{
Expand Down Expand Up @@ -64,6 +66,14 @@ Presenter::Presenter(IView& view, std::unique_ptr<TrackerFactory>&& t_factory, s
this->view->set_enabled(false);
this->view->show_message("There was a problem initializing the tracker. Check the models folder and restart the program.", MSG_SEVERITY::CRITICAL);
}

if (state.autocheck_updates)
{
logger->info("Checking for updates");
update_chkr = std::make_unique<UpdateChecker>(std::string(AITRACK_VERSION), (IUpdateSub*)this);
update_chkr->get_latest_update(std::string("AIRLegend/aitrack"));
}

sync_ui_inputs();
}

Expand Down Expand Up @@ -192,9 +202,9 @@ void Presenter::run_loop()

void Presenter::update_tracking_data(FaceData& facedata)
{
this->state.x = facedata.translation[1] * 10;
this->state.y = facedata.translation[0] * 10;
this->state.z = facedata.translation[2] * 10;
this->state.x = facedata.translation[1];
this->state.y = facedata.translation[0];
this->state.z = facedata.translation[2];
this->state.yaw = facedata.rotation[1]; // Yaw
this->state.pitch = facedata.rotation[0]; //Pitch
this->state.roll = facedata.rotation[2]; //Roll
Expand Down Expand Up @@ -288,6 +298,7 @@ void Presenter::save_prefs(const ConfigData& data)
state.video_fps = data.video_fps;
state.video_height = data.video_height;
state.video_width = data.video_width;
state.autocheck_updates = data.autocheck_updates;

update_camera_params();

Expand Down Expand Up @@ -315,4 +326,15 @@ void Presenter::close_program()
// Assure all cameras are released (some cameras have a "recording LED" which can be annoying to have on)
for(std::shared_ptr<Camera> cam : all_cameras)
cam->stop_camera();
}


void Presenter::on_update_check_completed(bool update_exists)
{
if (update_exists)
{
this->view->show_message("New update available. Check https://github.com/AIRLegend/aitrack/releases", MSG_SEVERITY::NORMAL);
this->logger->info("New release has been found.");
}

}
Loading

0 comments on commit 7649c3c

Please sign in to comment.