Windows RT sample updated.
Unused scenarious removed. Grey scale convertion replaced with cv::Canny call.
This commit is contained in:
parent
4990336760
commit
9e06287121
@ -3,4 +3,4 @@ cd build
|
||||
|
||||
rem call "C:\Program Files\Microsoft Visual Studio 11.0\VC\bin\x86_arm\vcvarsx86_arm.bat"
|
||||
|
||||
cmake.exe -GNinja -DCMAKE_BUILD_TYPE=Release -DWITH_FFMPEG=OFF -DBUILD_opencv_gpu=OFF -DBUILD_opencv_python=OFF -DCMAKE_TOOLCHAIN_FILE=..\..\winrt\arm.winrt.toolchain.cmake ..\..\..
|
||||
cmake.exe -GNinja -DWITH_TBB=ON -DBUILD_TBB=ON -DCMAKE_BUILD_TYPE=Release -DWITH_FFMPEG=OFF -DBUILD_opencv_gpu=OFF -DBUILD_opencv_python=OFF -DCMAKE_TOOLCHAIN_FILE=..\..\winrt\arm.winrt.toolchain.cmake ..\..\..
|
||||
|
@ -3,4 +3,15 @@ set(CMAKE_SYSTEM_PROCESSOR "arm-v7a")
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH "${CMAKE_SOURCE_DIR}/platforms/winrt")
|
||||
set(CMAKE_REQUIRED_DEFINITIONS -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE)
|
||||
add_definitions(-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE)
|
||||
add_definitions(-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags")
|
||||
set(CMAKE_C_FLAGS "" CACHE STRING "c flags")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ZW -EHsc -GS")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -GS")
|
||||
|
||||
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "/r:System.Runtime.WindowsRuntime.dll /r:System.Threading.Tasks.dll" CACHE STRING "shared linker flags")
|
||||
set(CMAKE_MODULE_LINKER_FLAGS "/r:System.Runtime.WindowsRuntime.dll /r:System.Threading.Tasks.dll" CACHE STRING "module linker flags")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "/r:System.Runtime.WindowsRuntime.dll /r:System.Threading.Tasks.dll" CACHE STRING "executable linker flags")
|
@ -1,62 +0,0 @@
|
||||
<!--
|
||||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
|
||||
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
|
||||
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
|
||||
//
|
||||
//*********************************************************
|
||||
-->
|
||||
|
||||
<common:LayoutAwarePage
|
||||
x:Class="SDKSample.MediaCapture.AudioCapture"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:$rootsnamespace$"
|
||||
xmlns:common="using:SDKSample.Common"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid x:Name="Input" Grid.Row="0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock x:Name="InputTextBlock1" TextWrapping="Wrap" Grid.Row="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" >
|
||||
This scenario shows how to do an audio only capture using the default microphone. Click on StartRecord to start recording.
|
||||
</TextBlock>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,10,0,0" Grid.Row="1">
|
||||
<Button x:Name="btnStartDevice3" Click="btnStartDevice_Click" IsEnabled="true" Margin="0,0,10,0">StartDevice</Button>
|
||||
<Button x:Name="btnStartStopRecord3" Click="btnStartStopRecord_Click" IsEnabled="false" Margin="0,0,10,0">StartRecord</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<Grid x:Name="Output" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1">
|
||||
<StackPanel>
|
||||
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Captured Audio' />
|
||||
<Canvas x:Name='playbackCanvas3' Width='320' Height ='240' >
|
||||
<MediaElement x:Name='playbackElement3' Width="320" Height="240" Margin="10,5,10,5"/>
|
||||
</Canvas>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<!-- Add Storyboards to the visual states below as necessary for supporting the various layouts -->
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup>
|
||||
<VisualState x:Name="FullScreenLandscape"/>
|
||||
<VisualState x:Name="Filled"/>
|
||||
<VisualState x:Name="FullScreenPortrait"/>
|
||||
<VisualState x:Name="Snapped"/>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Grid>
|
||||
|
||||
</common:LayoutAwarePage>
|
@ -1,366 +0,0 @@
|
||||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
|
||||
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
|
||||
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
|
||||
//
|
||||
//*********************************************************
|
||||
|
||||
//
|
||||
// AudioCapture.xaml.cpp
|
||||
// Implementation of the AudioCapture class
|
||||
//
|
||||
|
||||
#include "pch.h"
|
||||
#include "AudioCapture.xaml.h"
|
||||
#include <ppl.h>
|
||||
using namespace concurrency;
|
||||
|
||||
using namespace SDKSample::MediaCapture;
|
||||
|
||||
using namespace Windows::UI::Xaml;
|
||||
using namespace Windows::UI::Xaml::Navigation;
|
||||
using namespace Windows::UI::Xaml::Data;
|
||||
using namespace Windows::System;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Platform;
|
||||
using namespace Windows::UI;
|
||||
using namespace Windows::UI::Core;
|
||||
using namespace Windows::UI::Xaml;
|
||||
using namespace Windows::UI::Xaml::Controls;
|
||||
using namespace Windows::UI::Xaml::Data;
|
||||
using namespace Windows::UI::Xaml::Media;
|
||||
using namespace Windows::Storage;
|
||||
using namespace Windows::Media::MediaProperties;
|
||||
using namespace Windows::Storage::Streams;
|
||||
using namespace Windows::System;
|
||||
using namespace Windows::UI::Xaml::Media::Imaging;
|
||||
|
||||
|
||||
AudioCapture::AudioCapture()
|
||||
{
|
||||
InitializeComponent();
|
||||
ScenarioInit();
|
||||
}
|
||||
|
||||
/// <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 AudioCapture::OnNavigatedTo(NavigationEventArgs^ e)
|
||||
{
|
||||
// A pointer back to the main page. This is needed if you want to call methods in MainPage such
|
||||
// as NotifyUser()
|
||||
rootPage = MainPage::Current;
|
||||
m_eventRegistrationToken = Windows::Media::MediaControl::SoundLevelChanged += ref new EventHandler<Object^>(this, &AudioCapture::SoundLevelChanged);
|
||||
}
|
||||
|
||||
void AudioCapture::OnNavigatedFrom(NavigationEventArgs^ e)
|
||||
{
|
||||
// A pointer back to the main page. This is needed if you want to call methods in MainPage such
|
||||
// as NotifyUser()
|
||||
Windows::Media::MediaControl::SoundLevelChanged -= m_eventRegistrationToken;
|
||||
}
|
||||
|
||||
void AudioCapture::ScenarioInit()
|
||||
{
|
||||
try
|
||||
{
|
||||
rootPage = MainPage::Current;
|
||||
btnStartDevice3->IsEnabled = true;
|
||||
btnStartStopRecord3->IsEnabled = false;
|
||||
m_bRecording = false;
|
||||
playbackElement3->Source = nullptr;
|
||||
m_bSuspended = false;
|
||||
ShowStatusMessage("");
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AudioCapture::ScenarioReset()
|
||||
{
|
||||
ScenarioInit();
|
||||
}
|
||||
|
||||
|
||||
void AudioCapture::SoundLevelChanged(Object^ sender, Object^ e)
|
||||
{
|
||||
create_task(Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([this]()
|
||||
{
|
||||
if(Windows::Media::MediaControl::SoundLevel != Windows::Media::SoundLevel::Muted)
|
||||
{
|
||||
ScenarioReset();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_bRecording)
|
||||
{
|
||||
ShowStatusMessage("Stopping Record on invisibility");
|
||||
|
||||
create_task(m_mediaCaptureMgr->StopRecordAsync()).then([this](task<void> recordTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
recordTask.get();
|
||||
m_bRecording = false;
|
||||
}catch (Exception ^e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})));
|
||||
}
|
||||
|
||||
void AudioCapture::RecordLimitationExceeded(Windows::Media::Capture::MediaCapture ^currentCaptureObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (m_bRecording)
|
||||
{
|
||||
create_task(Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([this](){
|
||||
try
|
||||
{
|
||||
ShowStatusMessage("Stopping Record on exceeding max record duration");
|
||||
EnableButton(false, "StartStopRecord");
|
||||
create_task(m_mediaCaptureMgr->StopRecordAsync()).then([this](task<void> recordTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
recordTask.get();
|
||||
m_bRecording = false;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
ShowStatusMessage("Stopped record on exceeding max record duration:" + m_recordStorageFile->Path);
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
m_bRecording = false;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
m_bRecording = false;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
|
||||
})));
|
||||
}
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
m_bRecording = false;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioCapture::Failed(Windows::Media::Capture::MediaCapture ^currentCaptureObject, Windows::Media::Capture::MediaCaptureFailedEventArgs^ currentFailure)
|
||||
{
|
||||
String ^message = "Fatal error: " + currentFailure->Message;
|
||||
create_task(Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High,
|
||||
ref new Windows::UI::Core::DispatchedHandler([this, message]()
|
||||
{
|
||||
ShowStatusMessage(message);
|
||||
})));
|
||||
}
|
||||
|
||||
void AudioCapture::btnStartDevice_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnableButton(false, "StartDevice");
|
||||
ShowStatusMessage("Starting device");
|
||||
auto mediaCapture = ref new Windows::Media::Capture::MediaCapture();
|
||||
m_mediaCaptureMgr = mediaCapture;
|
||||
auto settings = ref new Windows::Media::Capture::MediaCaptureInitializationSettings();
|
||||
settings->StreamingCaptureMode = Windows::Media::Capture::StreamingCaptureMode::Audio;
|
||||
create_task(mediaCapture->InitializeAsync()).then([this](task<void> initTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
initTask.get();
|
||||
|
||||
auto mediaCapture = m_mediaCaptureMgr.Get();
|
||||
EnableButton(true, "StartPreview");
|
||||
EnableButton(true, "StartStopRecord");
|
||||
EnableButton(true, "TakePhoto");
|
||||
ShowStatusMessage("Device initialized successful");
|
||||
mediaCapture->RecordLimitationExceeded += ref new Windows::Media::Capture::RecordLimitationExceededEventHandler(this, &AudioCapture::RecordLimitationExceeded);
|
||||
mediaCapture->Failed += ref new Windows::Media::Capture::MediaCaptureFailedEventHandler(this, &AudioCapture::Failed);
|
||||
}
|
||||
catch (Exception ^ e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Platform::Exception^ e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioCapture::btnStartStopRecord_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
||||
{
|
||||
try
|
||||
{
|
||||
String ^fileName;
|
||||
EnableButton(false, "StartStopRecord");
|
||||
|
||||
if (!m_bRecording)
|
||||
{
|
||||
ShowStatusMessage("Starting Record");
|
||||
|
||||
fileName = AUDIO_FILE_NAME;
|
||||
|
||||
task<StorageFile^>(KnownFolders::VideosLibrary->CreateFileAsync(fileName, Windows::Storage::CreationCollisionOption::GenerateUniqueName)).then([this](task<StorageFile^> fileTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
this->m_recordStorageFile = fileTask.get();
|
||||
ShowStatusMessage("Create record file successful");
|
||||
|
||||
MediaEncodingProfile^ recordProfile= nullptr;
|
||||
recordProfile = MediaEncodingProfile::CreateM4a(Windows::Media::MediaProperties::AudioEncodingQuality::Auto);
|
||||
|
||||
create_task(m_mediaCaptureMgr->StartRecordToStorageFileAsync(recordProfile, this->m_recordStorageFile)).then([this](task<void> recordTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
recordTask.get();
|
||||
m_bRecording = true;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
|
||||
ShowStatusMessage("Start Record successful");
|
||||
|
||||
|
||||
}catch (Exception ^e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
m_bRecording = false;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
m_bRecording = false;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowStatusMessage("Stopping Record");
|
||||
|
||||
create_task(m_mediaCaptureMgr->StopRecordAsync()).then([this](task<void>)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_bRecording = false;
|
||||
EnableButton(true, "StartStopRecord");
|
||||
SwitchRecordButtonContent();
|
||||
|
||||
ShowStatusMessage("Stop record successful");
|
||||
if (!m_bSuspended)
|
||||
{
|
||||
task<IRandomAccessStream^>(this->m_recordStorageFile->OpenAsync(FileAccessMode::Read)).then([this](task<IRandomAccessStream^> streamTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
ShowStatusMessage("Record file opened");
|
||||
auto stream = streamTask.get();
|
||||
ShowStatusMessage(this->m_recordStorageFile->Path);
|
||||
playbackElement3->AutoPlay = true;
|
||||
playbackElement3->SetSource(stream, this->m_recordStorageFile->FileType);
|
||||
playbackElement3->Play();
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
m_bRecording = false;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
m_bRecording = false;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Platform::Exception^ e)
|
||||
{
|
||||
EnableButton(true, "StartStopRecord");
|
||||
ShowExceptionMessage(e);
|
||||
m_bRecording = false;
|
||||
SwitchRecordButtonContent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void AudioCapture::ShowStatusMessage(Platform::String^ text)
|
||||
{
|
||||
rootPage->NotifyUser(text, NotifyType::StatusMessage);
|
||||
}
|
||||
|
||||
void AudioCapture::ShowExceptionMessage(Platform::Exception^ ex)
|
||||
{
|
||||
rootPage->NotifyUser(ex->Message, NotifyType::ErrorMessage);
|
||||
}
|
||||
|
||||
void AudioCapture::SwitchRecordButtonContent()
|
||||
{
|
||||
{
|
||||
if (m_bRecording)
|
||||
{
|
||||
btnStartStopRecord3->Content="StopRecord";
|
||||
}
|
||||
else
|
||||
{
|
||||
btnStartStopRecord3->Content="StartRecord";
|
||||
}
|
||||
}
|
||||
}
|
||||
void AudioCapture::EnableButton(bool enabled, String^ name)
|
||||
{
|
||||
if (name->Equals("StartDevice"))
|
||||
{
|
||||
btnStartDevice3->IsEnabled = enabled;
|
||||
}
|
||||
|
||||
else if (name->Equals("StartStopRecord"))
|
||||
{
|
||||
btnStartStopRecord3->IsEnabled = enabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,70 +0,0 @@
|
||||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
|
||||
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
|
||||
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
|
||||
//
|
||||
//*********************************************************
|
||||
|
||||
//
|
||||
// AudioCapture.xaml.h
|
||||
// Declaration of the AudioCapture class
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "pch.h"
|
||||
#include "AudioCapture.g.h"
|
||||
#include "MainPage.xaml.h"
|
||||
|
||||
#define AUDIO_FILE_NAME "audio.mp4"
|
||||
|
||||
namespace SDKSample
|
||||
{
|
||||
namespace MediaCapture
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
[Windows::Foundation::Metadata::WebHostHidden]
|
||||
public ref class AudioCapture sealed
|
||||
{
|
||||
public:
|
||||
AudioCapture();
|
||||
|
||||
protected:
|
||||
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
|
||||
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
|
||||
private:
|
||||
MainPage^ rootPage;
|
||||
|
||||
void ScenarioInit();
|
||||
void ScenarioReset();
|
||||
|
||||
void SoundLevelChanged(Object^ sender, Object^ e);
|
||||
void RecordLimitationExceeded(Windows::Media::Capture::MediaCapture ^ mediaCapture);
|
||||
void Failed(Windows::Media::Capture::MediaCapture ^ mediaCapture, Windows::Media::Capture::MediaCaptureFailedEventArgs ^ args);
|
||||
|
||||
void btnStartDevice_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
|
||||
void btnStartPreview_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
|
||||
void btnStartStopRecord_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
|
||||
void ShowStatusMessage(Platform::String^ text);
|
||||
void ShowExceptionMessage(Platform::Exception^ ex);
|
||||
|
||||
void EnableButton(bool enabled, Platform::String ^name);
|
||||
void SwitchRecordButtonContent();
|
||||
|
||||
Platform::Agile<Windows::Media::Capture::MediaCapture> m_mediaCaptureMgr;
|
||||
Windows::Storage::StorageFile^ m_photoStorageFile;
|
||||
Windows::Storage::StorageFile^ m_recordStorageFile;
|
||||
bool m_bRecording;
|
||||
bool m_bSuspended;
|
||||
Windows::Foundation::EventRegistrationToken m_eventRegistrationToken;
|
||||
};
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
<!--
|
||||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
|
||||
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
|
||||
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
|
||||
//
|
||||
//*********************************************************
|
||||
-->
|
||||
|
||||
<common:LayoutAwarePage
|
||||
x:Class="SDKSample.MediaCapture.BasicCapture"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:$rootsnamespace$"
|
||||
xmlns:common="using:SDKSample.Common"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Left" VerticalAlignment="Top">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid x:Name="Input" Grid.Row="0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock x:Name="InputTextBlock1" TextWrapping="Wrap" Grid.Row="0" Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left" >
|
||||
This scenario demonstrates how to use the MediaCapture API to preview the camera stream, record a video, and take a picture using default initialization settings.
|
||||
You can also adjust the brightness and contrast.
|
||||
</TextBlock>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,10,0,0" Grid.Row="1">
|
||||
<Button x:Name="btnStartDevice1" Click="btnStartDevice_Click" IsEnabled="true" Margin="0,0,10,0">StartDevice</Button>
|
||||
<Button x:Name="btnStartPreview1" Click="btnStartPreview_Click" IsEnabled="true" Margin="0,0,10,0">StartPreview</Button>
|
||||
<Button x:Name="btnStartStopRecord1" Click="btnStartStopRecord_Click" IsEnabled="false" Margin="0,0,10,0">StartRecord</Button>
|
||||
<Button x:Name="btnTakePhoto1" Click="btnTakePhoto_Click" IsEnabled="false" Margin="0,0,10,0">TakePhoto</Button>
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" Margin="0,10,0,0" Grid.Row="2">
|
||||
<TextBlock TextWrapping="Wrap" Text="Brightness" Style="{StaticResource BasicTextStyle}" Margin="0,0,10,0" VerticalAlignment="Center"/>
|
||||
<Slider x:Name="sldBrightness" IsEnabled="False" ValueChanged="sldBrightness_ValueChanged" Width="207" Margin="0,0,10,0"/>
|
||||
<TextBlock TextWrapping="Wrap" Text="Contrast" Style="{StaticResource BasicTextStyle}" Margin="0,0,10,0" VerticalAlignment="Center" />
|
||||
<Slider x:Name="sldContrast" IsEnabled="False" ValueChanged="sldContrast_ValueChanged" Width="207" Margin="0,0,10,0"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<Grid x:Name="Output" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
|
||||
<StackPanel>
|
||||
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Preview' />
|
||||
<Canvas x:Name="previewCanvas1" Width="320" Height="240" Background="Gray">
|
||||
<CaptureElement x:Name="previewElement1" Width="320" Height="240" />
|
||||
</Canvas>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Captured Video' />
|
||||
<Canvas x:Name='playbackCanvas1' Width='320' Height ='240' >
|
||||
<MediaElement x:Name='playbackElement1' Width="320" Height="240" />
|
||||
</Canvas>
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Captured Images' />
|
||||
<Canvas x:Name="imageCanvas1" Width='320' Height ='240' >
|
||||
<Image x:Name="imageElement1" Width="320" Height="240"/>
|
||||
</Canvas>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
</Grid>
|
||||
|
||||
<!-- Add Storyboards to the visual states below as necessary for supporting the various layouts -->
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup>
|
||||
<VisualState x:Name="FullScreenLandscape"/>
|
||||
<VisualState x:Name="Filled"/>
|
||||
<VisualState x:Name="FullScreenPortrait"/>
|
||||
<VisualState x:Name="Snapped"/>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Grid>
|
||||
|
||||
</common:LayoutAwarePage>
|
@ -1,535 +0,0 @@
|
||||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
|
||||
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
|
||||
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
|
||||
//
|
||||
//*********************************************************
|
||||
|
||||
//
|
||||
// BasicCapture.xaml.cpp
|
||||
// Implementation of the BasicCapture class
|
||||
//
|
||||
|
||||
#include "pch.h"
|
||||
#include "BasicCapture.xaml.h"
|
||||
#include "ppl.h"
|
||||
|
||||
using namespace Windows::System;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Platform;
|
||||
using namespace Windows::UI;
|
||||
using namespace Windows::UI::Core;
|
||||
using namespace Windows::UI::Xaml;
|
||||
using namespace Windows::UI::Xaml::Controls;
|
||||
using namespace Windows::UI::Xaml::Navigation;
|
||||
using namespace Windows::UI::Xaml::Data;
|
||||
using namespace Windows::UI::Xaml::Media;
|
||||
using namespace Windows::Storage;
|
||||
using namespace Windows::Media::MediaProperties;
|
||||
using namespace Windows::Storage::Streams;
|
||||
using namespace Windows::System;
|
||||
using namespace Windows::UI::Xaml::Media::Imaging;
|
||||
|
||||
using namespace SDKSample::MediaCapture;
|
||||
using namespace concurrency;
|
||||
|
||||
|
||||
BasicCapture::BasicCapture()
|
||||
{
|
||||
InitializeComponent();
|
||||
ScenarioInit();
|
||||
}
|
||||
|
||||
/// <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 BasicCapture::OnNavigatedTo(NavigationEventArgs^ e)
|
||||
{
|
||||
// A pointer back to the main page. This is needed if you want to call methods in MainPage such
|
||||
// as NotifyUser()
|
||||
rootPage = MainPage::Current;
|
||||
m_eventRegistrationToken = Windows::Media::MediaControl::SoundLevelChanged += ref new EventHandler<Object^>(this, &BasicCapture::SoundLevelChanged);
|
||||
}
|
||||
|
||||
void BasicCapture::OnNavigatedFrom(NavigationEventArgs^ e)
|
||||
{
|
||||
// A pointer back to the main page. This is needed if you want to call methods in MainPage such
|
||||
// as NotifyUser()
|
||||
|
||||
Windows::Media::MediaControl::SoundLevelChanged -= m_eventRegistrationToken;
|
||||
m_currentScenarioLoaded = false;
|
||||
}
|
||||
|
||||
|
||||
void BasicCapture::ScenarioInit()
|
||||
{
|
||||
try
|
||||
{
|
||||
btnStartDevice1->IsEnabled = true;
|
||||
btnStartPreview1->IsEnabled = false;
|
||||
btnStartStopRecord1->IsEnabled = false;
|
||||
m_bRecording = false;
|
||||
m_bPreviewing = false;
|
||||
btnStartStopRecord1->Content = "StartRecord";
|
||||
btnTakePhoto1->IsEnabled = false;
|
||||
previewElement1->Source = nullptr;
|
||||
playbackElement1->Source = nullptr;
|
||||
imageElement1->Source= nullptr;
|
||||
sldBrightness->IsEnabled = false;
|
||||
sldContrast->IsEnabled = false;
|
||||
m_bSuspended = false;
|
||||
previewCanvas1->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
|
||||
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BasicCapture::ScenarioReset()
|
||||
{
|
||||
previewCanvas1->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
|
||||
ScenarioInit();
|
||||
}
|
||||
|
||||
void BasicCapture::SoundLevelChanged(Object^ sender, Object^ e)
|
||||
{
|
||||
create_task(Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([this]()
|
||||
{
|
||||
if(Windows::Media::MediaControl::SoundLevel != Windows::Media::SoundLevel::Muted)
|
||||
{
|
||||
ScenarioReset();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_bRecording)
|
||||
{
|
||||
ShowStatusMessage("Stopping Record on invisibility");
|
||||
|
||||
create_task(m_mediaCaptureMgr->StopRecordAsync()).then([this](task<void> recordTask)
|
||||
{
|
||||
m_bRecording = false;
|
||||
});
|
||||
}
|
||||
if (m_bPreviewing)
|
||||
{
|
||||
ShowStatusMessage("Stopping Preview on invisibility");
|
||||
|
||||
create_task(m_mediaCaptureMgr->StopPreviewAsync()).then([this](task<void> previewTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
previewTask.get();
|
||||
m_bPreviewing = false;
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
})));
|
||||
}
|
||||
|
||||
void BasicCapture::RecordLimitationExceeded(Windows::Media::Capture::MediaCapture ^currentCaptureObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (m_bRecording)
|
||||
{
|
||||
create_task(Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High, ref new Windows::UI::Core::DispatchedHandler([this](){
|
||||
try
|
||||
{
|
||||
ShowStatusMessage("Stopping Record on exceeding max record duration");
|
||||
EnableButton(false, "StartStopRecord");
|
||||
create_task(m_mediaCaptureMgr->StopRecordAsync()).then([this](task<void> recordTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
recordTask.get();
|
||||
m_bRecording = false;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
ShowStatusMessage("Stopped record on exceeding max record duration:" + m_recordStorageFile->Path);
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
m_bRecording = false;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
m_bRecording = false;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
|
||||
})));
|
||||
}
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
m_bRecording = false;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
}
|
||||
|
||||
void BasicCapture::Failed(Windows::Media::Capture::MediaCapture ^currentCaptureObject, Windows::Media::Capture::MediaCaptureFailedEventArgs^ currentFailure)
|
||||
{
|
||||
String ^message = "Fatal error: " + currentFailure->Message;
|
||||
create_task(Dispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::High,
|
||||
ref new Windows::UI::Core::DispatchedHandler([this, message]()
|
||||
{
|
||||
ShowStatusMessage(message);
|
||||
})));
|
||||
}
|
||||
|
||||
void BasicCapture::btnStartDevice_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
||||
{
|
||||
try
|
||||
{
|
||||
EnableButton(false, "StartDevice");
|
||||
ShowStatusMessage("Starting device");
|
||||
auto mediaCapture = ref new Windows::Media::Capture::MediaCapture();
|
||||
m_mediaCaptureMgr = mediaCapture;
|
||||
create_task(mediaCapture->InitializeAsync()).then([this](task<void> initTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
initTask.get();
|
||||
|
||||
auto mediaCapture = m_mediaCaptureMgr.Get();
|
||||
EnableButton(true, "StartPreview");
|
||||
EnableButton(true, "StartStopRecord");
|
||||
EnableButton(true, "TakePhoto");
|
||||
ShowStatusMessage("Device initialized successful");
|
||||
mediaCapture->RecordLimitationExceeded += ref new Windows::Media::Capture::RecordLimitationExceededEventHandler(this, &BasicCapture::RecordLimitationExceeded);
|
||||
mediaCapture->Failed += ref new Windows::Media::Capture::MediaCaptureFailedEventHandler(this, &BasicCapture::Failed);
|
||||
}
|
||||
catch (Exception ^ e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Platform::Exception^ e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
}
|
||||
|
||||
void BasicCapture::btnStartPreview_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
||||
{
|
||||
m_bPreviewing = false;
|
||||
try
|
||||
{
|
||||
ShowStatusMessage("Starting preview");
|
||||
EnableButton(false, "StartPreview");
|
||||
auto mediaCapture = m_mediaCaptureMgr.Get();
|
||||
|
||||
previewCanvas1->Visibility = Windows::UI::Xaml::Visibility::Visible;
|
||||
previewElement1->Source = mediaCapture;
|
||||
create_task(mediaCapture->StartPreviewAsync()).then([this](task<void> previewTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
previewTask.get();
|
||||
auto mediaCapture = m_mediaCaptureMgr.Get();
|
||||
m_bPreviewing = true;
|
||||
ShowStatusMessage("Start preview successful");
|
||||
if(mediaCapture->VideoDeviceController->Brightness)
|
||||
{
|
||||
SetupVideoDeviceControl(mediaCapture->VideoDeviceController->Brightness, sldBrightness);
|
||||
}
|
||||
if(mediaCapture->VideoDeviceController->Contrast)
|
||||
{
|
||||
SetupVideoDeviceControl(mediaCapture->VideoDeviceController->Contrast, sldContrast);
|
||||
}
|
||||
|
||||
}catch (Exception ^e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Platform::Exception^ e)
|
||||
{
|
||||
m_bPreviewing = false;
|
||||
previewElement1->Source = nullptr;
|
||||
EnableButton(true, "StartPreview");
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
}
|
||||
|
||||
void BasicCapture::btnTakePhoto_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
||||
{
|
||||
try
|
||||
{
|
||||
ShowStatusMessage("Taking photo");
|
||||
EnableButton(false, "TakePhoto");
|
||||
|
||||
task<StorageFile^>(KnownFolders::PicturesLibrary->CreateFileAsync(PHOTO_FILE_NAME, Windows::Storage::CreationCollisionOption::GenerateUniqueName)).then([this](task<StorageFile^> getFileTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
this->m_photoStorageFile = getFileTask.get();
|
||||
ShowStatusMessage("Create photo file successful");
|
||||
ImageEncodingProperties^ imageProperties = ImageEncodingProperties::CreateJpeg();
|
||||
|
||||
create_task(m_mediaCaptureMgr->CapturePhotoToStorageFileAsync(imageProperties, this->m_photoStorageFile)).then([this](task<void> photoTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
photoTask.get();
|
||||
EnableButton(true, "TakePhoto");
|
||||
ShowStatusMessage("Photo taken");
|
||||
|
||||
task<IRandomAccessStream^>(this->m_photoStorageFile->OpenAsync(FileAccessMode::Read)).then([this](task<IRandomAccessStream^> getStreamTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto photoStream = getStreamTask.get();
|
||||
ShowStatusMessage("File open successful");
|
||||
auto bmpimg = ref new BitmapImage();
|
||||
|
||||
bmpimg->SetSource(photoStream);
|
||||
imageElement1->Source = bmpimg;
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
EnableButton(true, "TakePhoto");
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Platform::Exception ^ e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
EnableButton(true, "TakePhoto");
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception^ e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
EnableButton(true, "TakePhoto");
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Platform::Exception^ e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
EnableButton(true, "TakePhoto");
|
||||
}
|
||||
}
|
||||
|
||||
void BasicCapture::btnStartStopRecord_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
|
||||
{
|
||||
try
|
||||
{
|
||||
String ^fileName;
|
||||
EnableButton(false, "StartStopRecord");
|
||||
|
||||
if (!m_bRecording)
|
||||
{
|
||||
ShowStatusMessage("Starting Record");
|
||||
|
||||
fileName = VIDEO_FILE_NAME;
|
||||
|
||||
task<StorageFile^>(KnownFolders::VideosLibrary->CreateFileAsync(fileName,Windows::Storage::CreationCollisionOption::GenerateUniqueName )).then([this](task<StorageFile^> fileTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
this->m_recordStorageFile = fileTask.get();
|
||||
ShowStatusMessage("Create record file successful");
|
||||
|
||||
MediaEncodingProfile^ recordProfile= nullptr;
|
||||
recordProfile = MediaEncodingProfile::CreateMp4(Windows::Media::MediaProperties::VideoEncodingQuality::Auto);
|
||||
|
||||
create_task(m_mediaCaptureMgr->StartRecordToStorageFileAsync(recordProfile, this->m_recordStorageFile)).then([this](task<void> recordTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
recordTask.get();
|
||||
m_bRecording = true;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
|
||||
ShowStatusMessage("Start Record successful");
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
m_bRecording = false;
|
||||
SwitchRecordButtonContent();
|
||||
EnableButton(true, "StartStopRecord");
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowStatusMessage("Stopping Record");
|
||||
|
||||
create_task(m_mediaCaptureMgr->StopRecordAsync()).then([this](task<void> recordTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
recordTask.get();
|
||||
m_bRecording = false;
|
||||
EnableButton(true, "StartStopRecord");
|
||||
SwitchRecordButtonContent();
|
||||
|
||||
ShowStatusMessage("Stop record successful");
|
||||
if (!m_bSuspended)
|
||||
{
|
||||
task<IRandomAccessStream^>(this->m_recordStorageFile->OpenAsync(FileAccessMode::Read)).then([this](task<IRandomAccessStream^> streamTask)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto stream = streamTask.get();
|
||||
ShowStatusMessage("Record file opened");
|
||||
ShowStatusMessage(this->m_recordStorageFile->Path);
|
||||
playbackElement1->AutoPlay = true;
|
||||
playbackElement1->SetSource(stream, this->m_recordStorageFile->FileType);
|
||||
playbackElement1->Play();
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
m_bRecording = false;
|
||||
EnableButton(true, "StartStopRecord");
|
||||
SwitchRecordButtonContent();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ^e)
|
||||
{
|
||||
m_bRecording = false;
|
||||
EnableButton(true, "StartStopRecord");
|
||||
SwitchRecordButtonContent();
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Platform::Exception^ e)
|
||||
{
|
||||
EnableButton(true, "StartStopRecord");
|
||||
ShowExceptionMessage(e);
|
||||
SwitchRecordButtonContent();
|
||||
m_bRecording = false;
|
||||
}
|
||||
}
|
||||
|
||||
void BasicCapture::SetupVideoDeviceControl(Windows::Media::Devices::MediaDeviceControl^ videoDeviceControl, Slider^ slider)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((videoDeviceControl->Capabilities)->Supported)
|
||||
{
|
||||
slider->IsEnabled = true;
|
||||
slider->Maximum = videoDeviceControl->Capabilities->Max;
|
||||
slider->Minimum = videoDeviceControl->Capabilities->Min;
|
||||
slider->StepFrequency = videoDeviceControl->Capabilities->Step;
|
||||
double controlValue = 0;
|
||||
if (videoDeviceControl->TryGetValue(&controlValue))
|
||||
{
|
||||
slider->Value = controlValue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
slider->IsEnabled = false;
|
||||
}
|
||||
}
|
||||
catch (Platform::Exception^ e)
|
||||
{
|
||||
ShowExceptionMessage(e);
|
||||
}
|
||||
}
|
||||
|
||||
// VideoDeviceControllers
|
||||
void BasicCapture::sldBrightness_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e)
|
||||
{
|
||||
bool succeeded = m_mediaCaptureMgr->VideoDeviceController->Brightness->TrySetValue(sldBrightness->Value);
|
||||
if (!succeeded)
|
||||
{
|
||||
ShowStatusMessage("Set Brightness failed");
|
||||
}
|
||||
}
|
||||
|
||||
void BasicCapture::sldContrast_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs ^e)
|
||||
{
|
||||
bool succeeded = m_mediaCaptureMgr->VideoDeviceController->Contrast->TrySetValue(sldContrast->Value);
|
||||
if (!succeeded)
|
||||
{
|
||||
ShowStatusMessage("Set Contrast failed");
|
||||
}
|
||||
}
|
||||
|
||||
void BasicCapture::ShowStatusMessage(Platform::String^ text)
|
||||
{
|
||||
rootPage->NotifyUser(text, NotifyType::StatusMessage);
|
||||
}
|
||||
|
||||
void BasicCapture::ShowExceptionMessage(Platform::Exception^ ex)
|
||||
{
|
||||
rootPage->NotifyUser(ex->Message, NotifyType::ErrorMessage);
|
||||
}
|
||||
|
||||
void BasicCapture::SwitchRecordButtonContent()
|
||||
{
|
||||
if (m_bRecording)
|
||||
{
|
||||
btnStartStopRecord1->Content="StopRecord";
|
||||
}
|
||||
else
|
||||
{
|
||||
btnStartStopRecord1->Content="StartRecord";
|
||||
}
|
||||
}
|
||||
void BasicCapture::EnableButton(bool enabled, String^ name)
|
||||
{
|
||||
if (name->Equals("StartDevice"))
|
||||
{
|
||||
btnStartDevice1->IsEnabled = enabled;
|
||||
}
|
||||
else if (name->Equals("StartPreview"))
|
||||
{
|
||||
btnStartPreview1->IsEnabled = enabled;
|
||||
}
|
||||
else if (name->Equals("StartStopRecord"))
|
||||
{
|
||||
btnStartStopRecord1->IsEnabled = enabled;
|
||||
}
|
||||
else if (name->Equals("TakePhoto"))
|
||||
{
|
||||
btnTakePhoto1->IsEnabled = enabled;
|
||||
}
|
||||
}
|
||||
|
@ -1,88 +0,0 @@
|
||||
//*********************************************************
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
|
||||
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
|
||||
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
|
||||
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
|
||||
//
|
||||
//*********************************************************
|
||||
|
||||
//
|
||||
// BasicCapture.xaml.h
|
||||
// Declaration of the BasicCapture class
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "pch.h"
|
||||
#include "BasicCapture.g.h"
|
||||
#include "MainPage.xaml.h"
|
||||
|
||||
using namespace Windows::UI::Xaml;
|
||||
using namespace Windows::UI::Xaml::Controls;
|
||||
using namespace Windows::Graphics::Display;
|
||||
using namespace Windows::UI::ViewManagement;
|
||||
using namespace Windows::Devices::Enumeration;
|
||||
#define VIDEO_FILE_NAME "video.mp4"
|
||||
#define PHOTO_FILE_NAME "photo.jpg"
|
||||
namespace SDKSample
|
||||
{
|
||||
namespace MediaCapture
|
||||
{
|
||||
/// <summary>
|
||||
/// An empty page that can be used on its own or navigated to within a Frame.
|
||||
/// </summary>
|
||||
[Windows::Foundation::Metadata::WebHostHidden]
|
||||
public ref class BasicCapture sealed
|
||||
{
|
||||
public:
|
||||
BasicCapture();
|
||||
|
||||
protected:
|
||||
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
|
||||
virtual void OnNavigatedFrom(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
|
||||
|
||||
private:
|
||||
MainPage^ rootPage;
|
||||
void ScenarioInit();
|
||||
void ScenarioReset();
|
||||
|
||||
void Suspending(Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e);
|
||||
void Resuming(Object^ sender, Object^ e);
|
||||
|
||||
void btnStartDevice_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
void SoundLevelChanged(Object^ sender, Object^ e);
|
||||
void RecordLimitationExceeded(Windows::Media::Capture::MediaCapture ^ mediaCapture);
|
||||
void Failed(Windows::Media::Capture::MediaCapture ^ mediaCapture, Windows::Media::Capture::MediaCaptureFailedEventArgs ^ args);
|
||||
|
||||
|
||||
void btnStartPreview_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
|
||||
void btnStartStopRecord_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
|
||||
void btnTakePhoto_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
|
||||
void SetupVideoDeviceControl(Windows::Media::Devices::MediaDeviceControl^ videoDeviceControl, Slider^ slider);
|
||||
void sldBrightness_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e);
|
||||
void sldContrast_ValueChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::Primitives::RangeBaseValueChangedEventArgs^ e);
|
||||
|
||||
void ShowStatusMessage(Platform::String^ text);
|
||||
void ShowExceptionMessage(Platform::Exception^ ex);
|
||||
|
||||
void EnableButton(bool enabled, Platform::String ^name);
|
||||
void SwitchRecordButtonContent();
|
||||
|
||||
Platform::Agile<Windows::Media::Capture::MediaCapture> m_mediaCaptureMgr;
|
||||
Windows::Storage::StorageFile^ m_photoStorageFile;
|
||||
Windows::Storage::StorageFile^ m_recordStorageFile;
|
||||
bool m_bRecording;
|
||||
bool m_bEffectAdded;
|
||||
bool m_bSuspended;
|
||||
bool m_bPreviewing;
|
||||
Windows::UI::Xaml::WindowVisibilityChangedEventHandler ^m_visbilityHandler;
|
||||
Windows::Foundation::EventRegistrationToken m_eventRegistrationToken;
|
||||
bool m_currentScenarioLoaded;
|
||||
};
|
||||
}
|
||||
}
|
@ -18,7 +18,5 @@ Platform::Array<Scenario>^ MainPage::scenariosInner = ref new Platform::Array<Sc
|
||||
{
|
||||
// The format here is the following:
|
||||
// { "Description for the sample", "Fully quaified name for the class that implements the scenario" }
|
||||
{ "Video preview, record and take pictures", "SDKSample.MediaCapture.BasicCapture" },
|
||||
{ "Enumerate cameras and add a video effect", "SDKSample.MediaCapture.AdvancedCapture" },
|
||||
{ "Audio Capture", "SDKSample.MediaCapture.AudioCapture" }
|
||||
};
|
||||
|
@ -26,7 +26,7 @@ namespace SDKSample
|
||||
{
|
||||
Platform::String^ get()
|
||||
{
|
||||
return ref new Platform::String(L"MediaCapture CPP sample");
|
||||
return ref new Platform::String(L"OpenCV Image Manipulations sample");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
|
||||
<Grid x:Name="LayoutRoot" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
|
||||
|
||||
|
||||
<Grid x:Name="ContentRoot" Background="{StaticResource ApplicationPageBackgroundThemeBrush}" Margin="100,20,100,20">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
@ -47,7 +47,7 @@
|
||||
<!-- Header -->
|
||||
<StackPanel Orientation="Horizontal" Grid.Row="0">
|
||||
<Image x:Name="WindowsLogo" Stretch="None" Source="Assets/windows-sdk.png" AutomationProperties.Name="Windows Logo" HorizontalAlignment="Left" Grid.Column="0"/>
|
||||
<TextBlock Text="Windows 8 SDK Samples" VerticalAlignment="Bottom" Style="{StaticResource TitleTextStyle}" TextWrapping="Wrap" Grid.Column="1"/>
|
||||
<TextBlock VerticalAlignment="Bottom" Style="{StaticResource TitleTextStyle}" TextWrapping="Wrap" Grid.Column="1" Text="OpenCV for Windows RT"/>
|
||||
</StackPanel>
|
||||
<ScrollViewer x:Name="MainScrollViewer" Grid.Row="1" ZoomMode="Disabled" IsTabStop="False" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Padding="0,0,0,20" >
|
||||
<Grid>
|
||||
@ -92,7 +92,7 @@
|
||||
<TextBlock x:Name="DescriptionText" Margin="0,5,0,0" Text="Description:" Style="{StaticResource SubheaderTextStyle}" Grid.Row="1" Grid.Column="1"/>
|
||||
<!-- Input Scenarios -->
|
||||
<UserControl x:Name="InputSection" Margin="0,5,0,0" IsTabStop="False" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top"/>
|
||||
|
||||
|
||||
<!-- Output section -->
|
||||
<TextBlock Text="Output" Grid.Row="5" Margin="0,25,0,20" Style="{StaticResource H2Style}" Grid.ColumnSpan="2"/>
|
||||
<TextBlock x:Name="StatusBlock" Grid.Row="6" Margin="0,0,0,5" Grid.ColumnSpan="2"/>
|
||||
|
@ -101,14 +101,6 @@
|
||||
<DependentUpon>AdvancedCapture.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</ClInclude>
|
||||
<ClInclude Include="AudioCapture.xaml.h">
|
||||
<DependentUpon>AudioCapture.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</ClInclude>
|
||||
<ClInclude Include="BasicCapture.xaml.h">
|
||||
<DependentUpon>BasicCapture.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Constants.h" />
|
||||
<ClInclude Include="MainPage.xaml.h">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
@ -127,12 +119,6 @@
|
||||
<Page Include="AdvancedCapture.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="AudioCapture.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="BasicCapture.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="Common\StandardStyles.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
@ -156,14 +142,6 @@
|
||||
<ClCompile Include="App.xaml.cpp">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</ClCompile>
|
||||
<ClCompile Include="AudioCapture.xaml.cpp">
|
||||
<DependentUpon>AudioCapture.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</ClCompile>
|
||||
<ClCompile Include="BasicCapture.xaml.cpp">
|
||||
<DependentUpon>BasicCapture.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Common\LayoutAwarePage.cpp" />
|
||||
<ClCompile Include="Constants.cpp" />
|
||||
<ClCompile Include="Common\SuspensionManager.cpp" />
|
||||
@ -194,6 +172,144 @@
|
||||
<Project>{ba69218f-da5c-4d14-a78d-21a9e4dec669}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_calib3d245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_contrib245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_core245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_features2d245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_flann245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_highgui245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_imgproc245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_legacy245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_ml245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_nonfree245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_objdetect245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_photo245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_stitching245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_superres245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_ts245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_video245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_videostab245.dll">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
@ -40,9 +40,7 @@
|
||||
<Page Include="Sample-Utils\SampleTemplateStyles.xaml">
|
||||
<Filter>Sample-Utils</Filter>
|
||||
</Page>
|
||||
<Page Include="BasicCapture.xaml" />
|
||||
<Page Include="AdvancedCapture.xaml" />
|
||||
<Page Include="AudioCapture.xaml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="MainPage.xaml.h" />
|
||||
@ -56,8 +54,6 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="Constants.h" />
|
||||
<ClInclude Include="AdvancedCapture.xaml.h" />
|
||||
<ClInclude Include="AudioCapture.xaml.h" />
|
||||
<ClInclude Include="BasicCapture.xaml.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="App.xaml.cpp" />
|
||||
@ -71,8 +67,6 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="Constants.cpp" />
|
||||
<ClCompile Include="AdvancedCapture.xaml.cpp" />
|
||||
<ClCompile Include="AudioCapture.xaml.cpp" />
|
||||
<ClCompile Include="BasicCapture.xaml.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="Assets">
|
||||
@ -85,4 +79,23 @@
|
||||
<UniqueIdentifier>{54f287f8-e4cb-4f47-97d0-4c469de6992e}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_calib3d245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_contrib245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_core245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_features2d245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_flann245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_highgui245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_imgproc245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_legacy245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_ml245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_nonfree245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_objdetect245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_photo245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_stitching245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_superres245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_ts245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_video245.dll" />
|
||||
<None Include="..\..\..\..\build\install\bin\opencv_videostab245.dll" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -8,6 +8,9 @@
|
||||
#include "Grayscale.h"
|
||||
#include "bufferlock.h"
|
||||
|
||||
#include "opencv2\core\core.hpp"
|
||||
#include "opencv2\imgproc\imgproc.hpp"
|
||||
|
||||
#pragma comment(lib, "d2d1")
|
||||
|
||||
using namespace Microsoft::WRL;
|
||||
@ -80,16 +83,12 @@ NOTES ON THE MFT IMPLEMENTATION
|
||||
|
||||
|
||||
// Video FOURCC codes.
|
||||
const DWORD FOURCC_YUY2 = '2YUY';
|
||||
const DWORD FOURCC_UYVY = 'YVYU';
|
||||
const DWORD FOURCC_NV12 = '21VN';
|
||||
|
||||
// Static array of media types (preferred and accepted).
|
||||
const GUID g_MediaSubtypes[] =
|
||||
{
|
||||
MFVideoFormat_NV12,
|
||||
MFVideoFormat_YUY2,
|
||||
MFVideoFormat_UYVY
|
||||
MFVideoFormat_NV12
|
||||
};
|
||||
|
||||
HRESULT GetImageSize(DWORD fcc, UINT32 width, UINT32 height, DWORD* pcbImage);
|
||||
@ -102,27 +101,6 @@ inline T clamp(const T& val, const T& minVal, const T& maxVal)
|
||||
return (val < minVal ? minVal : (val > maxVal ? maxVal : val));
|
||||
}
|
||||
|
||||
|
||||
// TransformChroma:
|
||||
// Apply the transforms to calculate the output chroma values.
|
||||
|
||||
void TransformChroma(const D2D1::Matrix3x2F& mat, BYTE *pu, BYTE *pv)
|
||||
{
|
||||
// Normalize the chroma values to [-112, 112] range
|
||||
|
||||
D2D1_POINT_2F pt = { static_cast<float>(*pu) - 128, static_cast<float>(*pv) - 128 };
|
||||
|
||||
pt = mat.TransformPoint(pt);
|
||||
|
||||
// Clamp to valid range.
|
||||
clamp(pt.x, -112.0f, 112.0f);
|
||||
clamp(pt.y, -112.0f, 112.0f);
|
||||
|
||||
// Map back to [16...240] range.
|
||||
*pu = static_cast<BYTE>(pt.x + 128.0f);
|
||||
*pv = static_cast<BYTE>(pt.y + 128.0f);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Functions to convert a YUV images to grayscale.
|
||||
//
|
||||
@ -141,144 +119,6 @@ void TransformChroma(const D2D1::Matrix3x2F& mat, BYTE *pu, BYTE *pv)
|
||||
// dwHeightInPixels Frame height, in pixels.
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
// Convert UYVY image.
|
||||
|
||||
void TransformImage_UYVY(
|
||||
const D2D1::Matrix3x2F& mat,
|
||||
const D2D_RECT_U& rcDest,
|
||||
_Inout_updates_(_Inexpressible_(lDestStride * dwHeightInPixels)) BYTE *pDest,
|
||||
_In_ LONG lDestStride,
|
||||
_In_reads_(_Inexpressible_(lSrcStride * dwHeightInPixels)) const BYTE* pSrc,
|
||||
_In_ LONG lSrcStride,
|
||||
_In_ DWORD dwWidthInPixels,
|
||||
_In_ DWORD dwHeightInPixels)
|
||||
{
|
||||
DWORD y = 0;
|
||||
const DWORD y0 = min(rcDest.bottom, dwHeightInPixels);
|
||||
|
||||
// Lines above the destination rectangle.
|
||||
for ( ; y < rcDest.top; y++)
|
||||
{
|
||||
memcpy(pDest, pSrc, dwWidthInPixels * 2);
|
||||
pSrc += lSrcStride;
|
||||
pDest += lDestStride;
|
||||
}
|
||||
|
||||
// Lines within the destination rectangle.
|
||||
for ( ; y < y0; y++)
|
||||
{
|
||||
WORD *pSrc_Pixel = (WORD*)pSrc;
|
||||
WORD *pDest_Pixel = (WORD*)pDest;
|
||||
|
||||
for (DWORD x = 0; (x + 1) < dwWidthInPixels; x += 2)
|
||||
{
|
||||
// Byte order is U0 Y0 V0 Y1
|
||||
// Each WORD is a byte pair (U/V, Y)
|
||||
// Windows is little-endian so the order appears reversed.
|
||||
|
||||
if (x >= rcDest.left && x < rcDest.right)
|
||||
{
|
||||
BYTE u = pSrc_Pixel[x] & 0x00FF;
|
||||
BYTE v = pSrc_Pixel[x+1] & 0x00FF;
|
||||
|
||||
TransformChroma(mat, &u, &v);
|
||||
|
||||
pDest_Pixel[x] = (pSrc_Pixel[x] & 0xFF00) | u;
|
||||
pDest_Pixel[x+1] = (pSrc_Pixel[x+1] & 0xFF00) | v;
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 6385)
|
||||
#pragma warning(disable: 6386)
|
||||
pDest_Pixel[x] = pSrc_Pixel[x];
|
||||
pDest_Pixel[x+1] = pSrc_Pixel[x+1];
|
||||
#pragma warning(pop)
|
||||
}
|
||||
}
|
||||
|
||||
pDest += lDestStride;
|
||||
pSrc += lSrcStride;
|
||||
}
|
||||
|
||||
// Lines below the destination rectangle.
|
||||
for ( ; y < dwHeightInPixels; y++)
|
||||
{
|
||||
memcpy(pDest, pSrc, dwWidthInPixels * 2);
|
||||
pSrc += lSrcStride;
|
||||
pDest += lDestStride;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Convert YUY2 image.
|
||||
|
||||
void TransformImage_YUY2(
|
||||
const D2D1::Matrix3x2F& mat,
|
||||
const D2D_RECT_U& rcDest,
|
||||
_Inout_updates_(_Inexpressible_(lDestStride * dwHeightInPixels)) BYTE *pDest,
|
||||
_In_ LONG lDestStride,
|
||||
_In_reads_(_Inexpressible_(lSrcStride * dwHeightInPixels)) const BYTE* pSrc,
|
||||
_In_ LONG lSrcStride,
|
||||
_In_ DWORD dwWidthInPixels,
|
||||
_In_ DWORD dwHeightInPixels)
|
||||
{
|
||||
DWORD y = 0;
|
||||
const DWORD y0 = min(rcDest.bottom, dwHeightInPixels);
|
||||
|
||||
// Lines above the destination rectangle.
|
||||
for ( ; y < rcDest.top; y++)
|
||||
{
|
||||
memcpy(pDest, pSrc, dwWidthInPixels * 2);
|
||||
pSrc += lSrcStride;
|
||||
pDest += lDestStride;
|
||||
}
|
||||
|
||||
// Lines within the destination rectangle.
|
||||
for ( ; y < y0; y++)
|
||||
{
|
||||
WORD *pSrc_Pixel = (WORD*)pSrc;
|
||||
WORD *pDest_Pixel = (WORD*)pDest;
|
||||
|
||||
for (DWORD x = 0; (x + 1) < dwWidthInPixels; x += 2)
|
||||
{
|
||||
// Byte order is Y0 U0 Y1 V0
|
||||
// Each WORD is a byte pair (Y, U/V)
|
||||
// Windows is little-endian so the order appears reversed.
|
||||
|
||||
if (x >= rcDest.left && x < rcDest.right)
|
||||
{
|
||||
BYTE u = pSrc_Pixel[x] >> 8;
|
||||
BYTE v = pSrc_Pixel[x+1] >> 8;
|
||||
|
||||
TransformChroma(mat, &u, &v);
|
||||
|
||||
pDest_Pixel[x] = (pSrc_Pixel[x] & 0x00FF) | (u<<8);
|
||||
pDest_Pixel[x+1] = (pSrc_Pixel[x+1] & 0x00FF) | (v<<8);
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 6385)
|
||||
#pragma warning(disable: 6386)
|
||||
pDest_Pixel[x] = pSrc_Pixel[x];
|
||||
pDest_Pixel[x+1] = pSrc_Pixel[x+1];
|
||||
#pragma warning(pop)
|
||||
}
|
||||
}
|
||||
pDest += lDestStride;
|
||||
pSrc += lSrcStride;
|
||||
}
|
||||
|
||||
// Lines below the destination rectangle.
|
||||
for ( ; y < dwHeightInPixels; y++)
|
||||
{
|
||||
memcpy(pDest, pSrc, dwWidthInPixels * 2);
|
||||
pSrc += lSrcStride;
|
||||
pDest += lDestStride;
|
||||
}
|
||||
}
|
||||
|
||||
// Convert NV12 image
|
||||
|
||||
void TransformImage_NV12(
|
||||
@ -307,7 +147,8 @@ void TransformImage_NV12(
|
||||
|
||||
// Lines above the destination rectangle.
|
||||
DWORD y = 0;
|
||||
const DWORD y0 = min(rcDest.bottom, dwHeightInPixels);
|
||||
|
||||
const DWORD y0 = rcDest.bottom < dwHeightInPixels ? rcDest.bottom : dwHeightInPixels;
|
||||
|
||||
for ( ; y < rcDest.top/2; y++)
|
||||
{
|
||||
@ -323,13 +164,8 @@ void TransformImage_NV12(
|
||||
{
|
||||
if (x >= rcDest.left && x < rcDest.right)
|
||||
{
|
||||
BYTE u = pSrc[x];
|
||||
BYTE v = pSrc[x+1];
|
||||
|
||||
TransformChroma(mat, &u, &v);
|
||||
|
||||
pDest[x] = u;
|
||||
pDest[x+1] = v;
|
||||
pDest[x] = 0;
|
||||
pDest[x+1] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -351,9 +187,9 @@ void TransformImage_NV12(
|
||||
}
|
||||
|
||||
CGrayscale::CGrayscale() :
|
||||
m_pSample(NULL), m_pInputType(NULL), m_pOutputType(NULL), m_pTransformFn(NULL),
|
||||
m_pSample(NULL), m_pInputType(NULL), m_pOutputType(NULL),
|
||||
m_imageWidthInPixels(0), m_imageHeightInPixels(0), m_cbImageSize(0),
|
||||
m_transform(D2D1::Matrix3x2F::Identity()), m_rcDest(D2D1::RectU()), m_bStreamingInitialized(false),
|
||||
m_TransformType(Preview), m_rcDest(D2D1::RectU()), m_bStreamingInitialized(false),
|
||||
m_pAttributes(NULL)
|
||||
{
|
||||
InitializeCriticalSectionEx(&m_critSec, 3000, 0);
|
||||
@ -1516,10 +1352,8 @@ HRESULT CGrayscale::BeginStreaming()
|
||||
|
||||
// Get the chroma transformations.
|
||||
|
||||
float scale = (float)MFGetAttributeDouble(m_pAttributes, MFT_GRAYSCALE_SATURATION, 0.0f);
|
||||
float angle = (float)MFGetAttributeDouble(m_pAttributes, MFT_GRAYSCALE_CHROMA_ROTATION, 0.0f);
|
||||
|
||||
m_transform = D2D1::Matrix3x2F::Scale(scale, scale) * D2D1::Matrix3x2F::Rotation(angle);
|
||||
// float scale = (float)MFGetAttributeDouble(m_pAttributes, MFT_GRAYSCALE_SATURATION, 0.0f);
|
||||
// float angle = (float)MFGetAttributeDouble(m_pAttributes, MFT_GRAYSCALE_CHROMA_ROTATION, 0.0f);
|
||||
|
||||
m_bStreamingInitialized = true;
|
||||
}
|
||||
@ -1563,42 +1397,36 @@ HRESULT CGrayscale::OnProcessOutput(IMFMediaBuffer *pIn, IMFMediaBuffer *pOut)
|
||||
HRESULT hr = GetDefaultStride(m_pInputType, &lDefaultStride);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
goto done;
|
||||
return hr;
|
||||
}
|
||||
|
||||
// Lock the input buffer.
|
||||
hr = inputLock.LockBuffer(lDefaultStride, m_imageHeightInPixels, &pSrc, &lSrcStride);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
goto done;
|
||||
return hr;
|
||||
}
|
||||
|
||||
// Lock the output buffer.
|
||||
hr = outputLock.LockBuffer(lDefaultStride, m_imageHeightInPixels, &pDest, &lDestStride);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
goto done;
|
||||
}
|
||||
|
||||
// Invoke the image transform function.
|
||||
assert (m_pTransformFn != NULL);
|
||||
if (m_pTransformFn)
|
||||
{
|
||||
(*m_pTransformFn)(m_transform, m_rcDest, pDest, lDestStride, pSrc, lSrcStride,
|
||||
m_imageWidthInPixels, m_imageHeightInPixels);
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = E_UNEXPECTED;
|
||||
goto done;
|
||||
return hr;
|
||||
}
|
||||
|
||||
//(*m_pTransformFn)(m_transform, m_rcDest, pDest, lDestStride, pSrc, lSrcStride,
|
||||
// m_imageWidthInPixels, m_imageHeightInPixels);
|
||||
|
||||
cv::Mat InputFrame(m_imageHeightInPixels + m_imageHeightInPixels/2, m_imageWidthInPixels, CV_8UC1, pSrc, lSrcStride);
|
||||
cv::Mat InputGreyScale(InputFrame, cv::Range(0, m_imageHeightInPixels), cv::Range(0, m_imageWidthInPixels));
|
||||
cv::Mat OutputFrame(m_imageHeightInPixels + m_imageHeightInPixels/2, m_imageWidthInPixels, CV_8UC1, pDest, lDestStride);
|
||||
OutputFrame.setTo(cv::Scalar(128));
|
||||
cv::Mat OutputGreyScale(OutputFrame, cv::Range(0, m_imageHeightInPixels), cv::Range(0, m_imageWidthInPixels));
|
||||
cv::Canny(InputGreyScale, OutputGreyScale, 80, 90);
|
||||
|
||||
// Set the data size on the output buffer.
|
||||
hr = pOut->SetCurrentLength(m_cbImageSize);
|
||||
|
||||
// The VideoBufferLock class automatically unlocks the buffers.
|
||||
done:
|
||||
return hr;
|
||||
}
|
||||
|
||||
@ -1626,8 +1454,6 @@ HRESULT CGrayscale::UpdateFormatInfo()
|
||||
m_imageHeightInPixels = 0;
|
||||
m_cbImageSize = 0;
|
||||
|
||||
m_pTransformFn = NULL;
|
||||
|
||||
if (m_pInputType != NULL)
|
||||
{
|
||||
hr = m_pInputType->GetGUID(MF_MT_SUBTYPE, &subtype);
|
||||
@ -1635,19 +1461,7 @@ HRESULT CGrayscale::UpdateFormatInfo()
|
||||
{
|
||||
goto done;
|
||||
}
|
||||
if (subtype == MFVideoFormat_YUY2)
|
||||
{
|
||||
m_pTransformFn = TransformImage_YUY2;
|
||||
}
|
||||
else if (subtype == MFVideoFormat_UYVY)
|
||||
{
|
||||
m_pTransformFn = TransformImage_UYVY;
|
||||
}
|
||||
else if (subtype == MFVideoFormat_NV12)
|
||||
{
|
||||
m_pTransformFn = TransformImage_NV12;
|
||||
}
|
||||
else
|
||||
if (subtype != MFVideoFormat_NV12)
|
||||
{
|
||||
hr = E_UNEXPECTED;
|
||||
goto done;
|
||||
@ -1678,20 +1492,6 @@ HRESULT GetImageSize(DWORD fcc, UINT32 width, UINT32 height, DWORD* pcbImage)
|
||||
|
||||
switch (fcc)
|
||||
{
|
||||
case FOURCC_YUY2:
|
||||
case FOURCC_UYVY:
|
||||
// check overflow
|
||||
if ((width > MAXDWORD / 2) || (width * 2 > MAXDWORD / height))
|
||||
{
|
||||
hr = E_INVALIDARG;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 16 bpp
|
||||
*pcbImage = width * height * 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case FOURCC_NV12:
|
||||
// check overflow
|
||||
if ((height/2 > MAXDWORD - height) || ((height + height/2) > MAXDWORD / width))
|
||||
|
@ -42,15 +42,14 @@ DEFINE_GUID(CLSID_GrayscaleMFT,
|
||||
DEFINE_GUID(MFT_GRAYSCALE_DESTINATION_RECT,
|
||||
0x7bbbb051, 0x133b, 0x41f5, 0xb6, 0xaa, 0x5a, 0xff, 0x9b, 0x33, 0xa2, 0xcb);
|
||||
|
||||
|
||||
// {14782342-93E8-4565-872C-D9A2973D5CBF}
|
||||
DEFINE_GUID(MFT_GRAYSCALE_SATURATION,
|
||||
0x14782342, 0x93e8, 0x4565, 0x87, 0x2c, 0xd9, 0xa2, 0x97, 0x3d, 0x5c, 0xbf);
|
||||
|
||||
// {E0BADE5D-E4B9-4689-9DBA-E2F00D9CED0E}
|
||||
DEFINE_GUID(MFT_GRAYSCALE_CHROMA_ROTATION,
|
||||
0xe0bade5d, 0xe4b9, 0x4689, 0x9d, 0xba, 0xe2, 0xf0, 0xd, 0x9c, 0xed, 0xe);
|
||||
|
||||
enum ProcessingType
|
||||
{
|
||||
Preview,
|
||||
GrayScale,
|
||||
Canny,
|
||||
Zoom,
|
||||
Sepia
|
||||
};
|
||||
|
||||
template <class T> void SafeRelease(T **ppT)
|
||||
{
|
||||
@ -61,18 +60,6 @@ template <class T> void SafeRelease(T **ppT)
|
||||
}
|
||||
}
|
||||
|
||||
// Function pointer for the function that transforms the image.
|
||||
typedef void (*IMAGE_TRANSFORM_FN)(
|
||||
const D2D1::Matrix3x2F& mat, // Chroma transform matrix.
|
||||
const D2D_RECT_U& rcDest, // Destination rectangle for the transformation.
|
||||
BYTE* pDest, // Destination buffer.
|
||||
LONG lDestStride, // Destination stride.
|
||||
const BYTE* pSrc, // Source buffer.
|
||||
LONG lSrcStride, // Source stride.
|
||||
DWORD dwWidthInPixels, // Image width in pixels.
|
||||
DWORD dwHeightInPixels // Image height in pixels.
|
||||
);
|
||||
|
||||
// CGrayscale class:
|
||||
// Implements a grayscale video effect.
|
||||
|
||||
@ -244,7 +231,7 @@ private:
|
||||
CRITICAL_SECTION m_critSec;
|
||||
|
||||
// Transformation parameters
|
||||
D2D1::Matrix3x2F m_transform; // Chroma transform matrix.
|
||||
ProcessingType m_TransformType;
|
||||
D2D_RECT_U m_rcDest; // Destination rectangle for the effect.
|
||||
|
||||
// Streaming
|
||||
@ -259,8 +246,5 @@ private:
|
||||
DWORD m_cbImageSize; // Image size, in bytes.
|
||||
|
||||
IMFAttributes *m_pAttributes;
|
||||
|
||||
// Image transform function. (Changes based on the media type.)
|
||||
IMAGE_TRANSFORM_FN m_pTransformFn;
|
||||
};
|
||||
#endif
|
@ -123,13 +123,14 @@
|
||||
</PrecompiledHeaderOutputFile>
|
||||
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
|
||||
<CompileAsWinRT>false</CompileAsWinRT>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common;</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(OPENCV_DIR)\include;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>runtimeobject.lib;%(AdditionalDependencies);mf.lib;mfuuid.lib;mfplat.lib</AdditionalDependencies>
|
||||
<AdditionalDependencies>runtimeobject.lib;%(AdditionalDependencies);mf.lib;mfuuid.lib;mfplat.lib;opencv_core245.lib;opencv_imgproc245.lib</AdditionalDependencies>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ModuleDefinitionFile>Grayscale.def</ModuleDefinitionFile>
|
||||
<AdditionalLibraryDirectories>$(OPENCV_DIR)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<CustomBuildStep>
|
||||
<Command>mdmerge -metadata_dir "$(WindowsSDK_MetadataPath)" -o "$(ProjectDir)$(Configuration)\$(MSBuildProjectName)" -i "$(MSBuildProjectDirectory)" -v -partial</Command>
|
||||
@ -146,13 +147,14 @@
|
||||
</PrecompiledHeaderOutputFile>
|
||||
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
|
||||
<CompileAsWinRT>false</CompileAsWinRT>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common;</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(OPENCV_DIR)\include;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>runtimeobject.lib;%(AdditionalDependencies);mf.lib;mfuuid.lib;mfplat.lib</AdditionalDependencies>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ModuleDefinitionFile>Grayscale.def</ModuleDefinitionFile>
|
||||
<AdditionalLibraryDirectories>$(OPENCV_DIR)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<CustomBuildStep>
|
||||
<Command>mdmerge -metadata_dir "$(WindowsSDK_MetadataPath)" -o "$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)" -i "$(MSBuildProjectDirectory)" -v -partial</Command>
|
||||
@ -169,13 +171,14 @@
|
||||
</PrecompiledHeaderOutputFile>
|
||||
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
|
||||
<CompileAsWinRT>false</CompileAsWinRT>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common;</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(OPENCV_DIR)\include;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>runtimeobject.lib;%(AdditionalDependencies);mf.lib;mfuuid.lib;mfplat.lib</AdditionalDependencies>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ModuleDefinitionFile>Grayscale.def</ModuleDefinitionFile>
|
||||
<AdditionalLibraryDirectories>$(OPENCV_DIR)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<CustomBuildStep>
|
||||
<Command>mdmerge -metadata_dir "$(WindowsSDK_MetadataPath)" -o "$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)" -i "$(MSBuildProjectDirectory)" -v -partial</Command>
|
||||
@ -192,13 +195,14 @@
|
||||
</PrecompiledHeaderOutputFile>
|
||||
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
|
||||
<CompileAsWinRT>false</CompileAsWinRT>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common;</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(OPENCV_DIR)\include;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>runtimeobject.lib;%(AdditionalDependencies);mf.lib;mfuuid.lib;mfplat.lib</AdditionalDependencies>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ModuleDefinitionFile>Grayscale.def</ModuleDefinitionFile>
|
||||
<AdditionalLibraryDirectories>$(OPENCV_DIR)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<CustomBuildStep>
|
||||
<Command>mdmerge -metadata_dir "$(WindowsSDK_MetadataPath)" -o "$(ProjectDir)$(Configuration)\$(MSBuildProjectName)" -i "$(MSBuildProjectDirectory)" -v -partial</Command>
|
||||
@ -215,13 +219,14 @@
|
||||
</PrecompiledHeaderOutputFile>
|
||||
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
|
||||
<CompileAsWinRT>false</CompileAsWinRT>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common;</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(OPENCV_DIR)\include;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>runtimeobject.lib;%(AdditionalDependencies);mf.lib;mfuuid.lib;mfplat.lib</AdditionalDependencies>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ModuleDefinitionFile>Grayscale.def</ModuleDefinitionFile>
|
||||
<AdditionalLibraryDirectories>$(OPENCV_DIR)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<CustomBuildStep>
|
||||
<Command>mdmerge -metadata_dir "$(WindowsSDK_MetadataPath)" -o "$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)" -i "$(MSBuildProjectDirectory)" -v -partial</Command>
|
||||
@ -238,13 +243,14 @@
|
||||
</PrecompiledHeaderOutputFile>
|
||||
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
|
||||
<CompileAsWinRT>false</CompileAsWinRT>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common;</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(OPENCV_DIR)\include;$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories);$(ProjectDir)\..\Common</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<AdditionalDependencies>runtimeobject.lib;%(AdditionalDependencies);mf.lib;mfuuid.lib;mfplat.lib</AdditionalDependencies>
|
||||
<IgnoreAllDefaultLibraries>false</IgnoreAllDefaultLibraries>
|
||||
<ModuleDefinitionFile>Grayscale.def</ModuleDefinitionFile>
|
||||
<AdditionalLibraryDirectories>$(OPENCV_DIR)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<CustomBuildStep>
|
||||
<Command>mdmerge -metadata_dir "$(WindowsSDK_MetadataPath)" -o "$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)" -i "$(MSBuildProjectDirectory)" -v -partial</Command>
|
||||
|
Loading…
Reference in New Issue
Block a user