forked from microsoft/MixedRealityCompanionKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenCVFrameProvider.h
79 lines (60 loc) · 1.75 KB
/
OpenCVFrameProvider.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
#pragma once
#if USE_OPENCV
#include "IFrameProvider.h"
#include <mutex>
//TODO: Update with the 3.x version of OpenCV you are using.
#pragma comment(lib, "opencv_world341")
#include "opencv2/opencv.hpp"
#include "DirectXHelper.h"
//TODO: Change this value to match the camera id you are using.
// If your PC has an integrated webcam, that will probably be id 0.
#define CAMERA_ID 0
class OpenCVFrameProvider : public IFrameProvider
{
private:
std::mutex frameAccessLock;
std::mutex videoLock;
LONGLONG latestTimeStamp = 0;
LARGE_INTEGER freq;
cv::VideoCapture* videoCapture = nullptr;
ID3D11ShaderResourceView* _colorSRV;
ID3D11Device* _device;
cv::Mat frame;
cv::Mat rgbaFrame;
int rgbaConversion[8];
class BufferCache
{
public:
BYTE * buffer;
LONGLONG timeStamp;
};
BufferCache bufferCache[MAX_NUM_CACHED_BUFFERS];
int captureFrameIndex = 0;
public:
OpenCVFrameProvider();
~OpenCVFrameProvider();
// Inherited via IFrameProvider
virtual HRESULT Initialize(ID3D11ShaderResourceView* srv) override;
virtual bool IsEnabled() override;
virtual void Update(int compositeFrameIndex) override;
virtual void Dispose() override;
virtual bool OutputYUV()
{
return false;
}
virtual LONGLONG GetTimestamp(int frame)
{
return bufferCache[frame % MAX_NUM_CACHED_BUFFERS].timeStamp;
}
virtual LONGLONG GetDurationHNS()
{
return (LONGLONG)((1.0f / 60.0f) * S2HNS);
}
virtual int GetCaptureFrameIndex()
{
return captureFrameIndex;
}
};
#endif