-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunit_tests.cpp
56 lines (48 loc) · 1.98 KB
/
unit_tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "gtest/gtest.h"
#include "opencv2/opencv.hpp"
#include "harris_cpp.h"
#include "harris_opencl.h"
#include "harris_opencv.h"
#include "image.h"
using namespace harris;
Image<Argb32> LoadImage(std::string filename) {
cv::Mat mat = cv::imread(filename, cv::IMREAD_UNCHANGED);
return Image<Argb32>(mat.data, mat.cols, mat.rows, mat.step[0]);
}
void CheckCorners(const Image<float>& output) {
for(auto row = 0; row < output.height(); ++row) {
const auto output_row = output.RowPtr(row);
for(auto col = 0; col < output.width(); ++col) {
const auto output_pixel = output_row[col];
if (output_pixel > 0) {
ASSERT_GT(row, 400) << "At point (" << col << "," << row << "): Corners must all be in the lower right quadrant";
ASSERT_GT(col, 400) << "At point (" << col << "," << row << "): Corners must all be in the lower right quadrant";
ASSERT_EQ((row - 10) % 20, 0) << "At point (" << col << "," << row << "): Corners must align with odd multiples of 10";
ASSERT_EQ((col - 10) % 20, 0) << "At point (" << col << "," << row << "): Corners must align with odd multiples of 10";
} else {
ASSERT_FALSE(row > 400 && col > 400 && ((row - 10) % 20) == 0 && ((col - 10) % 20) == 0) << "At point (" << col << "," << row << "): There should be a point here";
}
}
}
}
// Tests pure C++ implementation
TEST(AlgorithmTest, Cpp) {
HarrisCpp harris;
auto input = LoadImage("lines.png");
auto output = harris.FindCorners(input);
CheckCorners(output);
}
// Tests pure C++ implementation
TEST(AlgorithmTest, OpenCL) {
HarrisOpenCL harris;
auto input = LoadImage("lines.png");
auto output = harris.FindCorners(input);
CheckCorners(output);
}
// Tests pure C++ implementation
TEST(AlgorithmTest, OpenCV) {
HarrisOpenCV harris;
auto input = LoadImage("lines.png");
auto output = harris.FindCorners(input);
CheckCorners(output);
}