Signed-off-by: Maxim Kostin <v-maxkos@microsoft.com>pull/3700/head
@ -0,0 +1,87 @@ |
||||
# Ignore thumbnails created by windows |
||||
Thumbs.db |
||||
|
||||
#ignore winrt copies of opencv files |
||||
opencl_kernels.cpp |
||||
opencl_kernels.hpp |
||||
|
||||
# Ignore files build by Visual Studio |
||||
*.obj |
||||
*.exe |
||||
*.pdb |
||||
*.aps |
||||
*.vcproj.*.user |
||||
*.vcxproj.user |
||||
*.vspscc |
||||
*_i.c |
||||
*.i |
||||
*.icf |
||||
*_p.c |
||||
*.ncb |
||||
*.suo |
||||
*.tlb |
||||
*.tlh |
||||
*.bak |
||||
*.cache |
||||
*.ilk |
||||
*.log |
||||
*.winmd |
||||
[Bb]in |
||||
[Dd]ebug*/ |
||||
*.sbr |
||||
*.sdf |
||||
obj/ |
||||
[Rr]elease*/ |
||||
_ReSharper*/ |
||||
[Tt]est[Rr]esult* |
||||
ipch/ |
||||
*.opensdf |
||||
Generated Files |
||||
AppPackages |
||||
SubmissionInfo |
||||
*.hps |
||||
|
||||
# Ignore files build by ndk and eclipse |
||||
libs/ |
||||
bin/ |
||||
obj/ |
||||
gen/ |
||||
local.properties |
||||
|
||||
# Ignore python compiled files |
||||
*.pyc |
||||
|
||||
# Ignore files build by airplay and marmalade |
||||
build_*_xcode/ |
||||
build_*_vc10/ |
||||
|
||||
# Ignore files built by xcode |
||||
*.mode*v* |
||||
*.pbxuser |
||||
*.xcbkptlist |
||||
*.xcscheme |
||||
*.xcworkspacedata |
||||
*.xcuserstate |
||||
xcschememanagement.plist |
||||
build/ |
||||
.DS_Store |
||||
._.* |
||||
xcuserdata/ |
||||
DerivedData/ |
||||
*.xccheckout |
||||
|
||||
# Ignore files built by bada |
||||
.Simulator-Debug/ |
||||
.Target-Debug/ |
||||
.Target-Release/ |
||||
|
||||
# Ignore files built by blackberry |
||||
Simulator/ |
||||
Device-Debug/ |
||||
Device-Release/ |
||||
|
||||
# Ignore vim swaps |
||||
*.swp |
||||
|
||||
# CTags |
||||
tags |
After Width: | Height: | Size: 8.8 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 4.8 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 118 KiB |
@ -0,0 +1,77 @@ |
||||
#include "pch.h" |
||||
#include "Direct3DContentProvider.h" |
||||
|
||||
using namespace PhoneXamlDirect3DApp1Comp; |
||||
|
||||
Direct3DContentProvider::Direct3DContentProvider(Direct3DInterop^ controller) : |
||||
m_controller(controller) |
||||
{ |
||||
m_controller->RequestAdditionalFrame += ref new RequestAdditionalFrameHandler([=] () |
||||
{ |
||||
if (m_host) |
||||
{ |
||||
m_host->RequestAdditionalFrame(); |
||||
} |
||||
}); |
||||
|
||||
m_controller->RecreateSynchronizedTexture += ref new RecreateSynchronizedTextureHandler([=] () |
||||
{ |
||||
if (m_host) |
||||
{ |
||||
m_host->CreateSynchronizedTexture(m_controller->GetTexture(), &m_synchronizedTexture); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
// IDrawingSurfaceContentProviderNative interface
|
||||
HRESULT Direct3DContentProvider::Connect(_In_ IDrawingSurfaceRuntimeHostNative* host) |
||||
{ |
||||
m_host = host; |
||||
|
||||
return m_controller->Connect(host); |
||||
} |
||||
|
||||
void Direct3DContentProvider::Disconnect() |
||||
{ |
||||
m_controller->Disconnect(); |
||||
m_host = nullptr; |
||||
m_synchronizedTexture = nullptr; |
||||
} |
||||
|
||||
HRESULT Direct3DContentProvider::PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty) |
||||
{ |
||||
return m_controller->PrepareResources(presentTargetTime, contentDirty); |
||||
} |
||||
|
||||
HRESULT Direct3DContentProvider::GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle) |
||||
{ |
||||
HRESULT hr = S_OK; |
||||
|
||||
if (!m_synchronizedTexture) |
||||
{ |
||||
hr = m_host->CreateSynchronizedTexture(m_controller->GetTexture(), &m_synchronizedTexture); |
||||
} |
||||
|
||||
// Set output parameters.
|
||||
textureSubRectangle->left = 0.0f; |
||||
textureSubRectangle->top = 0.0f; |
||||
textureSubRectangle->right = static_cast<FLOAT>(size->width); |
||||
textureSubRectangle->bottom = static_cast<FLOAT>(size->height); |
||||
|
||||
m_synchronizedTexture.CopyTo(synchronizedTexture); |
||||
|
||||
// Draw to the texture.
|
||||
if (SUCCEEDED(hr)) |
||||
{ |
||||
hr = m_synchronizedTexture->BeginDraw(); |
||||
|
||||
if (SUCCEEDED(hr)) |
||||
{ |
||||
hr = m_controller->GetTexture(size, synchronizedTexture, textureSubRectangle); |
||||
} |
||||
|
||||
m_synchronizedTexture->EndDraw(); |
||||
} |
||||
|
||||
return hr; |
||||
} |
@ -0,0 +1,33 @@ |
||||
#pragma once |
||||
|
||||
#include "pch.h" |
||||
#include <wrl/module.h> |
||||
#include <Windows.Phone.Graphics.Interop.h> |
||||
#include <DrawingSurfaceNative.h> |
||||
|
||||
#include "Direct3DInterop.h" |
||||
|
||||
class Direct3DContentProvider : public Microsoft::WRL::RuntimeClass< |
||||
Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::WinRtClassicComMix>, |
||||
ABI::Windows::Phone::Graphics::Interop::IDrawingSurfaceContentProvider, |
||||
IDrawingSurfaceContentProviderNative> |
||||
{ |
||||
public: |
||||
Direct3DContentProvider(PhoneXamlDirect3DApp1Comp::Direct3DInterop^ controller); |
||||
|
||||
void ReleaseD3DResources(); |
||||
|
||||
// IDrawingSurfaceContentProviderNative
|
||||
HRESULT STDMETHODCALLTYPE Connect(_In_ IDrawingSurfaceRuntimeHostNative* host); |
||||
void STDMETHODCALLTYPE Disconnect(); |
||||
|
||||
HRESULT STDMETHODCALLTYPE PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty); |
||||
HRESULT STDMETHODCALLTYPE GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle); |
||||
|
||||
private: |
||||
HRESULT InitializeTexture(_In_ const DrawingSurfaceSizeF* size); |
||||
|
||||
PhoneXamlDirect3DApp1Comp::Direct3DInterop^ m_controller; |
||||
Microsoft::WRL::ComPtr<IDrawingSurfaceRuntimeHostNative> m_host; |
||||
Microsoft::WRL::ComPtr<IDrawingSurfaceSynchronizedTextureNative> m_synchronizedTexture; |
||||
}; |
@ -0,0 +1,351 @@ |
||||
#include "pch.h" |
||||
#include "Direct3DInterop.h" |
||||
#include "Direct3DContentProvider.h" |
||||
#include <windows.storage.streams.h> |
||||
#include <wrl.h> |
||||
#include <robuffer.h> |
||||
#include <opencv2\core\core.hpp> |
||||
#include <opencv2\imgproc\imgproc.hpp> |
||||
#include <opencv2\features2d\features2d.hpp> |
||||
#include <algorithm> |
||||
|
||||
using namespace Windows::Storage::Streams; |
||||
using namespace Microsoft::WRL; |
||||
using namespace Windows::Foundation; |
||||
using namespace Windows::UI::Core; |
||||
using namespace Microsoft::WRL; |
||||
using namespace Windows::Phone::Graphics::Interop; |
||||
using namespace Windows::Phone::Input::Interop; |
||||
using namespace Windows::Foundation; |
||||
using namespace Windows::Foundation::Collections; |
||||
using namespace Windows::Phone::Media::Capture; |
||||
|
||||
#if !defined(_M_ARM) |
||||
#pragma message("warning: Direct3DInterop.cpp: Windows Phone camera code does not run in the emulator.") |
||||
#pragma message("warning: Direct3DInterop.cpp: Please compile as an ARM build and run on a device.") |
||||
#endif |
||||
|
||||
namespace PhoneXamlDirect3DApp1Comp |
||||
{ |
||||
// Called each time a preview frame is available
|
||||
void CameraCapturePreviewSink::OnFrameAvailable( |
||||
DXGI_FORMAT format, |
||||
UINT width, |
||||
UINT height, |
||||
BYTE* pixels |
||||
) |
||||
{ |
||||
m_Direct3dInterop->UpdateFrame(pixels, width, height);
|
||||
} |
||||
|
||||
// Called each time a captured frame is available
|
||||
void CameraCaptureSampleSink::OnSampleAvailable( |
||||
ULONGLONG hnsPresentationTime, |
||||
ULONGLONG hnsSampleDuration, |
||||
DWORD cbSample, |
||||
BYTE* pSample) |
||||
{ |
||||
|
||||
|
||||
} |
||||
|
||||
Direct3DInterop::Direct3DInterop()
|
||||
: m_algorithm(OCVFilterType::ePreview) |
||||
, m_contentDirty(false) |
||||
, m_backFrame(nullptr) |
||||
, m_frontFrame(nullptr) |
||||
{ |
||||
} |
||||
|
||||
bool Direct3DInterop::SwapFrames() |
||||
{ |
||||
std::lock_guard<std::mutex> lock(m_mutex); |
||||
if(m_backFrame != nullptr) |
||||
{ |
||||
std::swap(m_backFrame, m_frontFrame); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
void Direct3DInterop::UpdateFrame(byte* buffer,int width,int height) |
||||
{ |
||||
std::lock_guard<std::mutex> lock(m_mutex); |
||||
if(m_backFrame == nullptr) |
||||
{ |
||||
m_backFrame = std::shared_ptr<cv::Mat> (new cv::Mat(height, width, CV_8UC4)); |
||||
m_frontFrame = std::shared_ptr<cv::Mat> (new cv::Mat(height, width, CV_8UC4)); |
||||
} |
||||
|
||||
memcpy(m_backFrame.get()->data, buffer, 4 * height*width); |
||||
m_contentDirty = true; |
||||
RequestAdditionalFrame(); |
||||
} |
||||
|
||||
void Direct3DInterop::ProcessFrame() |
||||
{ |
||||
if (SwapFrames()) |
||||
{ |
||||
if (m_renderer) |
||||
{ |
||||
cv::Mat* mat = m_frontFrame.get(); |
||||
|
||||
switch (m_algorithm) |
||||
{ |
||||
case OCVFilterType::ePreview: |
||||
{ |
||||
break; |
||||
} |
||||
|
||||
case OCVFilterType::eGray: |
||||
{ |
||||
ApplyGrayFilter(mat); |
||||
break; |
||||
} |
||||
|
||||
case OCVFilterType::eCanny: |
||||
{ |
||||
ApplyCannyFilter(mat); |
||||
break; |
||||
} |
||||
|
||||
case OCVFilterType::eBlur: |
||||
{ |
||||
ApplyBlurFilter(mat); |
||||
break; |
||||
} |
||||
|
||||
case OCVFilterType::eFindFeatures: |
||||
{ |
||||
ApplyFindFeaturesFilter(mat); |
||||
break; |
||||
} |
||||
|
||||
case OCVFilterType::eSepia: |
||||
{ |
||||
ApplySepiaFilter(mat); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
m_renderer->CreateTextureFromByte(mat->data, mat->cols, mat->rows); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void Direct3DInterop::ApplyGrayFilter(cv::Mat* mat) |
||||
{ |
||||
cv::Mat intermediateMat; |
||||
cv::cvtColor(*mat, intermediateMat, CV_RGBA2GRAY); |
||||
cv::cvtColor(intermediateMat, *mat, CV_GRAY2BGRA); |
||||
} |
||||
|
||||
void Direct3DInterop::ApplyCannyFilter(cv::Mat* mat) |
||||
{ |
||||
cv::Mat intermediateMat; |
||||
cv::Canny(*mat, intermediateMat, 80, 90); |
||||
cv::cvtColor(intermediateMat, *mat, CV_GRAY2BGRA); |
||||
} |
||||
|
||||
void Direct3DInterop::ApplyBlurFilter(cv::Mat* mat) |
||||
{ |
||||
cv::Mat intermediateMat; |
||||
// cv::Blur(image, intermediateMat, 80, 90);
|
||||
cv::cvtColor(intermediateMat, *mat, CV_GRAY2BGRA); |
||||
} |
||||
|
||||
void Direct3DInterop::ApplyFindFeaturesFilter(cv::Mat* mat) |
||||
{ |
||||
cv::Mat intermediateMat; |
||||
cv::Ptr<cv::FastFeatureDetector> detector = cv::FastFeatureDetector::create(50); |
||||
std::vector<cv::KeyPoint> features; |
||||
|
||||
cv::cvtColor(*mat, intermediateMat, CV_RGBA2GRAY); |
||||
detector->detect(intermediateMat, features); |
||||
|
||||
for( unsigned int i = 0; i < std::min(features.size(), (size_t)50); i++ ) |
||||
{ |
||||
const cv::KeyPoint& kp = features[i]; |
||||
cv::circle(*mat, cv::Point((int)kp.pt.x, (int)kp.pt.y), 10, cv::Scalar(255,0,0,255)); |
||||
} |
||||
} |
||||
|
||||
void Direct3DInterop::ApplySepiaFilter(cv::Mat* mat) |
||||
{ |
||||
const float SepiaKernelData[16] = |
||||
{ |
||||
/* B */0.131f, 0.534f, 0.272f, 0.f, |
||||
/* G */0.168f, 0.686f, 0.349f, 0.f, |
||||
/* R */0.189f, 0.769f, 0.393f, 0.f, |
||||
/* A */0.000f, 0.000f, 0.000f, 1.f |
||||
}; |
||||
|
||||
const cv::Mat SepiaKernel(4, 4, CV_32FC1, (void*)SepiaKernelData); |
||||
cv::transform(*mat, *mat, SepiaKernel); |
||||
} |
||||
|
||||
IDrawingSurfaceContentProvider^ Direct3DInterop::CreateContentProvider() |
||||
{ |
||||
ComPtr<Direct3DContentProvider> provider = Make<Direct3DContentProvider>(this); |
||||
return reinterpret_cast<IDrawingSurfaceContentProvider^>(provider.Detach()); |
||||
} |
||||
|
||||
// IDrawingSurfaceManipulationHandler
|
||||
void Direct3DInterop::SetManipulationHost(DrawingSurfaceManipulationHost^ manipulationHost) |
||||
{ |
||||
manipulationHost->PointerPressed += |
||||
ref new TypedEventHandler<DrawingSurfaceManipulationHost^, PointerEventArgs^>(this, &Direct3DInterop::OnPointerPressed); |
||||
|
||||
manipulationHost->PointerMoved += |
||||
ref new TypedEventHandler<DrawingSurfaceManipulationHost^, PointerEventArgs^>(this, &Direct3DInterop::OnPointerMoved); |
||||
|
||||
manipulationHost->PointerReleased += |
||||
ref new TypedEventHandler<DrawingSurfaceManipulationHost^, PointerEventArgs^>(this, &Direct3DInterop::OnPointerReleased); |
||||
} |
||||
|
||||
void Direct3DInterop::RenderResolution::set(Windows::Foundation::Size renderResolution) |
||||
{ |
||||
if (renderResolution.Width != m_renderResolution.Width || |
||||
renderResolution.Height != m_renderResolution.Height) |
||||
{ |
||||
m_renderResolution = renderResolution; |
||||
|
||||
if (m_renderer) |
||||
{ |
||||
m_renderer->UpdateForRenderResolutionChange(m_renderResolution.Width, m_renderResolution.Height); |
||||
RecreateSynchronizedTexture(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// Event Handlers
|
||||
|
||||
void Direct3DInterop::OnPointerPressed(DrawingSurfaceManipulationHost^ sender, PointerEventArgs^ args) |
||||
{ |
||||
// Insert your code here.
|
||||
} |
||||
|
||||
void Direct3DInterop::OnPointerMoved(DrawingSurfaceManipulationHost^ sender, PointerEventArgs^ args) |
||||
{ |
||||
// Insert your code here.
|
||||
} |
||||
|
||||
void Direct3DInterop::OnPointerReleased(DrawingSurfaceManipulationHost^ sender, PointerEventArgs^ args) |
||||
{ |
||||
// Insert your code here.
|
||||
} |
||||
|
||||
void Direct3DInterop::StartCamera() |
||||
{ |
||||
// Set the capture dimensions
|
||||
Size captureDimensions; |
||||
captureDimensions.Width = 640; |
||||
captureDimensions.Height = 480;
|
||||
|
||||
// Open the AudioVideoCaptureDevice for video only
|
||||
IAsyncOperation<AudioVideoCaptureDevice^> ^openOperation = AudioVideoCaptureDevice::OpenForVideoOnlyAsync(CameraSensorLocation::Back, captureDimensions); |
||||
|
||||
openOperation->Completed = ref new AsyncOperationCompletedHandler<AudioVideoCaptureDevice^>( |
||||
[this] (IAsyncOperation<AudioVideoCaptureDevice^> ^operation, Windows::Foundation::AsyncStatus status) |
||||
{ |
||||
if (status == Windows::Foundation::AsyncStatus::Completed) |
||||
{ |
||||
auto captureDevice = operation->GetResults(); |
||||
|
||||
// Save the reference to the opened video capture device
|
||||
pAudioVideoCaptureDevice = captureDevice; |
||||
|
||||
// Retrieve the native ICameraCaptureDeviceNative interface from the managed video capture device
|
||||
ICameraCaptureDeviceNative *iCameraCaptureDeviceNative = NULL;
|
||||
HRESULT hr = reinterpret_cast<IUnknown*>(captureDevice)->QueryInterface(__uuidof(ICameraCaptureDeviceNative), (void**) &iCameraCaptureDeviceNative); |
||||
|
||||
// Save the pointer to the native interface
|
||||
pCameraCaptureDeviceNative = iCameraCaptureDeviceNative; |
||||
|
||||
// Initialize the preview dimensions (see the accompanying article at )
|
||||
// The aspect ratio of the capture and preview resolution must be equal,
|
||||
// 4:3 for capture => 4:3 for preview, and 16:9 for capture => 16:9 for preview.
|
||||
Size previewDimensions; |
||||
previewDimensions.Width = 640; |
||||
previewDimensions.Height = 480;
|
||||
|
||||
IAsyncAction^ setPreviewResolutionAction = pAudioVideoCaptureDevice->SetPreviewResolutionAsync(previewDimensions); |
||||
setPreviewResolutionAction->Completed = ref new AsyncActionCompletedHandler( |
||||
[this](IAsyncAction^ action, Windows::Foundation::AsyncStatus status) |
||||
{ |
||||
HResult hr = action->ErrorCode; |
||||
|
||||
if (status == Windows::Foundation::AsyncStatus::Completed) |
||||
{ |
||||
// Create the sink
|
||||
MakeAndInitialize<CameraCapturePreviewSink>(&pCameraCapturePreviewSink); |
||||
pCameraCapturePreviewSink->SetDelegate(this); |
||||
pCameraCaptureDeviceNative->SetPreviewSink(pCameraCapturePreviewSink); |
||||
|
||||
// Set the preview format
|
||||
pCameraCaptureDeviceNative->SetPreviewFormat(DXGI_FORMAT::DXGI_FORMAT_B8G8R8A8_UNORM);
|
||||
} |
||||
} |
||||
); |
||||
|
||||
// Retrieve IAudioVideoCaptureDeviceNative native interface from managed projection.
|
||||
IAudioVideoCaptureDeviceNative *iAudioVideoCaptureDeviceNative = NULL; |
||||
hr = reinterpret_cast<IUnknown*>(captureDevice)->QueryInterface(__uuidof(IAudioVideoCaptureDeviceNative), (void**) &iAudioVideoCaptureDeviceNative); |
||||
|
||||
// Save the pointer to the IAudioVideoCaptureDeviceNative native interface
|
||||
pAudioVideoCaptureDeviceNative = iAudioVideoCaptureDeviceNative; |
||||
|
||||
// Set sample encoding format to ARGB. See the documentation for further values.
|
||||
pAudioVideoCaptureDevice->VideoEncodingFormat = CameraCaptureVideoFormat::Argb; |
||||
|
||||
// Initialize and set the CameraCaptureSampleSink class as sink for captures samples
|
||||
MakeAndInitialize<CameraCaptureSampleSink>(&pCameraCaptureSampleSink); |
||||
pAudioVideoCaptureDeviceNative->SetVideoSampleSink(pCameraCaptureSampleSink); |
||||
|
||||
// Start recording (only way to receive samples using the ICameraCaptureSampleSink interface
|
||||
pAudioVideoCaptureDevice->StartRecordingToSinkAsync(); |
||||
} |
||||
} |
||||
); |
||||
|
||||
} |
||||
// Interface With Direct3DContentProvider
|
||||
HRESULT Direct3DInterop::Connect(_In_ IDrawingSurfaceRuntimeHostNative* host) |
||||
{ |
||||
m_renderer = ref new QuadRenderer(); |
||||
m_renderer->Initialize(); |
||||
m_renderer->UpdateForWindowSizeChange(WindowBounds.Width, WindowBounds.Height); |
||||
m_renderer->UpdateForRenderResolutionChange(m_renderResolution.Width, m_renderResolution.Height); |
||||
StartCamera(); |
||||
|
||||
return S_OK; |
||||
} |
||||
|
||||
void Direct3DInterop::Disconnect() |
||||
{ |
||||
m_renderer = nullptr; |
||||
} |
||||
|
||||
HRESULT Direct3DInterop::PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty) |
||||
{ |
||||
*contentDirty = m_contentDirty; |
||||
if(m_contentDirty) |
||||
{ |
||||
ProcessFrame(); |
||||
} |
||||
m_contentDirty = false; |
||||
return S_OK; |
||||
} |
||||
|
||||
HRESULT Direct3DInterop::GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle) |
||||
{ |
||||
m_renderer->Update(); |
||||
m_renderer->Render(); |
||||
return S_OK; |
||||
} |
||||
|
||||
ID3D11Texture2D* Direct3DInterop::GetTexture() |
||||
{ |
||||
return m_renderer->GetTexture(); |
||||
} |
||||
} |
@ -0,0 +1,143 @@ |
||||
#pragma once |
||||
|
||||
#include "pch.h" |
||||
#include "BasicTimer.h" |
||||
#include "QuadRenderer.h" |
||||
#include <DrawingSurfaceNative.h> |
||||
#include <ppltasks.h> |
||||
#include <windows.storage.streams.h> |
||||
#include <memory> |
||||
#include <mutex> |
||||
|
||||
|
||||
#include <opencv2\imgproc\types_c.h> |
||||
|
||||
|
||||
namespace PhoneXamlDirect3DApp1Comp |
||||
{ |
||||
|
||||
public enum class OCVFilterType |
||||
{ |
||||
ePreview, |
||||
eGray, |
||||
eCanny, |
||||
eBlur, |
||||
eFindFeatures, |
||||
eSepia, |
||||
eNumOCVFilterTypes |
||||
}; |
||||
|
||||
class CameraCapturePreviewSink; |
||||
class CameraCaptureSampleSink; |
||||
|
||||
public delegate void RequestAdditionalFrameHandler(); |
||||
public delegate void RecreateSynchronizedTextureHandler(); |
||||
|
||||
[Windows::Foundation::Metadata::WebHostHidden] |
||||
public ref class Direct3DInterop sealed : public Windows::Phone::Input::Interop::IDrawingSurfaceManipulationHandler |
||||
{ |
||||
public: |
||||
Direct3DInterop(); |
||||
|
||||
Windows::Phone::Graphics::Interop::IDrawingSurfaceContentProvider^ CreateContentProvider(); |
||||
|
||||
// IDrawingSurfaceManipulationHandler
|
||||
virtual void SetManipulationHost(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ manipulationHost); |
||||
|
||||
event RequestAdditionalFrameHandler^ RequestAdditionalFrame; |
||||
event RecreateSynchronizedTextureHandler^ RecreateSynchronizedTexture; |
||||
|
||||
property Windows::Foundation::Size WindowBounds; |
||||
property Windows::Foundation::Size NativeResolution; |
||||
property Windows::Foundation::Size RenderResolution |
||||
{ |
||||
Windows::Foundation::Size get(){ return m_renderResolution; } |
||||
void set(Windows::Foundation::Size renderResolution); |
||||
} |
||||
void SetAlgorithm(OCVFilterType type) { m_algorithm = type; }; |
||||
void UpdateFrame(byte* buffer, int width, int height); |
||||
|
||||
|
||||
protected: |
||||
// Event Handlers
|
||||
void OnPointerPressed(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args); |
||||
void OnPointerMoved(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args); |
||||
void OnPointerReleased(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args); |
||||
|
||||
internal: |
||||
HRESULT STDMETHODCALLTYPE Connect(_In_ IDrawingSurfaceRuntimeHostNative* host); |
||||
void STDMETHODCALLTYPE Disconnect(); |
||||
HRESULT STDMETHODCALLTYPE PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty); |
||||
HRESULT STDMETHODCALLTYPE GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle); |
||||
ID3D11Texture2D* GetTexture(); |
||||
|
||||
private: |
||||
void StartCamera(); |
||||
void ProcessFrame(); |
||||
bool SwapFrames(); |
||||
|
||||
QuadRenderer^ m_renderer; |
||||
Windows::Foundation::Size m_renderResolution; |
||||
OCVFilterType m_algorithm; |
||||
bool m_contentDirty; |
||||
std::shared_ptr<cv::Mat> m_backFrame; |
||||
std::shared_ptr<cv::Mat> m_frontFrame; |
||||
std::mutex m_mutex; |
||||
|
||||
Windows::Phone::Media::Capture::AudioVideoCaptureDevice ^pAudioVideoCaptureDevice; |
||||
ICameraCaptureDeviceNative* pCameraCaptureDeviceNative; |
||||
IAudioVideoCaptureDeviceNative* pAudioVideoCaptureDeviceNative; |
||||
CameraCapturePreviewSink* pCameraCapturePreviewSink; |
||||
CameraCaptureSampleSink* pCameraCaptureSampleSink; |
||||
|
||||
//void ApplyPreviewFilter(const cv::Mat& image);
|
||||
void ApplyGrayFilter(cv::Mat* mat); |
||||
void ApplyCannyFilter(cv::Mat* mat); |
||||
void ApplyBlurFilter(cv::Mat* mat); |
||||
void ApplyFindFeaturesFilter(cv::Mat* mat); |
||||
void ApplySepiaFilter(cv::Mat* mat); |
||||
}; |
||||
|
||||
class CameraCapturePreviewSink : |
||||
public Microsoft::WRL::RuntimeClass< |
||||
Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>, |
||||
ICameraCapturePreviewSink> |
||||
{ |
||||
public: |
||||
void SetDelegate(Direct3DInterop^ delegate) |
||||
{ |
||||
m_Direct3dInterop = delegate; |
||||
} |
||||
|
||||
IFACEMETHODIMP_(void) OnFrameAvailable( |
||||
DXGI_FORMAT format, |
||||
UINT width, |
||||
UINT height, |
||||
BYTE* pixels); |
||||
|
||||
private: |
||||
Direct3DInterop^ m_Direct3dInterop; |
||||
}; |
||||
|
||||
class CameraCaptureSampleSink : |
||||
public Microsoft::WRL::RuntimeClass< |
||||
Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::RuntimeClassType::ClassicCom>, |
||||
ICameraCaptureSampleSink> |
||||
{ |
||||
public: |
||||
void SetDelegate(Direct3DInterop^ delegate) |
||||
{ |
||||
m_Direct3dInterop = delegate; |
||||
} |
||||
|
||||
IFACEMETHODIMP_(void) OnSampleAvailable( |
||||
ULONGLONG hnsPresentationTime, |
||||
ULONGLONG hnsSampleDuration, |
||||
DWORD cbSample, |
||||
BYTE* pSample); |
||||
|
||||
private: |
||||
Direct3DInterop^ m_Direct3dInterop; |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,25 @@ |
||||
Texture2D shaderTexture; |
||||
SamplerState SampleType; |
||||
|
||||
////////////// |
||||
// TYPEDEFS // |
||||
////////////// |
||||
struct PixelInputType |
||||
{ |
||||
float4 position : SV_POSITION; |
||||
float2 tex : TEXCOORD0; |
||||
}; |
||||
|
||||
//////////////////////////////////////////////////////////////////////////////// |
||||
// Pixel Shader |
||||
//////////////////////////////////////////////////////////////////////////////// |
||||
float4 main(PixelInputType input) : SV_TARGET |
||||
{ |
||||
float4 textureColor; |
||||
|
||||
|
||||
// Sample the pixel color from the texture using the sampler at this texture coordinate location. |
||||
textureColor = shaderTexture.Sample(SampleType, input.tex); |
||||
|
||||
return textureColor; |
||||
} |
@ -0,0 +1,39 @@ |
||||
cbuffer ModelViewProjectionConstantBuffer : register(b0) |
||||
{ |
||||
matrix model; |
||||
matrix view; |
||||
matrix projection; |
||||
}; |
||||
|
||||
struct VertexInputType |
||||
{ |
||||
float4 position : POSITION; |
||||
float2 tex : TEXCOORD0; |
||||
}; |
||||
|
||||
struct PixelInputType |
||||
{ |
||||
float4 position : SV_POSITION; |
||||
float2 tex : TEXCOORD0; |
||||
}; |
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////// |
||||
// Vertex Shader |
||||
//////////////////////////////////////////////////////////////////////////////// |
||||
PixelInputType main(VertexInputType input) |
||||
{ |
||||
PixelInputType output; |
||||
|
||||
// Change the position vector to be 4 units for proper matrix calculations. |
||||
input.position.w = 1.0f; |
||||
|
||||
// Calculate the position of the vertex against the world, view, and projection matrices. |
||||
output.position = mul(input.position, model); |
||||
output.position = mul(output.position, view); |
||||
output.position = mul(output.position, projection); |
||||
// Store the texture coordinates for the pixel shader. |
||||
output.tex = input.tex; |
||||
|
||||
return output; |
||||
} |
After Width: | Height: | Size: 8.8 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 483 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 4.8 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 118 KiB |
@ -0,0 +1,77 @@ |
||||
#include "pch.h" |
||||
#include "Direct3DContentProvider.h" |
||||
|
||||
using namespace PhoneXamlDirect3DApp1Comp; |
||||
|
||||
Direct3DContentProvider::Direct3DContentProvider(Direct3DInterop^ controller) : |
||||
m_controller(controller) |
||||
{ |
||||
m_controller->RequestAdditionalFrame += ref new RequestAdditionalFrameHandler([=] () |
||||
{ |
||||
if (m_host) |
||||
{ |
||||
m_host->RequestAdditionalFrame(); |
||||
} |
||||
}); |
||||
|
||||
m_controller->RecreateSynchronizedTexture += ref new RecreateSynchronizedTextureHandler([=] () |
||||
{ |
||||
if (m_host) |
||||
{ |
||||
m_host->CreateSynchronizedTexture(m_controller->GetTexture(), &m_synchronizedTexture); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
// IDrawingSurfaceContentProviderNative interface
|
||||
HRESULT Direct3DContentProvider::Connect(_In_ IDrawingSurfaceRuntimeHostNative* host) |
||||
{ |
||||
m_host = host; |
||||
|
||||
return m_controller->Connect(host); |
||||
} |
||||
|
||||
void Direct3DContentProvider::Disconnect() |
||||
{ |
||||
m_controller->Disconnect(); |
||||
m_host = nullptr; |
||||
m_synchronizedTexture = nullptr; |
||||
} |
||||
|
||||
HRESULT Direct3DContentProvider::PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty) |
||||
{ |
||||
return m_controller->PrepareResources(presentTargetTime, contentDirty); |
||||
} |
||||
|
||||
HRESULT Direct3DContentProvider::GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle) |
||||
{ |
||||
HRESULT hr = S_OK; |
||||
|
||||
if (!m_synchronizedTexture) |
||||
{ |
||||
hr = m_host->CreateSynchronizedTexture(m_controller->GetTexture(), &m_synchronizedTexture); |
||||
} |
||||
|
||||
// Set output parameters.
|
||||
textureSubRectangle->left = 0.0f; |
||||
textureSubRectangle->top = 0.0f; |
||||
textureSubRectangle->right = static_cast<FLOAT>(size->width); |
||||
textureSubRectangle->bottom = static_cast<FLOAT>(size->height); |
||||
|
||||
m_synchronizedTexture.CopyTo(synchronizedTexture); |
||||
|
||||
// Draw to the texture.
|
||||
if (SUCCEEDED(hr)) |
||||
{ |
||||
hr = m_synchronizedTexture->BeginDraw(); |
||||
|
||||
if (SUCCEEDED(hr)) |
||||
{ |
||||
hr = m_controller->GetTexture(size, synchronizedTexture, textureSubRectangle); |
||||
} |
||||
|
||||
m_synchronizedTexture->EndDraw(); |
||||
} |
||||
|
||||
return hr; |
||||
} |
@ -0,0 +1,33 @@ |
||||
#pragma once |
||||
|
||||
#include "pch.h" |
||||
#include <wrl/module.h> |
||||
#include <Windows.Phone.Graphics.Interop.h> |
||||
#include <DrawingSurfaceNative.h> |
||||
|
||||
#include "Direct3DInterop.h" |
||||
|
||||
class Direct3DContentProvider : public Microsoft::WRL::RuntimeClass< |
||||
Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::WinRtClassicComMix>, |
||||
ABI::Windows::Phone::Graphics::Interop::IDrawingSurfaceContentProvider, |
||||
IDrawingSurfaceContentProviderNative> |
||||
{ |
||||
public: |
||||
Direct3DContentProvider(PhoneXamlDirect3DApp1Comp::Direct3DInterop^ controller); |
||||
|
||||
void ReleaseD3DResources(); |
||||
|
||||
// IDrawingSurfaceContentProviderNative
|
||||
HRESULT STDMETHODCALLTYPE Connect(_In_ IDrawingSurfaceRuntimeHostNative* host); |
||||
void STDMETHODCALLTYPE Disconnect(); |
||||
|
||||
HRESULT STDMETHODCALLTYPE PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty); |
||||
HRESULT STDMETHODCALLTYPE GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle); |
||||
|
||||
private: |
||||
HRESULT InitializeTexture(_In_ const DrawingSurfaceSizeF* size); |
||||
|
||||
PhoneXamlDirect3DApp1Comp::Direct3DInterop^ m_controller; |
||||
Microsoft::WRL::ComPtr<IDrawingSurfaceRuntimeHostNative> m_host; |
||||
Microsoft::WRL::ComPtr<IDrawingSurfaceSynchronizedTextureNative> m_synchronizedTexture; |
||||
}; |
@ -0,0 +1,186 @@ |
||||
#include "pch.h" |
||||
#include "Direct3DInterop.h" |
||||
#include "Direct3DContentProvider.h" |
||||
#include <windows.storage.streams.h> |
||||
#include <wrl.h> |
||||
#include <robuffer.h> |
||||
#include <opencv2\imgproc\types_c.h> |
||||
|
||||
using namespace Windows::Storage::Streams; |
||||
using namespace Microsoft::WRL; |
||||
using namespace Windows::Foundation; |
||||
using namespace Windows::UI::Core; |
||||
using namespace Microsoft::WRL; |
||||
using namespace Windows::Phone::Graphics::Interop; |
||||
using namespace Windows::Phone::Input::Interop; |
||||
|
||||
namespace PhoneXamlDirect3DApp1Comp |
||||
{ |
||||
void Direct3DInterop::ApplyGrayFilter(const cv::Mat& image) |
||||
{ |
||||
cv::Mat intermediateMat; |
||||
cv::cvtColor(image, intermediateMat, CV_RGBA2GRAY); |
||||
cv::cvtColor(intermediateMat, image, CV_GRAY2BGRA); |
||||
} |
||||
|
||||
void Direct3DInterop::ApplyCannyFilter(const cv::Mat& image) |
||||
{ |
||||
cv::Mat intermediateMat; |
||||
cv::Canny(image, intermediateMat, 80, 90); |
||||
cv::cvtColor(intermediateMat, image, CV_GRAY2BGRA); |
||||
} |
||||
|
||||
void Direct3DInterop::ApplySepiaFilter(const cv::Mat& image) |
||||
{ |
||||
const float SepiaKernelData[16] = |
||||
{ |
||||
/* B */0.131f, 0.534f, 0.272f, 0.f, |
||||
/* G */0.168f, 0.686f, 0.349f, 0.f, |
||||
/* R */0.189f, 0.769f, 0.393f, 0.f, |
||||
/* A */0.000f, 0.000f, 0.000f, 1.f |
||||
}; |
||||
|
||||
const cv::Mat SepiaKernel(4, 4, CV_32FC1, (void*)SepiaKernelData); |
||||
cv::transform(image, image, SepiaKernel); |
||||
} |
||||
|
||||
Direct3DInterop::Direct3DInterop() : |
||||
m_timer(ref new BasicTimer()) |
||||
{ |
||||
} |
||||
|
||||
IDrawingSurfaceContentProvider^ Direct3DInterop::CreateContentProvider() |
||||
{ |
||||
ComPtr<Direct3DContentProvider> provider = Make<Direct3DContentProvider>(this); |
||||
return reinterpret_cast<IDrawingSurfaceContentProvider^>(provider.Detach()); |
||||
} |
||||
|
||||
// IDrawingSurfaceManipulationHandler
|
||||
void Direct3DInterop::SetManipulationHost(DrawingSurfaceManipulationHost^ manipulationHost) |
||||
{ |
||||
manipulationHost->PointerPressed += |
||||
ref new TypedEventHandler<DrawingSurfaceManipulationHost^, PointerEventArgs^>(this, &Direct3DInterop::OnPointerPressed); |
||||
|
||||
manipulationHost->PointerMoved += |
||||
ref new TypedEventHandler<DrawingSurfaceManipulationHost^, PointerEventArgs^>(this, &Direct3DInterop::OnPointerMoved); |
||||
|
||||
manipulationHost->PointerReleased += |
||||
ref new TypedEventHandler<DrawingSurfaceManipulationHost^, PointerEventArgs^>(this, &Direct3DInterop::OnPointerReleased); |
||||
} |
||||
|
||||
void Direct3DInterop::RenderResolution::set(Windows::Foundation::Size renderResolution) |
||||
{ |
||||
if (renderResolution.Width != m_renderResolution.Width || |
||||
renderResolution.Height != m_renderResolution.Height) |
||||
{ |
||||
m_renderResolution = renderResolution; |
||||
|
||||
if (m_renderer) |
||||
{ |
||||
m_renderer->UpdateForRenderResolutionChange(m_renderResolution.Width, m_renderResolution.Height); |
||||
RecreateSynchronizedTexture(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
// Event Handlers
|
||||
|
||||
void Direct3DInterop::OnPointerPressed(DrawingSurfaceManipulationHost^ sender, PointerEventArgs^ args) |
||||
{ |
||||
// Insert your code here.
|
||||
} |
||||
|
||||
void Direct3DInterop::OnPointerMoved(DrawingSurfaceManipulationHost^ sender, PointerEventArgs^ args) |
||||
{ |
||||
// Insert your code here.
|
||||
} |
||||
|
||||
void Direct3DInterop::OnPointerReleased(DrawingSurfaceManipulationHost^ sender, PointerEventArgs^ args) |
||||
{ |
||||
// Insert your code here.
|
||||
} |
||||
|
||||
// Interface With Direct3DContentProvider
|
||||
HRESULT Direct3DInterop::Connect(_In_ IDrawingSurfaceRuntimeHostNative* host) |
||||
{ |
||||
m_renderer = ref new CubeRenderer(); |
||||
m_renderer->Initialize(); |
||||
m_renderer->UpdateForWindowSizeChange(WindowBounds.Width, WindowBounds.Height); |
||||
m_renderer->UpdateForRenderResolutionChange(m_renderResolution.Width, m_renderResolution.Height); |
||||
|
||||
// Restart timer after renderer has finished initializing.
|
||||
m_timer->Reset(); |
||||
|
||||
return S_OK; |
||||
} |
||||
|
||||
void Direct3DInterop::Disconnect() |
||||
{ |
||||
m_renderer = nullptr; |
||||
} |
||||
|
||||
HRESULT Direct3DInterop::PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty) |
||||
{ |
||||
*contentDirty = true; |
||||
|
||||
return S_OK; |
||||
} |
||||
|
||||
HRESULT Direct3DInterop::GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle) |
||||
{ |
||||
m_timer->Update(); |
||||
m_renderer->Update(m_timer->Total, m_timer->Delta); |
||||
m_renderer->Render(); |
||||
|
||||
RequestAdditionalFrame(); |
||||
|
||||
return S_OK; |
||||
} |
||||
|
||||
ID3D11Texture2D* Direct3DInterop::GetTexture() |
||||
{ |
||||
return m_renderer->GetTexture(); |
||||
} |
||||
|
||||
void Direct3DInterop::CreateTexture(const Platform::Array<int>^ buffer,int width,int height, OCVFilterType filter) |
||||
{ |
||||
if (m_renderer) |
||||
{
|
||||
cv::Mat Lena = cv::Mat(height, width, CV_8UC4); |
||||
memcpy(Lena.data, buffer->Data, 4 * height*width); |
||||
|
||||
switch (filter) |
||||
{ |
||||
case OCVFilterType::ePreview:
|
||||
break; |
||||
|
||||
case OCVFilterType::eGray: |
||||
ApplyGrayFilter(Lena); |
||||
break; |
||||
|
||||
case OCVFilterType::eCanny: |
||||
ApplyCannyFilter(Lena); |
||||
break; |
||||
|
||||
case OCVFilterType::eSepia: |
||||
ApplySepiaFilter(Lena); |
||||
break; |
||||
} |
||||
|
||||
m_renderer->CreateTextureFromByte(Lena.data, width, height); |
||||
} |
||||
} |
||||
|
||||
byte* GetPointerToPixelData( Windows::Storage::Streams::IBuffer ^ pixelBuffer) |
||||
{ |
||||
// Query the IBufferByteAccess interface.
|
||||
ComPtr<IBufferByteAccess> bufferByteAccess; |
||||
reinterpret_cast<IInspectable*>( pixelBuffer)->QueryInterface(IID_PPV_ARGS(&bufferByteAccess)); |
||||
|
||||
// Retrieve the buffer data.
|
||||
byte* pixels = nullptr; |
||||
bufferByteAccess->Buffer(&pixels); |
||||
return pixels; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,80 @@ |
||||
#pragma once |
||||
|
||||
#include "pch.h" |
||||
#include "BasicTimer.h" |
||||
#include "CubeRenderer.h" |
||||
#include <DrawingSurfaceNative.h> |
||||
#include <ppltasks.h> |
||||
#include <windows.storage.streams.h> |
||||
#include <opencv2\core\core.hpp> |
||||
#include <opencv2\imgproc\imgproc.hpp> |
||||
#include <opencv2\features2d\features2d.hpp> |
||||
|
||||
namespace PhoneXamlDirect3DApp1Comp |
||||
{ |
||||
|
||||
public enum class OCVFilterType |
||||
{ |
||||
ePreview, |
||||
eGray, |
||||
eCanny, |
||||
eSepia, |
||||
eNumOCVFilterTypes |
||||
}; |
||||
|
||||
public delegate void RequestAdditionalFrameHandler(); |
||||
public delegate void RecreateSynchronizedTextureHandler(); |
||||
|
||||
[Windows::Foundation::Metadata::WebHostHidden] |
||||
public ref class Direct3DInterop sealed : public Windows::Phone::Input::Interop::IDrawingSurfaceManipulationHandler |
||||
{ |
||||
public: |
||||
Direct3DInterop(); |
||||
|
||||
Windows::Phone::Graphics::Interop::IDrawingSurfaceContentProvider^ CreateContentProvider(); |
||||
|
||||
// IDrawingSurfaceManipulationHandler
|
||||
virtual void SetManipulationHost(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ manipulationHost); |
||||
|
||||
event RequestAdditionalFrameHandler^ RequestAdditionalFrame; |
||||
event RecreateSynchronizedTextureHandler^ RecreateSynchronizedTexture; |
||||
|
||||
property Windows::Foundation::Size WindowBounds; |
||||
property Windows::Foundation::Size NativeResolution; |
||||
property Windows::Foundation::Size RenderResolution |
||||
{ |
||||
Windows::Foundation::Size get(){ return m_renderResolution; } |
||||
void set(Windows::Foundation::Size renderResolution); |
||||
} |
||||
void CreateTexture(const Platform::Array<int>^ buffer, int with, int height, OCVFilterType filter); |
||||
|
||||
|
||||
protected: |
||||
// Event Handlers
|
||||
void OnPointerPressed(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args); |
||||
void OnPointerMoved(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args); |
||||
void OnPointerReleased(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args); |
||||
|
||||
internal: |
||||
HRESULT STDMETHODCALLTYPE Connect(_In_ IDrawingSurfaceRuntimeHostNative* host); |
||||
void STDMETHODCALLTYPE Disconnect(); |
||||
HRESULT STDMETHODCALLTYPE PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty); |
||||
HRESULT STDMETHODCALLTYPE GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle); |
||||
ID3D11Texture2D* GetTexture(); |
||||
|
||||
private: |
||||
CubeRenderer^ m_renderer; |
||||
BasicTimer^ m_timer; |
||||
Windows::Foundation::Size m_renderResolution; |
||||
|
||||
void ApplyGrayFilter(const cv::Mat& image); |
||||
void ApplyCannyFilter(const cv::Mat& image); |
||||
void ApplySepiaFilter(const cv::Mat& image); |
||||
|
||||
void UpdateImage(const cv::Mat& image); |
||||
|
||||
cv::Mat Lena; |
||||
unsigned int frameWidth, frameHeight; |
||||
}; |
||||
|
||||
} |
@ -0,0 +1,25 @@ |
||||
Texture2D shaderTexture; |
||||
SamplerState SampleType; |
||||
|
||||
////////////// |
||||
// TYPEDEFS // |
||||
////////////// |
||||
struct PixelInputType |
||||
{ |
||||
float4 position : SV_POSITION; |
||||
float2 tex : TEXCOORD0; |
||||
}; |
||||
|
||||
//////////////////////////////////////////////////////////////////////////////// |
||||
// Pixel Shader |
||||
//////////////////////////////////////////////////////////////////////////////// |
||||
float4 main(PixelInputType input) : SV_TARGET |
||||
{ |
||||
float4 textureColor; |
||||
|
||||
|
||||
// Sample the pixel color from the texture using the sampler at this texture coordinate location. |
||||
textureColor = shaderTexture.Sample(SampleType, input.tex); |
||||
|
||||
return textureColor; |
||||
} |
@ -0,0 +1,39 @@ |
||||
cbuffer ModelViewProjectionConstantBuffer : register(b0) |
||||
{ |
||||
matrix model; |
||||
matrix view; |
||||
matrix projection; |
||||
}; |
||||
|
||||
struct VertexInputType |
||||
{ |
||||
float4 position : POSITION; |
||||
float2 tex : TEXCOORD0; |
||||
}; |
||||
|
||||
struct PixelInputType |
||||
{ |
||||
float4 position : SV_POSITION; |
||||
float2 tex : TEXCOORD0; |
||||
}; |
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////// |
||||
// Vertex Shader |
||||
//////////////////////////////////////////////////////////////////////////////// |
||||
PixelInputType main(VertexInputType input) |
||||
{ |
||||
PixelInputType output; |
||||
|
||||
// Change the position vector to be 4 units for proper matrix calculations. |
||||
input.position.w = 1.0f; |
||||
|
||||
// Calculate the position of the vertex against the world, view, and projection matrices. |
||||
output.position = mul(input.position, model); |
||||
output.position = mul(output.position, view); |
||||
output.position = mul(output.position, projection); |
||||
// Store the texture coordinates for the pixel shader. |
||||
output.tex = input.tex; |
||||
|
||||
return output; |
||||
} |
After Width: | Height: | Size: 8.8 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 483 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 4.8 KiB |
After Width: | Height: | Size: 3.6 KiB |
@ -0,0 +1,6 @@ |
||||
Building OpenCV Windows Phone Samples |
||||
===================================== |
||||
|
||||
Samples are created to run against x86 architecture OpenCV binaries. |
||||
|
||||
Please follow the instructions in "platforms/winrt/readme.txt" to generate and build OpenCV for Windows Phone 8.0/8.1 |