PoseMatch.h

#ifndef POSE_MATCH_H
#define POSE_MATCH_H

#include "Windows.h"
#include "Kinect.h"
#include <string>

void loadPoseData(std::string filename, Joint *jarr);
double cosineSimilarity(Joint a, Joint b);
double comparePoses(Joint *arr1, Joint *arr2);

#endif

PoseMatch.cpp

#include "PoseMatch.h"
#include <iostream>
#include <stdio.h>
#include <fstream>


using namespace std;

const int JOINT_COUNT = 25;

// Percentage of similarity that two poses must meet to be considered matching
const double MATCHING_EPSILON = 0.99; 

// Load pose data from a text file
void loadPoseData(std::string filename, Joint *jarr) {
	ifstream fp(filename);
	string token;
	for (int i = 0; i < JOINT_COUNT; i++) {
		fp >> token;
		jarr[i].Position.X = stod(token);
		fp >> token;
		jarr[i].Position.Y = stod(token);
		fp >> token;
		jarr[i].Position.Z = stod(token);
	}
}

// Get cosine similarity based on two Joint's position
double cosineSimilarity(Joint a, Joint b) {
	double numerator = a.Position.X * b.Position.X + a.Position.Y * 
		b.Position.Y + a.Position.Z * b.Position.Z;
	double aMagn = pow(a.Position.X * a.Position.X + a.Position.Y *
		a.Position.Y + a.Position.Z * a.Position.Z, 0.5);
	double bMagn = pow(b.Position.X * b.Position.X + b.Position.Y *
		b.Position.Y + b.Position.Z * b.Position.Z, 0.5);
	return (numerator / (aMagn*bMagn));
}

// Compare two arrays of joints based on their cosine similarities
// Return false if the cosine similarity of any two joints exceeds epsilon threshold
double comparePoses(Joint *arr1, Joint *arr2) {
	for (int i = 0; i < JOINT_COUNT; i++) {
		cout << cosineSimilarity(arr1[i], arr2[i]) << endl;
		if (cosineSimilarity(arr1[i], arr2[i]) < MATCHING_EPSILON) { return false; }
	}
	return true;
}