Skip to content

Commit 7649c3c

Browse files
authored
Merge pull request #51 from AIRLegend/dev
Dev
2 parents d36ecca + 3e0ce44 commit 7649c3c

19 files changed

+262
-29
lines changed

AITracker/src/PositionSolver.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ void PositionSolver::solve_rotation(FaceData* face_data)
9090
for (int i = 0; i < 3; i++)
9191
{
9292
face_data->rotation[i] = rvec.at<double>(i, 0);
93-
face_data->translation[i] = tvec.at<double>(i, 0);
93+
face_data->translation[i] = tvec.at<double>(i, 0) * 10;
9494
}
9595

96+
correct_rotation(*face_data);
97+
9698
}
9799

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

136138
}
137139

140+
void PositionSolver::correct_rotation(FaceData& face_data)
141+
{
142+
float distance = -(face_data.translation[2]);
143+
float lateral_offset = face_data.translation[1];
144+
float verical_offset = face_data.translation[0];
145+
146+
float correction_yaw = std::atan(std::tan(lateral_offset / distance)) * TO_DEG;
147+
float correction_pitch = std::atan(std::tan(verical_offset / distance)) * TO_DEG;
148+
149+
face_data.rotation[1] += correction_yaw;
150+
face_data.rotation[0] += correction_pitch;
151+
}
152+

AITracker/src/PositionSolver.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class PositionSolver
3333

3434
private:
3535
static const int NB_CONTOUR_POINTS = 18;
36+
const double TO_DEG = (180.0 / 3.14159265);
3637

3738
cv::Mat mat3dface;
3839
cv::Mat mat3dcontour;
@@ -52,5 +53,11 @@ class PositionSolver
5253
Gets euler angles from rotation matrix.
5354
*/
5455
void get_euler(cv::Mat& rvec, cv::Mat& tvec);
56+
57+
/**
58+
* Lateral/Vertical offset adds an error to the calculated rotation.
59+
* This method corrects them.
60+
*/
61+
void correct_rotation(FaceData& face_data);
5562
};
5663

Client/Client.vcxproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
</ItemDefinitionGroup>
114114
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
115115
<QtInstall>$(QTDIR)</QtInstall>
116-
<QtModules>core;uitools;widgets;quick</QtModules>
116+
<QtModules>core;uitools;widgets;quick;</QtModules>
117117
<QtBuildConfig>debug</QtBuildConfig>
118118
<QtLibrarySearchPath>$(QTDIR)\lib;$(QtLibrarySearchPath)</QtLibrarySearchPath>
119119
<QtHeaderSearchPath>$(QTDIR)\include</QtHeaderSearchPath>
@@ -179,6 +179,7 @@
179179
<ClCompile Include="src\camera\CameraFactory.cpp" />
180180
<ClCompile Include="src\model\Config.cpp" />
181181
<ClCompile Include="src\camera\Ps3Camera.cpp" />
182+
<ClCompile Include="src\model\UpdateChecker.cpp" />
182183
<ClCompile Include="src\presenter\presenter.cpp" />
183184
<ClCompile Include="src\Main.cpp" />
184185
<ClCompile Include="src\model\UDPSender.cpp" />
@@ -200,8 +201,10 @@
200201
<ClInclude Include="src\camera\CameraFactory.h" />
201202
<ClInclude Include="Include\ps3eye.h" />
202203
<ClInclude Include="resource.h" />
204+
<ClInclude Include="src\version.h" />
203205
<ClInclude Include="src\model\Config.h" />
204206
<ClInclude Include="src\camera\Ps3Camera.h" />
207+
<QtMoc Include="src\model\UpdateChecker.h" />
205208
<ClInclude Include="src\presenter\i_presenter.h" />
206209
<ClInclude Include="src\presenter\presenter.h" />
207210
<ClInclude Include="src\model\UDPSender.h" />

Client/Client.vcxproj.filters

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<ClCompile Include="src\view\ConfigWindow.cpp">
3131
<Filter>Source Files</Filter>
3232
</ClCompile>
33+
<ClCompile Include="src\model\UpdateChecker.cpp">
34+
<Filter>Source Files</Filter>
35+
</ClCompile>
3336
</ItemGroup>
3437
<ItemGroup>
3538
<ClInclude Include="Include\ps3eye.h" />
@@ -68,12 +71,18 @@
6871
<ClInclude Include="src\camera\CameraSettings.h">
6972
<Filter>Header Files</Filter>
7073
</ClInclude>
74+
<ClInclude Include="src\version.h">
75+
<Filter>Header Files</Filter>
76+
</ClInclude>
7177
</ItemGroup>
7278
<ItemGroup>
7379
<QtMoc Include="src\view\WindowMain.h" />
7480
<QtMoc Include="src\view\ConfigWindow.h">
7581
<Filter>Header Files</Filter>
7682
</QtMoc>
83+
<QtMoc Include="src\model\UpdateChecker.h">
84+
<Filter>Header Files</Filter>
85+
</QtMoc>
7786
</ItemGroup>
7887
<ItemGroup>
7988
<QtRcc Include="res\Resource.qrc">

Client/src/Main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include "spdlog/sinks/basic_file_sink.h"
1515

1616

17+
#include "model/UpdateChecker.h"
18+
19+
20+
1721
int main(int argc, char *argv[])
1822
{
1923

Client/src/camera/OCVCamera.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ OCVCamera::OCVCamera(int width, int height, int fps, int index) :
2727
if (fps < 0)
2828
this->fps = cam_native_fps;
2929

30-
31-
cap.set(cv::CAP_PROP_FRAME_WIDTH, this->width);
32-
cap.set(cv::CAP_PROP_FRAME_HEIGHT, this->height);
33-
cap.set(cv::CAP_PROP_FPS, this->fps);
34-
3530
exposure, gain = -1;
3631
}
3732

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

5651
cam_native_width = (int)cap.get(cv::CAP_PROP_FRAME_WIDTH);
5752
cam_native_height = (int)cap.get(cv::CAP_PROP_FRAME_HEIGHT);
58-
cam_native_fps = (int)cap.get(cv::CAP_PROP_FPS);
53+
cam_native_fps = std::max(30, (int)cap.get(cv::CAP_PROP_FPS));
5954
cap.release();
6055
}
6156
return available;
@@ -68,6 +63,13 @@ void OCVCamera::start_camera()
6863
{
6964
throw std::runtime_error("No compatible camera found.");
7065
}
66+
67+
// Force its properties each time we start the camera
68+
// because if we force them with the device switched off
69+
// bugs will occur (tiling, for example).
70+
cap.set(cv::CAP_PROP_FRAME_WIDTH, this->width);
71+
cap.set(cv::CAP_PROP_FRAME_HEIGHT, this->height);
72+
cap.set(cv::CAP_PROP_FPS, this->fps);
7173
}
7274

7375
void OCVCamera::stop_camera()
@@ -89,7 +91,7 @@ void OCVCamera::set_settings(CameraSettings& settings)
8991
{
9092
this->width = settings.width > 0 ? settings.width : this->cam_native_width;
9193
this->height = settings.height > 0 ? settings.height : this->cam_native_height;
92-
this->fps = settings.fps > 0 ? settings.fps : this->cam_native_fps;
94+
this->fps = settings.fps >= 30 ? settings.fps : this->cam_native_fps;
9395

9496
// Disabled for the moment because of the different ranges in generic cameras.
9597
//exposure = settings.exposure < 0 ? -1.0F : (float)settings.exposure/255;

Client/src/model/Config.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ConfigData ConfigData::getGenericConfig()
2020
conf.video_height = -1;
2121
conf.video_fps = -1;
2222
conf.use_landmark_stab = true;
23+
conf.autocheck_updates = true;
2324
conf.x, conf.y, conf.z, conf.pitch, conf.yaw, conf.roll = 0;
2425
conf.cam_exposure = -1;
2526
conf.cam_gain = -1;
@@ -55,6 +56,7 @@ void ConfigMgr::updateConfig(const ConfigData& data)
5556
conf.setValue("cam_exposure", data.cam_exposure);
5657
conf.setValue("cam_gain", data.cam_gain);
5758
conf.setValue("selected_camera", data.selected_camera);
59+
conf.setValue("autocheck_updates", data.autocheck_updates);
5860
}
5961

6062
ConfigData ConfigMgr::getConfig()
@@ -74,6 +76,7 @@ ConfigData ConfigMgr::getConfig()
7476
c.video_fps = conf.value("fps", 30).toInt();
7577
c.cam_exposure= conf.value("cam_exposure", -1).toInt();
7678
c.cam_gain = conf.value("cam_gain", -1).toInt();
79+
c.autocheck_updates = conf.value("autocheck_updates", 1).toBool();
7780
return c;
7881
}
7982

Client/src/model/Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct ConfigData
1818
double prior_pitch, prior_yaw, prior_distance;
1919
bool show_video_feed;
2020
bool use_landmark_stab;
21+
bool autocheck_updates;
2122

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

Client/src/model/UpdateChecker.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "UpdateChecker.h"
2+
3+
4+
#include <QJsonDocument>
5+
#include <QJsonObject>
6+
#include <QJsonArray>
7+
#include <iostream>
8+
#include <QObject>
9+
10+
11+
UpdateChecker::UpdateChecker(std::string& version, IUpdateSub *obs):
12+
request(),
13+
manager(),
14+
current_version(version)
15+
{
16+
this->observer = obs;
17+
}
18+
19+
void UpdateChecker::callback(QNetworkReply* reply)
20+
{
21+
if (reply->error()) {
22+
qDebug() << reply->errorString();
23+
return;
24+
}
25+
QString answer = reply->readAll();
26+
QJsonDocument doc = QJsonDocument::fromJson(answer.toUtf8());
27+
QJsonArray json_array = doc.array();
28+
QJsonObject latest_update = json_array[0].toObject();
29+
30+
Version v(latest_update["tag_name"].toString().toStdString());
31+
32+
qDebug() << latest_update["tag_name"].toString();
33+
34+
this->observer->on_update_check_completed((current_version < v));
35+
}
36+
37+
38+
void UpdateChecker::get_latest_update(std::string& repo)
39+
{
40+
QObject::connect(
41+
&manager,
42+
SIGNAL(finished(QNetworkReply*)),
43+
this,
44+
SLOT(callback(QNetworkReply*))
45+
);
46+
47+
std::cout << " REQUEST "<<std::endl;
48+
49+
QString url = QString("https://api.github.com/repos/%1/releases").arg(QString::fromStdString(repo));
50+
request.setUrl(QUrl(url));
51+
manager.get(request);
52+
}

Client/src/model/UpdateChecker.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <QNetworkAccessManager>
5+
#include <QNetworkReply>
6+
7+
8+
class Version
9+
{
10+
public:
11+
int stage; // alpha, beta or normal
12+
std::string ver;
13+
14+
Version(std::string version): ver(), stage(10)
15+
{
16+
int index_dash = -1;
17+
18+
for (int i = 0; i < version.size(); i++)
19+
{
20+
if (version.at(i) == *".")
21+
continue;
22+
if (version.at(i) == *"-")
23+
{
24+
index_dash = i;
25+
break;
26+
}
27+
ver.push_back(version.at(i));
28+
}
29+
30+
if (index_dash > 0)
31+
{
32+
// Version id contains alpha/beta
33+
if (version.at(index_dash + 1) == *"a") // alpha
34+
stage = 0;
35+
if (version.at(index_dash + 1) == *"b") // beta
36+
stage = 1;
37+
// Else, its a normal version
38+
}
39+
};
40+
41+
bool operator<(Version const& rhs) const
42+
{
43+
int numbers_comparison = rhs.ver.compare(ver);
44+
if (numbers_comparison == 0)
45+
{
46+
return stage < rhs.stage;
47+
}
48+
else
49+
{
50+
return numbers_comparison > 0;
51+
}
52+
}
53+
};
54+
55+
class IUpdateSub
56+
{
57+
public:
58+
/*
59+
* Callback to check whether a newer version is available.
60+
*/
61+
virtual void on_update_check_completed(bool update_exists) = 0;
62+
};
63+
64+
65+
66+
class UpdateChecker : public QObject
67+
{
68+
Q_OBJECT
69+
70+
private:
71+
QNetworkRequest request;
72+
QNetworkAccessManager manager;
73+
IUpdateSub* observer;
74+
Version current_version;
75+
76+
public:
77+
UpdateChecker(std::string &version, IUpdateSub *obs);
78+
void get_latest_update(std::string &repo);
79+
80+
81+
private slots:
82+
void callback(QNetworkReply* reply);
83+
};
84+
85+
86+

0 commit comments

Comments
 (0)