forked from augcog/OpenARK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHand.cpp
68 lines (53 loc) · 1.47 KB
/
Hand.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
57
58
59
60
61
62
63
64
65
66
67
68
#include "stdafx.h"
#include "Hand.h"
#include "Util.h"
#include "Visualizer.h"
Hand::Hand()
{
}
Hand::Hand(cv::Vec3f centroid_xyz, cv::Point2i centroid_ij, std::vector<cv::Vec3f> fingers_xyz,
std::vector<cv::Point2i> fingers_ij, std::vector<cv::Vec3f> defects_xyz, std::vector<cv::Point2i> defects_ij)
{
this->centroid_xyz = centroid_xyz;
this->centroid_ij = centroid_ij;
this->fingers_xyz = fingers_xyz;
this->fingers_ij = fingers_ij;
this->defects_xyz = defects_xyz;
this->defects_ij = defects_ij;
}
//Hand::Hand(cv::Mat xyzMap, float angle_threshhold, int cluster_thresh)
//{
// CLUSTER_THRESHOLD = cluster_thresh * (float)xyzMap.cols / 320.0;
// ANGLE_THRESHHOLD = angle_threshhold;
//}
//
Hand::~Hand()
{
}
int Hand::getNumFingers() {
return (int)fingers_xyz.size();
}
bool Hand::touchObject(std::vector<double> &equation, const double threshold)
{
if (equation.size() == 0)
{
return false;
}
for (int i = 0; i < fingers_xyz.size(); i++)
{
double x = fingers_xyz[i][0];
double y = fingers_xyz[i][1];
double z = fingers_xyz[i][2];
if (z == 0)
{
return false;
}
double z_hat = equation[0] * x + equation[1] * y + equation[2];
double r_squared = (z - z_hat) * (z - z_hat);
if (r_squared < threshold)
{
return true;
}
}
return false;
}