Update at the bottom.
I have a Kinect V2 laying around and wanted to see if I could do something fun with it so I downloaded the SDK, MinGW-w64, and the C/C++ for Visual Studio Code extension and started hacking away at acquiring the sensor and reading the infrared data source and this is what I have so far:
#include "test.h"
int main() {
HRESULT sensorAcquisition = aquireSensor();
return 0;
}
HRESULT aquireSensor() {
HRESULT hr = GetDefaultKinectSensor(&m_pKinectSensor);
if (FAILED(hr))
{
return hr;
}
// Initialize the Kinect and get the infrared reader
IInfraredFrameSource* pInfraredFrameSource = NULL;
hr = m_pKinectSensor->Open();
// https://docs.microsoft.com/en-us/previous-versions/bb931994(v=msdn.10)
if (SUCCEEDED(hr))
{
hr = m_pKinectSensor->get_InfraredFrameSource(&pInfraredFrameSource);
}
if (SUCCEEDED(hr))
{
hr = pInfraredFrameSource->OpenReader(&m_pInfraredFrameReader);
}
return hr;
}
Along with the header file:
#pragma once
#include "C:\Program Files\Microsoft SDKs\Kinect\v2.0_1409\inc\Kinect.h"
HRESULT aquireSensor();
// InfraredSourceValueMaximum is the highest value that can be returned in the InfraredFrame.
// It is cast to a float for readability in the visualization code.
#define InfraredSourceValueMaximum static_cast<float>(USHRT_MAX)
// The InfraredOutputValueMinimum value is used to set the lower limit, post processing, of the
// infrared data that we will render.
// Increasing or decreasing this value sets a brightness "wall" either closer or further away.
#define InfraredOutputValueMinimum 0.01f
// The InfraredOutputValueMaximum value is the upper limit, post processing, of the
// infrared data that we will render.
#define InfraredOutputValueMaximum 1.0f
// The InfraredSceneValueAverage value specifies the average infrared value of the scene.
// This value was selected by analyzing the average pixel intensity for a given scene.
// Depending on the visualization requirements for a given application, this value can be
// hardcoded, as was done here, or calculated by averaging the intensity for each pixel prior
// to rendering.
#define InfraredSceneValueAverage 0.08f
/// The InfraredSceneStandardDeviations value specifies the number of standard deviations
/// to apply to InfraredSceneValueAverage. This value was selected by analyzing data
/// from a given scene.
/// Depending on the visualization requirements for a given application, this value can be
/// hard coded, as was done here, or calculated at runtime.
#define InfraredSceneStandardDeviations 3.0f
// Current Kinect
IKinectSensor* m_pKinectSensor;
// Infrared reader
IInfraredFrameReader* m_pInfraredFrameReader;
When I compile this using:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\Program Files\\Microsoft SDKs\\Kinect\\v2.0_1409\\Lib\\x64",
"C:\\Program Files\\Microsoft SDKs\\Kinect\\v2.0_1409\\inc"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "gnu17",
"cppStandard": "c++20",
"intelliSenseMode": "${default}",
"compilerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe",
"forcedInclude": [],
"browse": {
"path": []
},
"compilerArgs": []
}
],
"version": 4
}
It throws a lot of the following errors:
use of enum '_KinectCapabilities' without a previous declaration
The enums are referenced here: https://docs.microsoft.com/en-us/previous-versions/windows/kinect/dn758672(v=ieb.10)
They seem to require the library Kinect20.lib.
I added the folder it is into my include path but that doesn't fix the issue and after A LOT of googling and changing the compiler configuration I've hit a wall.
Any ideas?
Disclaimer, I'm a noob when it comes to compilers and C++ so don't be mean if the solution is trivial.
UPDATE: (Forgive me if I say something wrong, compiling and c++ isn't my strong suit)
The problem: So as a few people commented and I suspected there seemed to be a problem with my compiling and linking, especially using MinGW-w64. There was a static library, namely "Kinect20.lib" that was needed for "Kinect.h" to work as I understand it and the MinGW-w64 compiler either couldn't handle .lib or I was to stupid/impatient to make it work.
The solution: I downloaded Visual Studio community 2019 and copy/pasted my previously written code into a new project, added paths to "Kinect.h" and "Kinect20.lib" to the c++ dependencies and linker directory/files respectively. Made sure to use x86 everywhere.
This is where it gets annoying... I ran the debugger and I got the same errors as before but I clicked one of the errors and it opened "Kinect.h" and all the errors disappeared, the code ran and my Kinect turned on!
I hope this can help anyone in the same position as me and also if you read through this and have any comments for me where I said something wrong or where I could improve in some way I'd be super grateful for feedback!