Commit 2cfd635e authored by Alexander Smorkalov's avatar Alexander Smorkalov

Image processing sample for WinRT added.

parent d5ead208

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OcvImageProcessing", "OcvImageProcessing\OcvImageProcessing.vcxproj", "{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|ARM = Release|ARM
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Debug|ARM.ActiveCfg = Debug|ARM
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Debug|ARM.Build.0 = Debug|ARM
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Debug|ARM.Deploy.0 = Debug|ARM
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Debug|Win32.ActiveCfg = Debug|Win32
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Debug|Win32.Build.0 = Debug|Win32
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Debug|Win32.Deploy.0 = Debug|Win32
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Debug|x64.ActiveCfg = Debug|x64
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Debug|x64.Build.0 = Debug|x64
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Debug|x64.Deploy.0 = Debug|x64
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Release|ARM.ActiveCfg = Release|ARM
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Release|ARM.Build.0 = Release|ARM
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Release|ARM.Deploy.0 = Release|ARM
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Release|Win32.ActiveCfg = Release|Win32
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Release|Win32.Build.0 = Release|Win32
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Release|Win32.Deploy.0 = Release|Win32
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Release|x64.ActiveCfg = Release|x64
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Release|x64.Build.0 = Release|x64
{A5555EA2-F9E8-4078-90F5-D428F2C0D6D1}.Release|x64.Deploy.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
<Application
x:Class="OcvImageProcessing.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:OcvImageProcessing">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--
Styles that define common aspects of the platform look and feel
Required by Visual Studio project and item templates
-->
<ResourceDictionary Source="Common/StandardStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
//
// App.xaml.cpp
// Implementation of the App class.
//
#include "pch.h"
#include "MainPage.xaml.h"
using namespace OcvImageProcessing;
using namespace Platform;
using namespace Windows::ApplicationModel;
using namespace Windows::ApplicationModel::Activation;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Interop;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
App::App()
{
InitializeComponent();
Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
}
/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used when the application is launched to open a specific file, to display
/// search results, and so forth.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ args)
{
auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content);
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == nullptr)
{
// Create a Frame to act as the navigation context and associate it with
// a SuspensionManager key
rootFrame = ref new Frame();
if (args->PreviousExecutionState == ApplicationExecutionState::Terminated)
{
// TODO: Restore the saved session state only when appropriate, scheduling the
// final launch steps after the restore is complete
}
if (rootFrame->Content == nullptr)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (!rootFrame->Navigate(TypeName(MainPage::typeid), args->Arguments))
{
throw ref new FailureException("Failed to create initial page");
}
}
// Place the frame in the current Window
Window::Current->Content = rootFrame;
// Ensure the current window is active
Window::Current->Activate();
}
else
{
if (rootFrame->Content == nullptr)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (!rootFrame->Navigate(TypeName(MainPage::typeid), args->Arguments))
{
throw ref new FailureException("Failed to create initial page");
}
}
// Ensure the current window is active
Window::Current->Activate();
}
}
/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)
{
(void) sender; // Unused parameter
(void) e; // Unused parameter
//TODO: Save application state and stop any background activity
}
//
// App.xaml.h
// Declaration of the App class.
//
#pragma once
#include "App.g.h"
namespace OcvImageProcessing
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
ref class App sealed
{
public:
App();
virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ args) override;
private:
void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e);
};
}
This source diff could not be displayed because it is too large. You can view the blob instead.
<Page
x:Class="OcvImageProcessing.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:OcvImageProcessing"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Image x:Name="PreviewWidget" HorizontalAlignment="Left" Height="748" Margin="10,10,0,0" VerticalAlignment="Top" Width="1146"/>
<Button Content="Button" HorizontalAlignment="Left" Margin="1161,10,0,0" VerticalAlignment="Top" Width="195" Height="63" Click="Button_Click"/>
</Grid>
</Page>
//
// MainPage.xaml.cpp
// Implementation of the MainPage class.
//
#include "pch.h"
#include "MainPage.xaml.h"
#include <ppltasks.h>
#include <wrl\client.h>
#include <Robuffer.h>
using namespace OcvImageProcessing;
using namespace Microsoft::WRL;
using namespace concurrency;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Storage::Streams;
using namespace Windows::UI::Xaml::Media::Imaging;
using namespace Windows::Graphics::Imaging;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Input;
using namespace Windows::UI::Xaml::Media;
using namespace Windows::UI::Xaml::Navigation;
#include <opencv2\core\core.hpp>
#include <opencv2\imgproc\imgproc.hpp>
Uri^ InputImageUri = ref new Uri(L"ms-appx:///Assets/Lena.png");
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
MainPage::MainPage()
{
InitializeComponent();
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
void MainPage::OnNavigatedTo(NavigationEventArgs^ e)
{
(void) e; // Unused parameter
}
void OcvImageProcessing::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
RandomAccessStreamReference^ streamRef = RandomAccessStreamReference::CreateFromUri(InputImageUri);
task<IRandomAccessStreamWithContentType^> (streamRef->OpenReadAsync()).
then([](task<IRandomAccessStreamWithContentType^> thisTask)
{
IRandomAccessStreamWithContentType^ fileStream = thisTask.get();
return BitmapDecoder::CreateAsync(fileStream);
}).
then([](task<BitmapDecoder^> thisTask)
{
BitmapDecoder^ decoder = thisTask.get();
return decoder->GetFrameAsync(0);
}).
then([this](task<BitmapFrame^> thisTask)
{
BitmapFrame^ frame = thisTask.get();
// Save some information as fields
frameWidth = frame->PixelWidth;
frameHeight = frame->PixelHeight;
return frame->GetPixelDataAsync();
}).
then([this](task<PixelDataProvider^> thisTask)
{
PixelDataProvider^ pixelProvider = thisTask.get();
Platform::Array<byte>^ srcPixels = pixelProvider->DetachPixelData();
cv::Mat inputImage(frameHeight, frameWidth, CV_8UC4, srcPixels->Data);
unsigned char* dstPixels;
// Create the WriteableBitmap
WriteableBitmap^ bitmap = ref new WriteableBitmap(frameWidth, frameHeight);
// Get access to the pixels
IBuffer^ buffer = bitmap->PixelBuffer;
// Obtain IBufferByteAccess
ComPtr<IBufferByteAccess> pBufferByteAccess;
ComPtr<IUnknown> pBuffer((IUnknown*)buffer);
pBuffer.As(&pBufferByteAccess);
// Get pointer to pixel bytes
pBufferByteAccess->Buffer(&dstPixels);
cv::Mat outputImage(frameHeight, frameWidth, CV_8UC4, dstPixels);
cv::Mat intermediateMat;
cv::Canny(inputImage, intermediateMat, 80, 90);
cv::cvtColor(intermediateMat, outputImage, CV_GRAY2BGRA);
//cv::blur(inputImage, outputImage, cv::Size(3,3));
// Set the bitmap to the Image element
PreviewWidget->Source = bitmap;
});
}
//
// MainPage.xaml.h
// Declaration of the MainPage class.
//
#pragma once
#include "MainPage.g.h"
namespace OcvImageProcessing
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public ref class MainPage sealed
{
public:
MainPage();
protected:
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
private:
void Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
unsigned int frameWidth, frameHeight;
};
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Common">
<UniqueIdentifier>a5555ea2-f9e8-4078-90f5-d428f2c0d6d1</UniqueIdentifier>
</Filter>
<Filter Include="Assets">
<UniqueIdentifier>714bc2d8-fb65-4062-80fa-4d1822fe24e2</UniqueIdentifier>
</Filter>
<Page Include="Common\StandardStyles.xaml">
<Filter>Common</Filter>
</Page>
<Image Include="Assets\Logo.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\SmallLogo.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\StoreLogo.png">
<Filter>Assets</Filter>
</Image>
<Image Include="Assets\SplashScreen.png">
<Filter>Assets</Filter>
</Image>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="App.xaml.cpp" />
<ClCompile Include="MainPage.xaml.cpp" />
<ClCompile Include="pch.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="App.xaml.h" />
<ClInclude Include="MainPage.xaml.h" />
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest" />
</ItemGroup>
<ItemGroup>
<None Include="OcvImageProcessing_TemporaryKey.pfx" />
<None Include="..\..\opencv\build\install\bin\opencv_core246.dll" />
<None Include="..\..\opencv\build\install\bin\opencv_imgproc246.dll" />
</ItemGroup>
<ItemGroup>
<Page Include="MainPage.xaml" />
</ItemGroup>
<ItemGroup>
<Image Include="Assets\Lena.png">
<Filter>Assets</Filter>
</Image>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/2010/manifest">
<Identity Name="96635370-3751-48a8-84a6-afd4229cf435"
Publisher="CN=asmorkalov"
Version="1.0.0.0" />
<Properties>
<DisplayName>OcvImageProcessing</DisplayName>
<PublisherDisplayName>asmorkalov</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Prerequisites>
<OSMinVersion>6.2.1</OSMinVersion>
<OSMaxVersionTested>6.2.1</OSMaxVersionTested>
</Prerequisites>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="OcvImageProcessing.App">
<VisualElements
DisplayName="OcvImageProcessing"
Logo="Assets\Logo.png"
SmallLogo="Assets\SmallLogo.png"
Description="OcvImageProcessing"
ForegroundText="light"
BackgroundColor="#464646">
<DefaultTile ShowName="allLogos" />
<SplashScreen Image="Assets\SplashScreen.png" />
</VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
</Capabilities>
</Package>
\ No newline at end of file
//
// pch.cpp
// Include the standard header and generate the precompiled header.
//
#include "pch.h"
//
// pch.h
// Header for standard system include files.
//
#pragma once
#include <collection.h>
#include "App.xaml.h"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment