-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasic.cpp
40 lines (33 loc) · 877 Bytes
/
basic.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
#include "basic.h"
float idot(const cv::Vec3f a, const cv::Vec3f b)
{
float innerp = a.val[0] * b.val[0] + a.val[1] * b.val[1] + a.val[2] * b.val[2];
return innerp;
}
float idot(const cv::Vec4f a, const cv::Vec4f b)
{
float innerp = a.val[0] * b.val[0] + a.val[1] * b.val[1] + a.val[2] * b.val[2] + a.val[3] * b.val[3];
return innerp;
}
void mul(const cv::Mat mtx, const cv::Vec4f a, cv::Vec4f& ret)
{
if (mtx.cols != 4)
{
std::cerr << "can not multiply the mtx and the vector. mtx rows != 4" << std::endl;
exit(1);
}
int rows = mtx.rows;
int cols = mtx.cols;
for (int i = 0; i < rows; ++ i)
{
cv::Vec4f tmpvec;
for(int j = 0; j < cols; ++ j)
tmpvec.val[j] = mtx.at<float>(i, j);
ret.val[i] = idot(tmpvec, a);
}
}
Scalar randomColor(RNG& rng)
{
int icolor = (unsigned) rng;
return Scalar(icolor&255, (icolor>>8)&255, (icolor>>16)&255);
}