Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/samples/wp8/OcvImageManipulation/PhoneXamlDirect3DApp1/PhoneXamlDirect3DApp1Comp/Direct3DInterop.h
16349 views
1
#pragma once
2
3
#include "pch.h"
4
#include "BasicTimer.h"
5
#include "QuadRenderer.h"
6
#include <DrawingSurfaceNative.h>
7
#include <ppltasks.h>
8
#include <windows.storage.streams.h>
9
#include <memory>
10
#include <mutex>
11
12
13
#include <opencv2\imgproc\types_c.h>
14
15
16
namespace PhoneXamlDirect3DApp1Comp
17
{
18
19
public enum class OCVFilterType
20
{
21
ePreview,
22
eGray,
23
eCanny,
24
eBlur,
25
eFindFeatures,
26
eSepia,
27
eNumOCVFilterTypes
28
};
29
30
class CameraCapturePreviewSink;
31
class CameraCaptureSampleSink;
32
33
public delegate void RequestAdditionalFrameHandler();
34
public delegate void RecreateSynchronizedTextureHandler();
35
36
[Windows::Foundation::Metadata::WebHostHidden]
37
public ref class Direct3DInterop sealed : public Windows::Phone::Input::Interop::IDrawingSurfaceManipulationHandler
38
{
39
public:
40
Direct3DInterop();
41
42
Windows::Phone::Graphics::Interop::IDrawingSurfaceContentProvider^ CreateContentProvider();
43
44
// IDrawingSurfaceManipulationHandler
45
virtual void SetManipulationHost(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ manipulationHost);
46
47
event RequestAdditionalFrameHandler^ RequestAdditionalFrame;
48
event RecreateSynchronizedTextureHandler^ RecreateSynchronizedTexture;
49
50
property Windows::Foundation::Size WindowBounds;
51
property Windows::Foundation::Size NativeResolution;
52
property Windows::Foundation::Size RenderResolution
53
{
54
Windows::Foundation::Size get(){ return m_renderResolution; }
55
void set(Windows::Foundation::Size renderResolution);
56
}
57
void SetAlgorithm(OCVFilterType type) { m_algorithm = type; };
58
void UpdateFrame(byte* buffer, int width, int height);
59
60
61
protected:
62
// Event Handlers
63
void OnPointerPressed(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);
64
void OnPointerMoved(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);
65
void OnPointerReleased(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);
66
67
internal:
68
HRESULT STDMETHODCALLTYPE Connect(_In_ IDrawingSurfaceRuntimeHostNative* host);
69
void STDMETHODCALLTYPE Disconnect();
70
HRESULT STDMETHODCALLTYPE PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty);
71
HRESULT STDMETHODCALLTYPE GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle);
72
ID3D11Texture2D* GetTexture();
73
74
private:
75
void StartCamera();
76
void ProcessFrame();
77
bool SwapFrames();
78
79
QuadRenderer^ m_renderer;
80
Windows::Foundation::Size m_renderResolution;
81
OCVFilterType m_algorithm;
82
bool m_contentDirty;
83
std::shared_ptr<cv::Mat> m_backFrame;
84
std::shared_ptr<cv::Mat> m_frontFrame;
85
std::mutex m_mutex;
86
87
Windows::Phone::Media::Capture::AudioVideoCaptureDevice ^pAudioVideoCaptureDevice;
88
ICameraCaptureDeviceNative* pCameraCaptureDeviceNative;
89
IAudioVideoCaptureDeviceNative* pAudioVideoCaptureDeviceNative;
90
CameraCapturePreviewSink* pCameraCapturePreviewSink;
91
CameraCaptureSampleSink* pCameraCaptureSampleSink;
92
93
//void ApplyPreviewFilter(const cv::Mat& image);
94
void ApplyGrayFilter(cv::Mat* mat);
95
void ApplyCannyFilter(cv::Mat* mat);
96
void ApplyBlurFilter(cv::Mat* mat);
97
void ApplyFindFeaturesFilter(cv::Mat* mat);
98
void ApplySepiaFilter(cv::Mat* mat);
99
};
100
101
class CameraCapturePreviewSink :
102
public Microsoft::WRL::RuntimeClass<
103
Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>,
104
ICameraCapturePreviewSink>
105
{
106
public:
107
void SetDelegate(Direct3DInterop^ delegate)
108
{
109
m_Direct3dInterop = delegate;
110
}
111
112
IFACEMETHODIMP_(void) OnFrameAvailable(
113
DXGI_FORMAT format,
114
UINT width,
115
UINT height,
116
BYTE* pixels);
117
118
private:
119
Direct3DInterop^ m_Direct3dInterop;
120
};
121
122
class CameraCaptureSampleSink :
123
public Microsoft::WRL::RuntimeClass<
124
Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>,
125
ICameraCaptureSampleSink>
126
{
127
public:
128
void SetDelegate(Direct3DInterop^ delegate)
129
{
130
m_Direct3dInterop = delegate;
131
}
132
133
IFACEMETHODIMP_(void) OnSampleAvailable(
134
ULONGLONG hnsPresentationTime,
135
ULONGLONG hnsSampleDuration,
136
DWORD cbSample,
137
BYTE* pSample);
138
139
private:
140
Direct3DInterop^ m_Direct3dInterop;
141
};
142
143
}
144
145