Repository navigation
Expand file tree
/
Copy pathassets.cpp
More file actions
235 lines (176 loc) · 6.57 KB
/
Copy pathassets.cpp
File metadata and controls
235 lines (176 loc) · 6.57 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
//
// Created by Louis Krämer on 26.09.25.
//
#include "processor.h"
cv::VideoCapture Processor::in_video(const std::string& video_path)
{
if (!std::filesystem::exists(video_path)) {
std::cerr << "Datei nicht gefunden: " << video_path << "\n";
return {};
}
cv::VideoCapture in_video(video_path, cv::CAP_ANY);
in_video.release();
if (in_video.open(video_path, cv::CAP_AVFOUNDATION) && in_video.isOpened()) {
std::cout << "Backend: " << in_video.getBackendName() << "\n";
return in_video;
}
std::cerr << "Konnte Video nicht öffnen: " << video_path << "\n";
return {};
}
void Processor::initializeBalls()
{
this->blue_ball.name = "blue";
this->green_ball.name = "green";
this->red_ball.name = "red";
const float triangle_length = DISTANCE_BETWEEN_BALL;
const float left = -triangle_length / 2;
const float right = triangle_length / 2;
const float triangle_height = triangle_length * std::sqrt(3) / 2;
const float bottom = camera_position.PEN_HEIGHT - triangle_height / 3;
const float top = camera_position.PEN_HEIGHT + triangle_height * 2 / 3;
this->blue_ball.id = 0;
this->blue_ball.x = left;
this->blue_ball.y = bottom;
this->blue_ball.z = 0;
this->blue_ball.color = cv::Scalar(255, 0, 0);
this->green_ball.id = 1;
this->green_ball.x = right;
this->green_ball.y = bottom;
this->green_ball.z = 0;
this->green_ball.color = cv::Scalar(0,255,0);
this->red_ball.id = 2;
this->red_ball.x = 0;
this->red_ball.y = top;
this->red_ball.z = 0;
this->red_ball.color = cv::Scalar(0,0,255);
}
void Processor::draw_to_screen(cv::Mat& out, std::vector<cv::Point2d>& drawPoints)
{
crossing_point(out, drawPoints);
std::vector<cv::Point> pts;
pts.reserve(drawPoints.size());
for (const auto& p : drawPoints)
pts.emplace_back(cvRound(p.x), cvRound(p.y));
cv::polylines(
out,
std::vector<std::vector<cv::Point>>{pts},
false,
cv::Scalar(255,255,255),
2,
cv::LINE_AA
);
}
void Processor::draw_line(cv::Mat& img, cv::Point2f p1, cv::Point2f p2, cv::Scalar color = cv::Scalar(255,255,255))
{
cv::line(img,
cv::Point(cvRound(p1.x), cvRound(p1.y)),
cv::Point(cvRound(p2.x), cvRound(p2.y)),
color , 1, cv::LINE_AA);
}
void Processor::m_display_info(cv::Mat& frame, cv::Mat& out)
{
cv::Point2f blue_middle(this->blue_ball.middle.first,this->blue_ball.middle.second);
cv::Point2f green_middle(this->green_ball.middle.first, this->green_ball.middle.second);
cv::Point2f blue_green_center = middle_two_vek(blue_middle, green_middle);
cv::Point2f target = target_vek(blue_ball, blue_middle, green_middle);
draw_line(out, blue_middle, green_middle);
// draw_line(out, blue_green_center, target);
double len_blue_green = vektor_length(blue_middle, green_middle);
double delta_blue = this->blue_ball.distances - this->camera_position.initial_blue_radii;
// Make Point for Middle Point in the Frame
const std::string label = cv::format("Red radii: %.6f Green radii: %.6f Blue radii: %.6f Delta Blue %.6f",
this->red_ball.distances, this->green_ball.distances, this->blue_ball.distances, delta_blue);
int baseline = 0;
const int fontFace = cv::FONT_HERSHEY_SIMPLEX;
const double fontScale = 0.6;
const int thickness = 1;
cv::Size sz = cv::getTextSize(label, fontFace, fontScale, thickness, &baseline);
cv::Rect bg(10, 10, sz.width + 12, sz.height + baseline + 10);
cv::circle(
out,
{static_cast<int>(blue_green_center.x), static_cast<int>(blue_green_center.y)},
3, cv::Scalar(255,255,255),
cv::FILLED,
cv::LINE_AA
);
cv::circle(
out,
{static_cast<int>(this->blue_ball.middle.first), static_cast<int>(this->blue_ball.middle.second)},
static_cast<int>(this->blue_ball.distances), cv::Scalar(255,255,255),
1,
cv::LINE_AA);
cv::circle(
out,
{static_cast<int>(this->green_ball.middle.first), static_cast<int>(this->green_ball.middle.second)},
static_cast<int>(this->green_ball.distances), cv::Scalar(255,255,255),
1,
cv::LINE_AA);
cv::circle(
frame,
{static_cast<int>(this->red_ball.middle.first), static_cast<int>(this->red_ball.middle.second)},
5, cv::Scalar(255,255,255),
cv::FILLED,
cv::LINE_AA);
cv::rectangle(out, bg, cv::Scalar(255, 255, 255), cv::FILLED);
cv::putText(out, label,
cv::Point(bg.x + 6, bg.y + 6 + sz.height),
fontFace, fontScale, cv::Scalar(0, 0, 0), thickness, cv::LINE_AA);
//draw_line(blue_ball, out);
//draw_line(green_ball, out);
// draw_line(red_ball, out);
/*cv::Mat maskBlue = cv::Mat::zeros(out.size(), CV_8U);
cv::Mat maskGreen = cv::Mat::zeros(out.size(), CV_8U);
int rB = cvRound(blue_ball.radius + 180);
int rG = cvRound(green_ball.radius + 180);
cv::circle(maskBlue, blue_middle, rB, 255, 1, cv::LINE_8);
cv::circle(maskGreen, green_middle, rG, 255, 1, cv::LINE_8);
cv::Mat inter;
cv::bitwise_and(maskBlue, maskGreen, inter);
std::vector<cv::Point> crossing;
cv::findNonZero(inter, crossing);
for (const auto& p : crossing)
{
cv::circle(out, p, 3, cv::Scalar(255,255,255), cv::FILLED, cv::LINE_AA);
}
*/
/*
std::vector<cv::Point> ringPtsBlue;
std::vector<cv::Point> ringPtsGreen;
cv::ellipse2Poly(blue_middle,
cv::Size(
static_cast<int>(blue_ball.radius + 180),
static_cast<int>(blue_ball.radius + 180)),
0, 0,360, 1,
ringPtsBlue);
cv::ellipse2Poly(green_middle,
cv::Size(
static_cast<int>(green_ball.radius + 180),
static_cast<int>(green_ball.radius + 180)),
0, 0,360, 1,
ringPtsGreen);
// Hashmap der Punktwolke für schnelleres Finden der Schnittpunkte !zu ungenau
auto key = [](int x, int y)->uint64_t
{
return (uint64_t(uint32_t(x)) << 32) | uint32_t(y);
};
std::unordered_set<uint64_t> blueSet;
blueSet.reserve(ringPtsBlue.size()*2);
for (const auto& p : ringPtsBlue)
{
blueSet.insert(key(p.x, p.y));
}
for (const auto& p : ringPtsGreen)
{
if (blueSet.count(key(p.x, p.y)))
{
cv::circle(
out,
{static_cast<int>(p.x), static_cast<int>(p.y)},
1, cv::Scalar(255,255,255),
cv::FILLED,
cv::LINE_AA
);
}
}
*/
}