Skip to content

Commit 0078f28

Browse files
authored
Merge pull request #25 from AIRLegend/dev
Bugfixing
2 parents 6840017 + b67d24c commit 0078f28

File tree

18 files changed

+150
-18
lines changed

18 files changed

+150
-18
lines changed

Client/Client.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
</Link>
174174
</ItemDefinitionGroup>
175175
<ItemGroup>
176+
<ClCompile Include="src\camera\CameraSettings.cpp" />
176177
<ClCompile Include="src\camera\NullCamera.cpp" />
177178
<ClCompile Include="src\camera\OCVCamera.cpp" />
178179
<ClCompile Include="src\camera\CameraFactory.cpp" />
@@ -195,6 +196,7 @@
195196
<QtUic Include="src\view\MainWindow.ui" />
196197
</ItemGroup>
197198
<ItemGroup>
199+
<ClInclude Include="src\camera\CameraSettings.h" />
198200
<ClInclude Include="src\camera\Camera.h" />
199201
<ClInclude Include="src\camera\NullCamera.h" />
200202
<ClInclude Include="src\camera\OCVCamera.h" />

Client/Client.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
<ClCompile Include="src\tracker\TrackerFactory.cpp">
2626
<Filter>Source Files</Filter>
2727
</ClCompile>
28+
<ClCompile Include="src\camera\CameraSettings.cpp">
29+
<Filter>Source Files</Filter>
30+
</ClCompile>
2831
</ItemGroup>
2932
<ItemGroup>
3033
<ClInclude Include="Include\ps3eye.h" />
@@ -61,6 +64,9 @@
6164
<ClInclude Include="src\tracker\TrackerFactory.h">
6265
<Filter>Header Files</Filter>
6366
</ClInclude>
67+
<ClInclude Include="src\camera\CameraSettings.h">
68+
<Filter>Header Files</Filter>
69+
</ClInclude>
6470
</ItemGroup>
6571
<ItemGroup>
6672
<QtMoc Include="src\view\WindowMain.h" />

Client/src/camera/Camera.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <cstdint>
4+
#include "CameraSettings.h"
45

56
class Camera
67
{
@@ -11,6 +12,8 @@ class Camera
1112
virtual void start_camera() = 0;
1213
virtual void stop_camera() = 0;
1314
virtual void get_frame(uint8_t* buffer) = 0;
15+
virtual void set_settings(CameraSettings& settings) = 0;
16+
virtual CameraSettings get_settings() = 0;
1417

1518
Camera(int width, int height, int fps) {
1619
this->width = width;

Client/src/camera/CameraFactory.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "OCVCamera.h"
55
#include "NullCamera.h"
66

7-
Camera* CameraFactory::buildCamera(int width, int height)
7+
Camera* CameraFactory::buildCamera(int width, int height, int exposure, int gain)
88
{
99
Camera *camera = NULL;
1010
bool error = false;
@@ -35,5 +35,10 @@ Camera* CameraFactory::buildCamera(int width, int height)
3535
camera = new NullCamera;
3636
}
3737

38+
CameraSettings cam_settings;
39+
cam_settings.exposure = exposure;
40+
cam_settings.gain = gain;
41+
camera->set_settings(cam_settings);
42+
3843
return camera;
3944
}

Client/src/camera/CameraFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
class CameraFactory
66
{
77
public:
8-
Camera* buildCamera(int width, int height);
8+
Camera* buildCamera(int width, int height, int exposure=-1, int gain=-1);
99
};
1010

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "CameraSettings.h"
2+
3+
4+
CameraSettings::CameraSettings()
5+
{
6+
exposure = -1;
7+
gain = -1;
8+
}
9+
10+
CameraSettings::CameraSettings(CameraSettings& settings)
11+
{
12+
exposure = settings.exposure;
13+
gain = settings.gain;
14+
}
15+
16+
CameraSettings::~CameraSettings()
17+
{}

Client/src/camera/CameraSettings.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
struct CameraSettings
4+
{
5+
int exposure;
6+
int gain;
7+
8+
CameraSettings();
9+
CameraSettings(CameraSettings& settings);
10+
~CameraSettings();
11+
};
12+

Client/src/camera/NullCamera.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ class NullCamera : public Camera
99
void start_camera() {};
1010
void stop_camera() {};
1111
void get_frame(uint8_t* buffer) {};
12+
void set_settings(CameraSettings& settings) {};
13+
CameraSettings get_settings() { return CameraSettings(); };
1214
};

Client/src/camera/OCVCamera.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
OCVCamera::OCVCamera(int width, int height, int fps) :
55
Camera(width, height, fps),
6-
size(width, height),
6+
size(0, 0),
77
cap()
88
{
99
CV_BACKEND = cv::CAP_DSHOW;
@@ -15,7 +15,8 @@ OCVCamera::OCVCamera(int width, int height, int fps) :
1515
throw std::runtime_error("No compatible camera found.");
1616
}
1717
is_valid = true;
18-
cap.set(cv::CAP_PROP_BUFFERSIZE, 1);
18+
19+
w_scale = (float)width/(float)cam_native_width;
1920
}
2021

2122
OCVCamera::~OCVCamera()
@@ -30,8 +31,10 @@ bool OCVCamera::is_camera_available()
3031
cap.open(0, CV_BACKEND);
3132
available = cap.isOpened();
3233
if (available)
34+
{
35+
cam_native_width = cap.get(cv::CAP_PROP_FRAME_WIDTH);
3336
cap.release();
34-
37+
}
3538
return available;
3639
}
3740

@@ -53,9 +56,22 @@ void OCVCamera::get_frame(uint8_t* buffer)
5356
{
5457
cv::Mat frame;
5558
cap.read(frame);
56-
cv::resize(frame, frame, size);
59+
//Scale maintaining aspect ratio. If distorted, the model will get confused.
60+
//TODO: Maybe cropping (width,height) section from the center is better.
61+
//cv::resize(frame, frame, size, w_scale, w_scale);
62+
cv::resize(frame, frame, size, w_scale, w_scale);
5763
cv::flip(frame, frame, 1);
5864
for (int i = 0; i < frame.cols * frame.rows * 3; i++)
5965
buffer[i] = frame.data[i];
6066

6167
}
68+
69+
void OCVCamera::set_settings(CameraSettings& settings)
70+
{
71+
//TODO
72+
}
73+
74+
CameraSettings OCVCamera::get_settings()
75+
{
76+
return CameraSettings();
77+
}

Client/src/camera/OCVCamera.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class OCVCamera : public Camera
77
private:
88
cv::VideoCapture cap;
99
cv::Size size;
10+
float w_scale;
11+
int cam_native_width;
1012
int CV_BACKEND;
1113

1214
bool is_camera_available();
@@ -17,5 +19,7 @@ class OCVCamera : public Camera
1719
void start_camera();
1820
void stop_camera();
1921
void get_frame(uint8_t* buffer);
22+
void set_settings(CameraSettings& settings);
23+
CameraSettings get_settings();
2024
};
2125

0 commit comments

Comments
 (0)