我对Kinect 2.0 SDK有问题: 无法复制样本就无法捕获样本数据。
问题在于, AcquireLatestFrame 不会给我新的示例,除非我发布 IColorFrame 的 Microsoft :: WRL :: ComPtr 。
所有教程使用相同的副本:
然后出现问题: 我该如何入侵 Microsoft :: WRL :: ComPtr ,并在不复制的情况下拦截数据?
SDKFetchSamplesWork.h
#pragma once
#include <memory>
#include <Windows.h>
#include <Kinect.h>
#include <wrl/client.h>
namespace kinect2
{
class ColorFrame
{
public:
static constexpr int WIDTH = 1920;
static constexpr int HEIGHT = 1080;
public:
unsigned short texels_yuy2[WIDTH * HEIGHT];
};
class SDKFetchSamplesWork
{
public:
SDKFetchSamplesWork();
void TryFetchSample();
public:
std::shared_ptr<const ColorFrame> fetched_color_frame;
private:
Microsoft::WRL::ComPtr<IKinectSensor> _kinect_sensor;
Microsoft::WRL::ComPtr<IColorFrameReader> _color_frame_reader;
};
}
SDKFetchSamplesWork.cpp
#include "Kinect2/sdk_fetch_samples_work.h"
namespace kinect2
{
SDKFetchSamplesWork::SDKFetchSamplesWork()
:
fetched_color_frame(nullptr)
{
GetDefaultKinectSensor(&_kinect_sensor);
_kinect_sensor->Open();
Microsoft::WRL::ComPtr<IColorFrameSource> color_frame_source;
_kinect_sensor->get_ColorFrameSource(&color_frame_source);
_color_frame_source->OpenReader(&_color_frame_reader);
}
void SDKFetchSamplesWork::TryFetchSample()
{
if (!_color_frame_reader || fetched_color_frame) return;
Microsoft::WRL::ComPtr<IColorFrame> sdk_color_frame;
const HRESULT ret = _color_frame_reader->AcquireLatestFrame(&sdk_color_frame);
if (FAILED(ret)) return;
auto new_color_frame = std::make_shared<ColorFrame>();
sdk_color_frame->CopyRawFrameDataToArray(
sizeof(UINT16) * ColorFrame::WIDTH * ColorFrame::HEIGHT,
(BYTE*)(new_color_frame->texels_yuy2)
);
fetched_color_frame = new_color_frame;
}
}