Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

Commit 99271e8

Browse files
author
Chris Hajduk
committed
Merged Conflicts
2 parents 33df7f8 + 7757b89 commit 99271e8

16 files changed

Lines changed: 419 additions & 26 deletions

main.cpp

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "metadata_input.h"
5555
#include "metadata_reader.h"
5656
#include "target.h"
57+
#include "camera.h"
5758

5859
using namespace std;
5960
using namespace boost;
@@ -87,6 +88,72 @@ MetadataInput *logReader = new MetadataInput();
8788
double aveFrameTime = 1000;
8889
int frameCount = 0;
8990

91+
double fisheyeMatrix[] = {
92+
2.4052826789763981e+03, 0, 2000,
93+
0, 2.4052826789763981e+03, 1500,
94+
0, 0, 1
95+
};
96+
97+
double fisheyeDistortion[] = {
98+
-0.392, 0.146, 0, 0, -0.023
99+
};
100+
101+
double newFisheyeMatrix[] = {
102+
2000, 0, 2000,
103+
0, 2000, 1500,
104+
0, 0, 1
105+
};
106+
107+
double rectMatrix[] = {
108+
2410, 0, 960,
109+
0, 2410, 540,
110+
0, 0, 1
111+
};
112+
113+
double rectDistortion[] = {
114+
0, 0, 0, 0, 0
115+
};
116+
117+
Camera goProFisheye(
118+
Size(4000, 3000),
119+
Size2d(120, 90),
120+
Mat(
121+
Size(3, 3),
122+
CV_64F,
123+
fisheyeMatrix
124+
),
125+
Mat(
126+
Size(5, 1),
127+
CV_64F,
128+
fisheyeDistortion
129+
),
130+
Mat(
131+
Size(3, 3),
132+
CV_64F,
133+
newFisheyeMatrix
134+
)
135+
);
136+
137+
Camera goProRect(
138+
Size(1920, 1080),
139+
Size2d(90, 67.5),
140+
Mat(
141+
Size(3, 3),
142+
CV_64F,
143+
rectMatrix
144+
),
145+
Mat(
146+
Size(5, 1),
147+
CV_64F,
148+
rectDistortion
149+
),
150+
Mat(
151+
Size(3, 3),
152+
CV_64F,
153+
rectMatrix
154+
)
155+
);
156+
90157
struct State {
91158
bool hasImageSource;
92159
bool hasMetadataSource;
@@ -149,7 +216,6 @@ void output() {
149216
}
150217
boost::this_thread::sleep(boost::posix_time::milliseconds(30));
151218
}
152-
ioService.stop();
153219
}
154220

155221
void init() {
@@ -171,7 +237,7 @@ int main(int argc, char** argv) {
171237
processors = boost::thread::hardware_concurrency();
172238

173239
while (!cin.eof()) handle_input();
174-
240+
ioService.stop();
175241
threadpool.join_all();
176242
delete logReader;
177243
return 0;
@@ -246,7 +312,7 @@ vector<Command> commands = {
246312
if (logReader->num_sources() == 0) {
247313
BOOST_LOG_TRIVIAL(error) << "Cannot add image source until a metadata source has been specified";
248314
} else {
249-
importer.add_source(new PictureImport(args[0], logReader), stol(args[1]));
315+
importer.add_source(new PictureImport(args[0], logReader, goProFisheye), stol(args[1]));
250316
newState.hasImageSource = true;
251317
}
252318
}),
@@ -255,7 +321,7 @@ vector<Command> commands = {
255321
if (logReader->num_sources() == 0) {
256322
BOOST_LOG_TRIVIAL(error) << "Cannot add image source until a metadata source has been specified";
257323
} else {
258-
importer.add_source(new DeckLinkImport(logReader), stol(args[0]));
324+
importer.add_source(new DeckLinkImport(logReader, goProRect), stol(args[0]));
259325
newState.hasImageSource = true;
260326
}
261327
}),
@@ -272,7 +338,9 @@ vector<Command> commands = {
272338
void handle_state_change(State &newState) {
273339
if (!currentState.readingImages && newState.readingImages) {
274340
if (newState.hasImageSource && newState.hasMetadataSource) {
341+
currentState.readingImages = true;
275342
queue_work(assign_workers);
343+
queue_work(output);
276344
} else {
277345
BOOST_LOG_TRIVIAL(error) << "Trying to read images without both image and metadata source is not supported";
278346
}
@@ -340,25 +408,29 @@ int handle_args(int argc, char** argv) {
340408

341409
if (vm.count("telemetry")) {
342410
logReader->add_source(new MetadataReader(*logReader, vm["telemetry"].as<string>()));
343-
currentState.hasMetadataSource = true;
411+
newState.hasMetadataSource = true;
412+
cout << "Adding Telemetry source..." << endl;
344413
}
345414

346415
if (vm.count("addr") && vm.count("port")) {
347416
logReader->add_source(new MetadataReader(*logReader, vm["addr"].as<string>(), vm["port"].as<string>()));
348417
newState.hasMetadataSource = true;
418+
cout << "Adding Telemetry source..." << endl;
349419
}
350420

351421
#ifdef HAS_DECKLINK
352422
if (vm.count("decklink")) {
353-
importer.add_source(new DeckLinkImport(logReader), 500);
423+
importer.add_source(new DeckLinkImport(logReader, goProRect), 500);
354424
newState.hasImageSource = true;
425+
cout << "Adding video source..." << endl;
355426
}
356427
#endif // HAS_DECKLINK
357428

358429
if (vm.count("images")) {
359430
string path = vm["images"].as<string>();
360-
importer.add_source(new PictureImport(path, logReader), 0);
431+
importer.add_source(new PictureImport(path, logReader, goProFisheye), 0);
361432
newState.hasImageSource = true;
433+
cout << "Adding picture source..." << endl;
362434
}
363435

364436
if (vm.count("output")) {

modules/core/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
include_directories(include ${EXIV2_INCLUDE_DIR})
2-
add_library(Core src/target.cpp src/object.cpp src/pixel_object.cpp src/frame.cpp src/benchmark.cpp)
2+
add_library(Core src/target.cpp src/object.cpp src/pixel_object.cpp src/frame.cpp src/benchmark.cpp src/camera.cpp)
33
target_link_libraries(Core ${EXIV2_LIBRARIES} ${OpenCV_LIBS})

modules/core/include/camera.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* @file camera.h
3+
* @author WARG
4+
*
5+
* @section LICENSE
6+
*
7+
* Copyright (c) 2015, Waterloo Aerial Robotics Group (WARG)
8+
* All rights reserved.
9+
*
10+
* This software is licensed under a modified version of the BSD 3 clause license
11+
* that should have been included with this software in a file called COPYING.txt
12+
* Otherwise it is available at:
13+
* https://raw.githubusercontent.com/UWARG/computer-vision/master/COPYING.txt
14+
*/
15+
16+
17+
#ifndef CAMERA_H_INCLUDED
18+
#define CAMERA_H_INCLUDED
19+
20+
/**
21+
* @class Camera
22+
*
23+
* @brief Container class for storing information about
24+
* the camera used to capture an image *
25+
*/
26+
27+
28+
class Camera {
29+
public:
30+
/**
31+
* @brief creates a Camera representing the specs for a given lens and sensor
32+
*
33+
* @param imageSize Size of the camera image
34+
* @param fov The field of view of the camera
35+
* @param cameraMatrix OpenCV camera calibration matrix giving focal length and principal point
36+
* @param distortionCoeffs OpenCV distortion coefficients used for undistorting images
37+
*/
38+
Camera(cv::Size imageSize, cv::Size2d fov, cv::Mat cameraMatrix, cv::Mat distortionCoeffs, cv::Mat newCameraMatrix);
39+
40+
/**
41+
* @brief Returns the field of view of the camera in degrees for both horizontal and vertical dimensions
42+
*/
43+
cv::Size2d get_fov();
44+
45+
/**
46+
* @brief Undistorts image
47+
* @param img mat to be undistorted
48+
* @return An orthorectified version of the given mat
49+
*/
50+
cv::Mat * undistort(cv::Mat &img);
51+
52+
/**
53+
* @brief Example Camera for testing purposes
54+
*/
55+
static Camera TestCamera();
56+
57+
private:
58+
cv::Size2d fov;
59+
cv::Mat cameraMatrix;
60+
cv::Mat distortionCoeffs;
61+
cv::Mat newCameraMatrix;
62+
};
63+
64+
#endif //CAMERA_H_INCLUDED

modules/core/include/frame.h

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
#include <opencv2/core/core.hpp>
2525
#include "metadata.h"
2626
#include <vector>
27+
#include "camera.h"
2728

2829
class PixelObject;
2930

3031
class Frame{
3132
public:
32-
Frame(cv::Mat * img, std::string id, Metadata m);
33-
33+
Frame(cv::Mat * img, std::string id, Metadata m, Camera &camera);
34+
35+
~Frame();
3436
/**
3537
* @brief
3638
*
@@ -43,7 +45,13 @@ class Frame{
4345
*
4446
* @return image associated with the frame
4547
*/
46-
cv::Mat & get_img();
48+
cv::Mat & get_img();
49+
50+
/**
51+
* @brief Original Image
52+
* @return original image before any calibration
53+
*/
54+
cv::Mat & orig_img();
4755

4856
/**
4957
* @brief Adds given object to the list of objects in the frame
@@ -97,13 +105,26 @@ class Frame{
97105
*/
98106
void set_pixel_distance(double x, double y);
99107

108+
/*
109+
* @brief returns a new undistorted image using the given camera
110+
* Intended for testing purposes, Does not modify the Frame.
111+
* @param camera the camera to use for undistortion
112+
* @return A new image that is the original image contained in this frame undistorted with the camera
113+
*/
114+
cv::Mat* undistort(Camera &camera);
115+
100116
private:
101117

102118
/**
103119
* @brief image associated with the Frame
104120
*/
105121
cv::Mat * img;
106122

123+
/**
124+
* @brief original image without undistortion
125+
*/
126+
cv::Mat * origImg;
127+
107128
/**
108129
* @brief Timestamp for the frame
109130
*/
@@ -119,11 +140,18 @@ class Frame{
119140
*/
120141
std::vector<PixelObject *> objects;
121142

143+
<<<<<<< HEAD
122144
/**
123145
* @brief Distance of each pixel covers in the x and y direction with
124146
* componesation for altitude, camera lens, etc.
125147
*/
126148
cv::Point2d pixel_distance;
149+
=======
150+
/*
151+
* @brief Camera used to capture the frame
152+
*/
153+
Camera &camera;
154+
>>>>>>> 7757b8909d05a2df51e4b260f0cf9b37010ecbba
127155
};
128156

129157

modules/core/src/camera.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* @file camera.h
3+
* @author WARG
4+
*
5+
* @section LICENSE
6+
*
7+
* Copyright (c) 2015, Waterloo Aerial Robotics Group (WARG)
8+
* All rights reserved.
9+
*
10+
* This software is licensed under a modified version of the BSD 3 clause license
11+
* that should have been included with this software in a file called COPYING.txt
12+
* Otherwise it is available at:
13+
* https://raw.githubusercontent.com/UWARG/computer-vision/master/COPYING.txt
14+
*/
15+
16+
#include <opencv2/calib3d.hpp>
17+
#include <opencv2/imgproc.hpp>
18+
#include <opencv2/core/core.hpp>
19+
#include "camera.h"
20+
21+
using namespace cv;
22+
23+
Camera::Camera(Size imageSize, Size2d fov, Mat cameraMatrix, Mat distortionCoeffs, Mat newCameraMatrix = Mat())
24+
: cameraMatrix(cameraMatrix), distortionCoeffs(distortionCoeffs), newCameraMatrix(newCameraMatrix), fov(fov) {
25+
}
26+
27+
Mat * Camera::undistort(Mat & img) {
28+
Mat *tmp = new Mat();
29+
cv::undistort(img, *tmp, cameraMatrix, distortionCoeffs, newCameraMatrix);
30+
return tmp;
31+
}
32+
33+
Camera Camera::TestCamera() {
34+
double cameraMatrix[] = {
35+
2.4052826789763981e+03, 0, 2000,
36+
0, 2.4052826789763981e+03, 1500,
37+
0, 0, 1
38+
};
39+
40+
double distMatrix[] = {
41+
6.0190515380007324e-02, -1.8618345553370965e+00, 0, 0,
42+
2.9590336363673964e+00
43+
};
44+
45+
return Camera(
46+
Size(4000, 3000),
47+
Size2d(120, 90),
48+
Mat(
49+
Size(3, 3),
50+
CV_8UC1,
51+
cameraMatrix
52+
),
53+
Mat(
54+
Size(5, 1),
55+
CV_8UC1,
56+
distMatrix
57+
)
58+
);
59+
}
60+
61+
Size2d Camera::get_fov() {
62+
return fov;
63+
}

0 commit comments

Comments
 (0)