Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
Added in bare bones server functionality, updated README.md to match
Browse files Browse the repository at this point in the history
  • Loading branch information
AdalynBlack committed Jun 12, 2021
1 parent 1b25283 commit 598e635
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 35 deletions.
77 changes: 63 additions & 14 deletions KinectV1Process/KinectV1Handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <KinectSettings.h>
#include <VRHelper.h>
#include <sfLine.h>
#include <iostream>
#include <KinectJoint.h>
Expand Down Expand Up @@ -42,6 +41,8 @@ LowPassFilter lowPassFilter[3][4] = {
}
};

static Networking networking;

void KinectV1Handler::initOpenGL()
{
LOG(INFO) << "Attempted to initialise OpenGL";
Expand Down Expand Up @@ -81,9 +82,10 @@ void KinectV1Handler::initOpenGL()

HRESULT KinectV1Handler::getStatusResult()
{
if (kinectSensor)
return netStatus();
/*if (kinectSensor)
return kinectSensor->NuiStatus();
return E_NUI_NOTCONNECTED;
return E_NUI_NOTCONNECTED;*/
}

std::string KinectV1Handler::statusResultString(HRESULT stat)
Expand All @@ -103,10 +105,22 @@ std::string KinectV1Handler::statusResultString(HRESULT stat)
case E_NUI_NOTPOWERED: return "E_NUI_NOTPOWERED\nCheck that your adapter is lit up.\nIf it is, look in Device Manager under \"other devices\"\nand as a last resort, try reinstalling the Kinect drivers entirely.";
// case E_NUI_NOTREADY: return "E_NUI_NOTREADY There was some other unspecified error.";
case E_NUI_NOTREADY: return "E_NUI_NOTREADY\nTry reconnecting the USB port of the device or restarting your PC.\nIf it doesn't work, reinstall the Kinect for Windows SDK.";
case S_FALSE: return "S_FALSE\nClient not connected, please connect it";
default: return "Uh Oh undefined kinect error! " + std::to_string(stat);
}
}

HRESULT KinectV1Handler::netStatus()
{
if (networking.connected)
{
return S_OK;
}
else {
return S_FALSE;
}
}

void KinectV1Handler::initialise()
{
try
Expand All @@ -128,12 +142,19 @@ void KinectV1Handler::update()
{
if (isInitialised())
{
HRESULT kinectStatus = kinectSensor->NuiStatus();
HRESULT kinectStatus = netStatus(); //kinectSensor->NuiStatus();
printf("status: %d\n", kinectStatus);
if (kinectStatus == S_OK)
{
getKinectRGBData();
updateSkeletalData();
}
else {
printf("wait for client\n");
networking.waitForClient();
printf("client connected\n");
Sleep(1000);
}
}
}

Expand Down Expand Up @@ -402,7 +423,7 @@ NUI_SKELETON_POSITION_INDEX KinectV1Handler::convertJoint(KVR::KinectJoint joint

bool KinectV1Handler::initKinect()
{
//Get a working Kinect Sensor
/*//Get a working Kinect Sensor
int numSensors = 0;
if (NuiGetSensorCount(&numSensors) < 0 || numSensors < 1)
{
Expand All @@ -419,7 +440,7 @@ bool KinectV1Handler::initKinect()
| NUI_INITIALIZE_FLAG_USES_SKELETON);
LOG_IF(FAILED(hr), ERROR) << "Kinect sensor failed to initialise!";
else
LOG(INFO) << "Kinect sensor opened successfully.";
LOG(INFO) << "Kinect sensor opened successfully.";*/
/*
kinectSensor->NuiImageStreamOpen(
NUI_IMAGE_TYPE_COLOR, //Depth Camera or RGB Camera?
Expand All @@ -430,7 +451,7 @@ bool KinectV1Handler::initKinect()
&kinectRGBStream);
*/
kinectSensor->NuiImageStreamOpen(
/*kinectSensor->NuiImageStreamOpen(
NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX, //Depth Camera or RGB Camera?
NUI_IMAGE_RESOLUTION_320x240, //Image Resolution
0, //Image stream flags, e.g. near mode
Expand All @@ -440,14 +461,17 @@ bool KinectV1Handler::initKinect()
kinectSensor->NuiSkeletonTrackingEnable(
nullptr,
NUI_SKELETON_TRACKING_FLAG_ENABLE_IN_NEAR_RANGE
);
);*/

return kinectSensor;
bool netErr = initNetworking() == 0;

return netErr;
}

void KinectV1Handler::getKinectRGBData()
{
NUI_IMAGE_FRAME imageFrame{};
return; // The data from this function is not used, the only use I can think of is that it might be necessary to track properly, so it is *probably* unnecessary on the server
/*NUI_IMAGE_FRAME imageFrame{};
NUI_LOCKED_RECT LockedRect{};
if (acquireKinectFrame(imageFrame, kinectRGBStream, kinectSensor))
{
Expand All @@ -457,7 +481,7 @@ void KinectV1Handler::getKinectRGBData()
copyKinectPixelData(LockedRect, kinectImageData.get());
unlockKinectPixelData(texture);
releaseKinectFrame(imageFrame, kinectRGBStream, kinectSensor);
releaseKinectFrame(imageFrame, kinectRGBStream, kinectSensor);*/
}

bool KinectV1Handler::acquireKinectFrame(NUI_IMAGE_FRAME& imageFrame, HANDLE& rgbStream, INuiSensor*& sensor)
Expand Down Expand Up @@ -499,9 +523,34 @@ void KinectV1Handler::releaseKinectFrame(NUI_IMAGE_FRAME& imageFrame, HANDLE& rg

static bool flip = false;

int KinectV1Handler::initNetworking()
{
LOG(INFO) << "Initializing Networking" << std::endl;
if (*networking.error_state == 0)
{
LOG(INFO) << "Searching for client" << std::endl;
networking.waitForClient();
return 0;
}
else
{
LOG(ERROR) << "Failed To Init Networking" << std::endl;
return -1;
}
}

HRESULT KinectV1Handler::netGetNextFrame(NUI_SKELETON_FRAME *frame)
{
*frame = networking.getLatestSkeleton(*frame);//wait for next frame and yoink it
return S_OK;
}

void KinectV1Handler::updateSkeletalData()
{
if (kinectSensor->NuiSkeletonGetNextFrame(0, &skeletonFrame) >= 0)
//if (kinectSensor->NuiSkeletonGetNextFrame(0, &skeletonFrame) >= 0)
//if (netGetNextFrame(&skeletonFrame) >= 0)
netGetNextFrame(&skeletonFrame);
if(true)
{
NUI_TRANSFORM_SMOOTH_PARAMETERS params;

Expand All @@ -518,9 +567,8 @@ void KinectV1Handler::updateSkeletalData()
params.fJitterRadius = 0.03f;
params.fPrediction = .25f;
*/
kinectSensor->NuiTransformSmooth(&skeletonFrame, &params); //Smooths jittery tracking
//kinectSensor->NuiTransformSmooth(&skeletonFrame, &params); //Smooths jittery tracking
NUI_SKELETON_DATA data;

for (int i = 0; i < NUI_SKELETON_COUNT; ++i)
{
NUI_SKELETON_TRACKING_STATE trackingState = skeletonFrame.SkeletonData[i].eTrackingState;
Expand All @@ -532,6 +580,7 @@ void KinectV1Handler::updateSkeletalData()
{
jointPositions[j] = skeletonFrame.SkeletonData[i].SkeletonPositions[j];
}
printf("\n");
NuiSkeletonCalculateBoneOrientations(&skeletonFrame.SkeletonData[i], boneOrientations);
rotFilter.update(boneOrientations);
break;
Expand Down
7 changes: 7 additions & 0 deletions KinectV1Process/KinectV1Handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "KinectV1Includes.h"
#include "KinectHandlerBase.h"
#include "KinectOrientationFilter.h"
#include "../Networking.cpp"

class KinectV1Handler : public KinectHandlerBase
{
Expand Down Expand Up @@ -37,6 +38,8 @@ class KinectV1Handler : public KinectHandlerBase
HRESULT getStatusResult() override;
std::string statusResultString(HRESULT stat) override;

HRESULT netStatus();

void drawKinectData(sf::RenderWindow& win) override;
void drawKinectImageData(sf::RenderWindow& win) override;
void drawTrackedSkeletons(sf::RenderWindow& win) override;
Expand Down Expand Up @@ -76,4 +79,8 @@ class KinectV1Handler : public KinectHandlerBase

bool jointsUntracked(KVR::KinectJoint joint0, KVR::KinectJoint joint1, NUI_SKELETON_DATA data);
bool jointsInferred(KVR::KinectJoint joint0, KVR::KinectJoint joint1, NUI_SKELETON_DATA data);

HRESULT netGetNextFrame(NUI_SKELETON_FRAME*);

int initNetworking();
};
10 changes: 3 additions & 7 deletions KinectV1Process/KinectV1Process.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// KinectV1Process.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "KinectToVR.h"
#include "KinectV1Handler.h"
#include <KinectToVR.h>
#include <openvr.h>
#include <Windows.h>
#define _DEBUG

// Logging Definitions
INITIALIZE_EASYLOGGINGPP
Expand Down Expand Up @@ -46,9 +44,7 @@ int main(int argc, char* argv[])
init_logging();
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd, SW_SHOW);
#ifndef _DEBUG
ShowWindow(hWnd, SW_HIDE);
#endif

KinectV1Handler kinect;
KinectSettings::leftFootJointWithRotation = KVR::KinectJointType::AnkleLeft;
KinectSettings::rightFootJointWithRotation = KVR::KinectJointType::AnkleRight;
Expand Down
5 changes: 4 additions & 1 deletion KinectV1Process/KinectV1Process.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<AdditionalIncludeDirectories>$(SolutionDir)external\PSMoveService;$(SolutionDir)external\opencv\include;$(ProjectDir)/inc;$(SolutionDir)external\glm_glm;$(SolutionDir)external\eigen-3.3.7;$(SolutionDir)external\Glew;$(SolutionDir)external\inputemulator\lib_vrinputemulator\include;$(SolutionDir)external\openvr\headers;$(SolutionDir)external\SFML\include;$(SolutionDir)external\sfgui;$(SolutionDir)external\easylogging\src;$(SolutionDir)SFMLProject\inc\;$(AdditionalIncludeDirectories);$(KINECTSDK10_DIR)inc;$(SolutionDir)external\PSMoveService\include;$(SolutionDir)external\boost_1_74_0;$(SolutionDir)KinectSDK-v1.8\AttachedContainer\SDK18\Microsoft SDKs\Kinect\v1.8\inc</AdditionalIncludeDirectories>
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
<LanguageStandard>stdcpp17</LanguageStandard>
<DisableSpecificWarnings>4996</DisableSpecificWarnings>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down Expand Up @@ -139,7 +140,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS;_CRT_SECURE_NO_WARNINGS;NOMINMAX;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(SolutionDir)external\PSMoveService;$(SolutionDir)external\opencv\include;$(ProjectDir)/inc;$(SolutionDir)external\Glew;$(SolutionDir)external\inputemulator\lib_vrinputemulator\include;$(SolutionDir)external\openvr\headers;$(SolutionDir)external\SFML\include;$(SolutionDir)external\sfgui;$(SolutionDir)external\easylogging\src;$(SolutionDir)SFMLProject\inc\;$(AdditionalIncludeDirectories);$(KINECTSDK10_DIR)inc;$(SolutionDir)external\PSMoveService\include;$(SolutionDir)external\boost_1_74_0;$(SolutionDir)KinectSDK-v1.8\AttachedContainer\SDK18\Microsoft SDKs\Kinect\v1.8\inc</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(SolutionDir)external\PSMoveService;$(SolutionDir)external\opencv\include;$(ProjectDir)/inc;$(SolutionDir)external\Glew;$(SolutionDir)external\inputemulator\lib_vrinputemulator\include;$(SolutionDir)external\openvr\headers;$(SolutionDir)external\SFML\include;$(SolutionDir)external\sfgui;$(SolutionDir)external\easylogging\src;$(SolutionDir)SFMLProject\inc\;$(AdditionalIncludeDirectories);$(KINECTSDK10_DIR)inc;$(SolutionDir)external\PSMoveService\include;$(SolutionDir)external\boost_1_74_0;$(SolutionDir)KinectSDK-v1.8\AttachedContainer\SDK18\Microsoft SDKs\Kinect\v1.8\inc;$(SolutionDir)external\sfgui\include</AdditionalIncludeDirectories>
<ForcedIncludeFiles>stdafx.h</ForcedIncludeFiles>
<LanguageStandard>stdcpp17</LanguageStandard>
<DebugInformationFormat>OldStyle</DebugInformationFormat>
Expand All @@ -157,6 +158,7 @@
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\SFMLProject\Networking.h" />
<ClInclude Include="KinectOrientationFilter.h" />
<ClInclude Include="KinectV1Handler.h" />
<ClInclude Include="KinectV1Includes.h" />
Expand All @@ -165,6 +167,7 @@
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\SFMLProject\Networking.cpp" />
<ClCompile Include="KinectV1Handler.cpp" />
<ClCompile Include="KinectV1Process.cpp" />
<ClCompile Include="stdafx.cpp">
Expand Down
6 changes: 6 additions & 0 deletions KinectV1Process/KinectV1Process.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\SFMLProject\Networking.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand All @@ -47,6 +50,9 @@
<ClCompile Include="KinectV1Handler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\SFMLProject\Networking.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="KinectV1Process.rc">
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,36 @@ Follow **[GitHub Actions script](https://github.com/KimihikoAkayasaki/KinectToVR
## Deploy
Grab all needed files from your current KinectToVR installation folder.<br>
This also applies to OpenVR driver folders structure and files.

## This Branch
This is a fork of the original [KinectToVR project](https://github.com/KinectToVR/KinectToVR), designed to allow a LAN connection between this server and the [corresponding client](https://github.com/TonyGamer/KinectToVRShadowClient).<br>
The program is quite finicky to set up and has quite a few issues which I imght fix in the future.<br>
**Only the Kinect V1 (Kinect 360) sensor is compatible with this project at the moment**

## First time setup
- Set up the ZeroTierOne on both your local Windows machine and on the Shadow PC. You will want to note the IP address for the Shadow PC when you do this.
- Install the server on the Shadow PC
- Install the client on your local machine (This is the server, the repo for the client is linked above)

## Installing the server
- Install the original KinectToVR project on Shadow
- Download the file called ```KinectV1Process.exe``` in the releases section
- Replace the corresponding file, which can be found in ```C:/K2EX```

## Use
- Launch SteamVR on Shadow and connect your headset
- Launch the KinectToVR server (KinectV1Process.exe on Shadow)
- Launch the KinectToVR client (KinectV1Process.exe on your local machine)
- Type in Shadow's IP in the command prompt which opens on your local machine

If all has gone well, the GUI on the KinectToVR server should appear, at which point it should, for the most part, behave like a normal instance of KinectToVR
If this is not the case, you will need to restart the server and try again

## Notes
- I highly recommend putting Virtual Desktop on both your local machine **and** Shadow. This makes the initial setup process much easier in my opinion
- If the KinectToVR Server stops responding, you will need to restart the server and reconnect to it manually on the KinectToVR client
- If the hip lagging behind bothers you, I recommend setting up owoTrack. The tracking quality from it is much better than the Kinect, and it helps mask the latency from the Kinect
- Some times the tracking will stop working altogether when you leave sight of the Kinect for an extended period of time. If this happens then you must restart both the Server and Client processes
- There is a noticable amount of latency, but from what I can tell it is mostly from the Kinect sensor itself, not the networking aspect added by this program

If you have any issues with this program, feel free to create an issue on the repository and/or send me a message on Discord at TonyGamer#7947
12 changes: 6 additions & 6 deletions SFMLProject/EKF_Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class KalmanFilter
{
public:
KalmanFilter::KalmanFilter(
KalmanFilter(
double dt,
const Eigen::MatrixXd& A,
const Eigen::MatrixXd& C,
Expand All @@ -19,11 +19,11 @@ class KalmanFilter
I.setIdentity();
}

KalmanFilter::KalmanFilter()
KalmanFilter()
{
}

void KalmanFilter::init(double t0, const Eigen::VectorXd& x0)
void init(double t0, const Eigen::VectorXd& x0)
{
x_hat = x0;
P = P0;
Expand All @@ -32,7 +32,7 @@ class KalmanFilter
initialized = true;
}

void KalmanFilter::init()
void init()
{
x_hat.setZero();
P = P0;
Expand All @@ -41,7 +41,7 @@ class KalmanFilter
initialized = true;
}

void KalmanFilter::update(const Eigen::VectorXd& y)
void update(const Eigen::VectorXd& y)
{
if (!initialized)
throw std::runtime_error("Filter is not initialized!");
Expand All @@ -56,7 +56,7 @@ class KalmanFilter
t += dt;
}

void KalmanFilter::update(const Eigen::VectorXd& y, double dt, const Eigen::MatrixXd A)
void update(const Eigen::VectorXd& y, double dt, const Eigen::MatrixXd A)
{
this->A = A;
this->dt = dt;
Expand Down
4 changes: 3 additions & 1 deletion SFMLProject/KinectToVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void attemptInitialiseDebugDisplay(sf::Font& font, sf::Text& debugText)
// Global Debug Font
#if _DEBUG
auto fontFileName = "arial.ttf";
LOG(DEBUG) << "Attemping Debug Font Load: " << fontFileName << '\n';
//LOG(DEBUG) << "Attemping Debug Font Load: " << fontFileName << '\n';
font.loadFromFile(fontFileName);
debugText.setFont(font);
#endif
Expand Down Expand Up @@ -241,6 +241,8 @@ int checkK2Server()

std::string ServerString = ServerData;

printf(ServerString.c_str());

if (ServerString.find("10") != std::string::npos)
{
return 10;
Expand Down
Loading

0 comments on commit 598e635

Please sign in to comment.