4
#include "BasicTimer.h"
5
#include "QuadRenderer.h"
6
#include <DrawingSurfaceNative.h>
8
#include <windows.storage.streams.h>
13
#include <opencv2\imgproc\types_c.h>
16
namespace PhoneXamlDirect3DApp1Comp
19
public enum class OCVFilterType
30
class CameraCapturePreviewSink;
31
class CameraCaptureSampleSink;
33
public delegate void RequestAdditionalFrameHandler();
34
public delegate void RecreateSynchronizedTextureHandler();
36
[Windows::Foundation::Metadata::WebHostHidden]
37
public ref class Direct3DInterop sealed : public Windows::Phone::Input::Interop::IDrawingSurfaceManipulationHandler
42
Windows::Phone::Graphics::Interop::IDrawingSurfaceContentProvider^ CreateContentProvider();
44
// IDrawingSurfaceManipulationHandler
45
virtual void SetManipulationHost(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ manipulationHost);
47
event RequestAdditionalFrameHandler^ RequestAdditionalFrame;
48
event RecreateSynchronizedTextureHandler^ RecreateSynchronizedTexture;
50
property Windows::Foundation::Size WindowBounds;
51
property Windows::Foundation::Size NativeResolution;
52
property Windows::Foundation::Size RenderResolution
54
Windows::Foundation::Size get(){ return m_renderResolution; }
55
void set(Windows::Foundation::Size renderResolution);
57
void SetAlgorithm(OCVFilterType type) { m_algorithm = type; };
58
void UpdateFrame(byte* buffer, int width, int height);
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);
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();
79
QuadRenderer^ m_renderer;
80
Windows::Foundation::Size m_renderResolution;
81
OCVFilterType m_algorithm;
83
std::shared_ptr<cv::Mat> m_backFrame;
84
std::shared_ptr<cv::Mat> m_frontFrame;
87
Windows::Phone::Media::Capture::AudioVideoCaptureDevice ^pAudioVideoCaptureDevice;
88
ICameraCaptureDeviceNative* pCameraCaptureDeviceNative;
89
IAudioVideoCaptureDeviceNative* pAudioVideoCaptureDeviceNative;
90
CameraCapturePreviewSink* pCameraCapturePreviewSink;
91
CameraCaptureSampleSink* pCameraCaptureSampleSink;
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);
101
class CameraCapturePreviewSink :
102
public Microsoft::WRL::RuntimeClass<
103
Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>,
104
ICameraCapturePreviewSink>
107
void SetDelegate(Direct3DInterop^ delegate)
109
m_Direct3dInterop = delegate;
112
IFACEMETHODIMP_(void) OnFrameAvailable(
119
Direct3DInterop^ m_Direct3dInterop;
122
class CameraCaptureSampleSink :
123
public Microsoft::WRL::RuntimeClass<
124
Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>,
125
ICameraCaptureSampleSink>
128
void SetDelegate(Direct3DInterop^ delegate)
130
m_Direct3dInterop = delegate;
133
IFACEMETHODIMP_(void) OnSampleAvailable(
134
ULONGLONG hnsPresentationTime,
135
ULONGLONG hnsSampleDuration,
140
Direct3DInterop^ m_Direct3dInterop;