Monado OpenXR Runtime
Loading...
Searching...
No Matches
hg_image_math.inl
Go to the documentation of this file.
1// Copyright 2021-2022, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Helper header for drawing and image transforms
6 * @author Moshi Turner <moshiturner@protonmail.com>
7 * @ingroup tracking
8 */
9#pragma once
10
11#include "hg_sync.hpp"
12
13namespace xrt::tracking::hand::mercury {
14
15/*!
16 * This is a template so that we can use xrt_vec3 or xrt_vec2.
17 * Please don't use this for anything other than xrt_vec3 or xrt_vec2!
18 */
19template <typename T>
20T
21transformVecBy2x3(T in, cv::Matx23f warp_back)
22{
23 T rr;
24 rr.x = (in.x * warp_back(0, 0)) + (in.y * warp_back(0, 1)) + warp_back(0, 2);
25 rr.y = (in.x * warp_back(1, 0)) + (in.y * warp_back(1, 1)) + warp_back(1, 2);
26 return rr;
27}
28
29static cv::Scalar
30hsv2rgb(float fH, float fS, float fV)
31{
32 const float fC = fV * fS; // Chroma
33 const float fHPrime = fmod(fH / 60.0, 6);
34 const float fX = fC * (1 - fabs(fmod(fHPrime, 2) - 1));
35 const float fM = fV - fC;
36
37 float fR, fG, fB;
38
39 if (0 <= fHPrime && fHPrime < 1) {
40 fR = fC;
41 fG = fX;
42 fB = 0;
43 } else if (1 <= fHPrime && fHPrime < 2) {
44 fR = fX;
45 fG = fC;
46 fB = 0;
47 } else if (2 <= fHPrime && fHPrime < 3) {
48 fR = 0;
49 fG = fC;
50 fB = fX;
51 } else if (3 <= fHPrime && fHPrime < 4) {
52 fR = 0;
53 fG = fX;
54 fB = fC;
55 } else if (4 <= fHPrime && fHPrime < 5) {
56 fR = fX;
57 fG = 0;
58 fB = fC;
59 } else if (5 <= fHPrime && fHPrime < 6) {
60 fR = fC;
61 fG = 0;
62 fB = fX;
63 } else {
64 fR = 0;
65 fG = 0;
66 fB = 0;
67 }
68
69 fR += fM;
70 fG += fM;
71 fB += fM;
72 return {fR * 255.0f, fG * 255.0f, fB * 255.0f};
73}
74
75inline void
76handDot(cv::Mat &mat, xrt_vec2 place, float radius, float hue, float intensity, int type)
77{
78 cv::circle(mat, {(int)place.x, (int)place.y}, radius, hsv2rgb(hue * 360.0f, intensity, intensity), type);
79}
80
81inline void
82handSquare(cv::Mat &debug_frame, xrt_vec2 center, float radius, cv::Scalar color)
83{
84 cv::Point2i pt((int)center.x, (int)center.y);
85 cv::rectangle(debug_frame, cv::Rect(pt - cv::Point2i(radius / 2, radius / 2), cv::Size(radius, radius)), color,
86 1);
87}
88
89} // namespace xrt::tracking::hand::mercury
T transformVecBy2x3(T in, cv::Matx23f warp_back)
This is a template so that we can use xrt_vec3 or xrt_vec2.
Definition hg_image_math.inl:21
Mercury main header!
A 2 element vector with single floats.
Definition xrt_defines.h:268