-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathclassified.cpp
More file actions
132 lines (112 loc) · 4.76 KB
/
classified.cpp
File metadata and controls
132 lines (112 loc) · 4.76 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Copyright (C) 2017-2020 Trent Houliston <trent@houliston.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <array>
#include <iostream>
#include <map>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <string>
#include <vector>
#include "Timer.hpp"
#include "dataset.hpp"
#include "draw.hpp"
#include "load_model.hpp"
#include "visualmesh/engine/cpu/engine.hpp"
#include "visualmesh/engine/opencl/engine.hpp"
#include "visualmesh/engine/vulkan/engine.hpp"
#include "visualmesh/geometry/Sphere.hpp"
#include "visualmesh/model/ring6.hpp"
#include "visualmesh/utility/fourcc.hpp"
#include "visualmesh/visualmesh.hpp"
template <typename Scalar>
using Model = visualmesh::model::Ring6<Scalar>;
using Scalar = float;
// NOLINTNEXTLINE(bugprone-exception-escape) This is debugging code, I would prefer exceptions crash the program
int main() {
// Input image path
std::string image_path = "../example/images";
std::string model_path = "../example/model.yaml";
std::vector<cv::Scalar> colours = {
// Ball
cv::Scalar(0, 0, 255),
// Goal
cv::Scalar(0, 255, 255),
// Field Line
cv::Scalar(255, 255, 255),
// Field
cv::Scalar(0, 255, 0),
// Unclassified
cv::Scalar(0, 0, 0),
};
// Create the window to show the images
cv::namedWindow("Image", cv::WINDOW_AUTOSIZE);
// Time how long each stage takes
Timer t;
// Build our classification network
visualmesh::NetworkStructure<Scalar> network = load_model<Scalar>(model_path);
t.measure("Loaded network from YAML file");
visualmesh::geometry::Sphere<Scalar> sphere(0.0949996);
visualmesh::VisualMesh<Scalar, Model> mesh(sphere, 0.5, 1.5, 6, 0.5, 20);
t.measure("Built Visual Mesh");
visualmesh::engine::cpu::Engine<Scalar> cpu_engine(network);
t.measure("Loaded CPU Engine");
#if !defined(VISUALMESH_DISABLE_OPENCL)
visualmesh::engine::opencl::Engine<Scalar> cl_engine(network);
t.measure("Loaded OpenCL Engine");
#endif // !defined(VISUALMESH_DISABLE_OPENCL)
#if !defined(VISUALMESH_DISABLE_VULKAN)
visualmesh::engine::vulkan::Engine<Scalar, false> vk_engine(network);
t.measure("Loaded Vulkan Engine");
#endif // !defined(VISUALMESH_DISABLE_VULKAN)
auto dataset = load_dataset<Scalar>(image_path);
t.measure("Loaded dataset");
// Go through all our training data
std::cerr << "Looping through training data" << std::endl;
for (const auto& element : dataset) {
std::cerr << "Processing file " << element.number << std::endl;
Timer t;
// Run the classifiers
#if !defined(VISUALMESH_DISABLE_OPENCL)
{
t.reset();
auto classified =
cl_engine(mesh, element.Hoc, element.lens, element.image.data, visualmesh::fourcc("BGRA"));
t.measure("\tOpenCL Classified Mesh");
draw("Image", element.image, classified, colours);
if (char(cv::waitKey(0)) == 27) { break; }
}
#endif // !defined(VISUALMESH_DISABLE_OPENCL)
#if !defined(VISUALMESH_DISABLE_VULKAN)
{
t.reset();
auto classified =
vk_engine(mesh, element.Hoc, element.lens, element.image.data, visualmesh::fourcc("BGRA"));
t.measure("\tVulkan Classified Mesh");
draw("Image", element.image, classified, colours);
if (char(cv::waitKey(0)) == 27) break;
}
#endif // !defined(VISUALMESH_DISABLE_VULKAN)
{
t.reset();
auto classified =
cpu_engine(mesh, element.Hoc, element.lens, element.image.data, visualmesh::fourcc("BGRA"));
t.measure("\tCPU Classified Mesh");
draw("Image", element.image, classified, colours);
if (char(cv::waitKey(0)) == 27) { break; }
}
}
}