write preview code, calibration code is flawed for now
This commit is contained in:
parent
423ef98ec9
commit
76e688b6b2
@ -1,6 +1,7 @@
|
||||
#include "includes.h"
|
||||
Vector4 leftLegPos = { 1.5F, 1.5F, 1.5F, 1.5F };
|
||||
Vector4 rightLegPos = { 1.5F, 1.5F, 1.5F, 1.5F };
|
||||
bool kinectScanning = true;
|
||||
|
||||
int calibration() {
|
||||
|
||||
@ -55,6 +56,18 @@ int calibration() {
|
||||
//Y calibration
|
||||
float yGrad = (yMax - yMin) / (zMax - zMin);
|
||||
float yOffset = (yMin - yGrad * zMin);
|
||||
|
||||
|
||||
// Clean up and proceed to kinect test
|
||||
kinectScanning = false;
|
||||
std::cout << std::to_string(xGrad) << " ";
|
||||
std::cout << std::to_string(xOffset) << " ";
|
||||
std::cout << std::to_string(yGrad) << " ";
|
||||
std::cout << std::to_string(yOffset) << " ";
|
||||
std::cout << std::to_string(zGrad) << " ";
|
||||
std::cout << std::to_string(zOffset) << "\n";
|
||||
std::cout << "Proceeding to Kinect Preview..\n";
|
||||
kinectTest(xGrad, xOffset, yGrad, yOffset, zGrad, zOffset);
|
||||
});
|
||||
|
||||
|
||||
@ -62,7 +75,7 @@ int calibration() {
|
||||
|
||||
// main loop to read and process skeleton data
|
||||
NUI_SKELETON_FRAME skeletonFrame = { 0 };
|
||||
while (true) {
|
||||
while (kinectScanning) {
|
||||
// get the latest skeleton frame
|
||||
hr = NuiSkeletonGetNextFrame(0, &skeletonFrame);
|
||||
if (FAILED(hr)) {
|
||||
@ -82,5 +95,6 @@ int calibration() {
|
||||
// Clean up and exit
|
||||
NuiSkeletonTrackingDisable();
|
||||
NuiShutdown();
|
||||
std::this_thread::sleep_for(std::chrono::hours(1000));
|
||||
return 0;
|
||||
}
|
@ -13,7 +13,7 @@ int main()
|
||||
return 0;
|
||||
}
|
||||
else if (choice == 2) {
|
||||
std::cout << "okay 2";
|
||||
kinectTest(1, 1, 1, 1, 1, 1);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
|
@ -134,10 +134,12 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="calibration.cpp" />
|
||||
<ClCompile Include="depthrushConfig.cpp" />
|
||||
<ClCompile Include="kinectTest.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="calibration.h" />
|
||||
<ClInclude Include="includes.h" />
|
||||
<ClInclude Include="kinectTest.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
@ -21,6 +21,9 @@
|
||||
<ClCompile Include="calibration.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="kinectTest.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="includes.h">
|
||||
@ -29,5 +32,8 @@
|
||||
<ClInclude Include="calibration.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="kinectTest.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
4
depthrushConfig/depthrushConfig.vcxproj.user
Normal file
4
depthrushConfig/depthrushConfig.vcxproj.user
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
@ -5,3 +5,6 @@
|
||||
#include <thread>
|
||||
#include <string>
|
||||
#include "calibration.h"
|
||||
#include "kinectTest.h"
|
||||
|
||||
|
||||
|
111
depthrushConfig/kinectTest.cpp
Normal file
111
depthrushConfig/kinectTest.cpp
Normal file
@ -0,0 +1,111 @@
|
||||
#include "includes.h"
|
||||
Vector4 leftLegPosPreview = { 1.5F, 1.5F, 1.5F, 1.5F };
|
||||
Vector4 rightLegPosPreview = { 1.5F, 1.5F, 1.5F, 1.5F };
|
||||
|
||||
int kinectTest(float xGrad, float xOffset, float yGrad, float yOffset, float zGrad, float zOffset) {
|
||||
//std::cout << "Kinect Preview\n";
|
||||
//std::cin >> xGrad;
|
||||
//std::cin >> xOffset;
|
||||
// Wait 10 secs for kinect shutdown
|
||||
// Sleep(10000);
|
||||
// initialize Kinect
|
||||
HRESULT hr = NuiInitialize(NUI_INITIALIZE_FLAG_USES_SKELETON);
|
||||
if (FAILED(hr)) {
|
||||
std::cout << "Failed to initialize Kinect." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// open the skeleton stream
|
||||
HANDLE skeletonStream = nullptr;
|
||||
hr = NuiSkeletonTrackingEnable(nullptr, 0);
|
||||
if (FAILED(hr)) {
|
||||
std::cout << "Failed to open the skeleton stream." << std::endl;
|
||||
NuiShutdown();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// main loop to read and process skeleton data
|
||||
NUI_SKELETON_FRAME skeletonFrame = { 0 };
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
int width = 0;
|
||||
float drsLeft = 0;
|
||||
float drsRight = 0;
|
||||
int toolLeft = 0;
|
||||
int toolRight = 0;
|
||||
int toolWidth = 0;
|
||||
bool leftTouch = false;
|
||||
bool rightTouch = false;
|
||||
|
||||
while (true) {
|
||||
// get the latest skeleton frame
|
||||
hr = NuiSkeletonGetNextFrame(0, &skeletonFrame);
|
||||
if (FAILED(hr)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Process each tracked skeleton
|
||||
for (int i = 0; i < NUI_SKELETON_COUNT; ++i) {
|
||||
if (skeletonFrame.SkeletonData[i].eTrackingState == NUI_SKELETON_TRACKED) {
|
||||
// get the position of both legs
|
||||
leftLegPosPreview = skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_ANKLE_LEFT];
|
||||
rightLegPosPreview = skeletonFrame.SkeletonData[i].SkeletonPositions[NUI_SKELETON_POSITION_ANKLE_RIGHT];
|
||||
}
|
||||
}
|
||||
|
||||
// keep updating screen width for fancy
|
||||
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
|
||||
width = (int)(csbi.srWindow.Right - csbi.srWindow.Left + 1);
|
||||
|
||||
// fetch calibrated feet
|
||||
drsLeft = xGrad * leftLegPosPreview.x + xOffset;
|
||||
drsRight = xGrad * rightLegPosPreview.x + xOffset;
|
||||
|
||||
// translate to console window width
|
||||
toolLeft = width * drsLeft;
|
||||
toolRight = width * drsRight;
|
||||
toolWidth = width * 0.05;
|
||||
|
||||
// foot lifting detection
|
||||
// see how far foot currently is from known ground value
|
||||
float fixedLeft = leftLegPosPreview.y - (yGrad * leftLegPosPreview.z + yOffset);
|
||||
float fixedRight = rightLegPosPreview.y - (yGrad * rightLegPosPreview.z + yOffset);
|
||||
|
||||
// check for stepping
|
||||
float errorMargin = 0.05;
|
||||
if (fixedLeft > (fixedRight + errorMargin)) {
|
||||
rightTouch = true;
|
||||
leftTouch = false;
|
||||
// std::cout << "right step\n";
|
||||
}
|
||||
else if (fixedLeft > (fixedRight + errorMargin)) {
|
||||
leftTouch = true;
|
||||
rightTouch = false;
|
||||
// std::cout << "left step \n";
|
||||
}
|
||||
else {
|
||||
leftTouch = true;
|
||||
rightTouch = true;
|
||||
// std::cout << "both step\n";
|
||||
}
|
||||
/*
|
||||
// print feet
|
||||
for (int i = 0; i < width; i++) {
|
||||
if ((i <= (toolLeft + toolWidth)) && (i >= (toolLeft - toolWidth)) && leftTouch) {
|
||||
std::cout << "L";
|
||||
}
|
||||
else if ((i <= (toolRight + toolWidth)) && (i >= (toolRight - toolWidth)) && rightTouch) {
|
||||
std::cout << "R";
|
||||
}
|
||||
else {
|
||||
std::cout << " ";
|
||||
}
|
||||
}
|
||||
*/
|
||||
std::cout << std::to_string(fixedLeft) << " " << std::to_string(fixedRight) << std::endl;
|
||||
}
|
||||
|
||||
// Clean up and exit
|
||||
NuiSkeletonTrackingDisable();
|
||||
NuiShutdown();
|
||||
return 0;
|
||||
}
|
2
depthrushConfig/kinectTest.h
Normal file
2
depthrushConfig/kinectTest.h
Normal file
@ -0,0 +1,2 @@
|
||||
#pragma once
|
||||
int kinectTest(float xGrad, float xOffset, float yGrad, float yOffset, float zGrad, float zOffset);
|
Loading…
Reference in New Issue
Block a user