Commit bf22567c authored by Alexander Smorkalov's avatar Alexander Smorkalov

Transform selection implemented in sample GUI.

Gistogram output does not work propertly due color conversion problems.
parent de9f659f
...@@ -33,38 +33,31 @@ ...@@ -33,38 +33,31 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Grid.Row="0" Text="This scenario shows how to enumerate cameras in the system. Choose a camera from the list to preview, record or take a photo from the chosen camera. You can add the gray scale effect using the checkbox provided." Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left"/> <TextBlock TextWrapping="Wrap" Grid.Row="0" Text="This scenario shows how to enumerate cameras in the system. Choose a camera from the list to preview, record or take a photo from the chosen camera. You can add the gray scale effect using the checkbox provided." Style="{StaticResource BasicTextStyle}" HorizontalAlignment="Left"/>
<StackPanel Orientation="Horizontal" Grid.Row="1" Margin="0,10,0,0"> <StackPanel Orientation="Horizontal" Grid.Row="1" Margin="0,10,0,0">
<ListBox x:Name="EnumedDeviceList2" SelectionChanged="lstEnumedDevices_SelectionChanged" ></ListBox> <ListBox x:Name="EnumedDeviceList2" SelectionChanged="lstEnumedDevices_SelectionChanged" />
<Button x:Name="btnStartDevice2" Click="btnStartDevice_Click" IsEnabled="true" Margin="0,0,10,0">StartDevice</Button> <Button x:Name="btnStartDevice2" Click="btnStartDevice_Click" IsEnabled="true" Margin="0,0,10,0" Content="StartDevice"/>
<Button x:Name="btnStartPreview2" Click="btnStartPreview_Click" IsEnabled="true" Margin="0,0,10,0">StartPreview</Button> <Button x:Name="btnStartPreview2" Click="btnStartPreview_Click" IsEnabled="true" Margin="0,0,10,0" Content="StartPreview"/>
<Button x:Name="btnStartStopRecord2" Click="btnStartStopRecord_Click" IsEnabled="false" Margin="0,0,10,0">StartRecord</Button> <ComboBox x:Name="EffectTypeCombo" Width="120" SelectedIndex="0">
<Button x:Name="btnTakePhoto2" Click="btnTakePhoto_Click" IsEnabled="false" Margin="0,0,10,0">TakePhoto</Button> <ComboBoxItem Content="Preview"/>
</StackPanel> <ComboBoxItem Content="Grayscale"/>
<StackPanel Orientation="Horizontal" Grid.Row="2" Margin="0,10,0,0"> <ComboBoxItem Content="Canny"/>
<CheckBox x:Name="chkAddRemoveEffect" Margin="0,0,10,0" Content="Add Effect" IsEnabled="False" Checked="chkAddRemoveEffect_Checked" Unchecked="chkAddRemoveEffect_Unchecked"/> <ComboBoxItem Content="Sobel"/>
<ComboBox Width="120"/> <ComboBoxItem Content="Histogram"/>
</ComboBox>
<Button Content="Apply" HorizontalAlignment="Stretch" VerticalAlignment="Top" Click="Button_Click"/>
</StackPanel> </StackPanel>
<StackPanel x:Name="EffectTypeCombo1" Orientation="Horizontal" Grid.Row="1" Margin="324,5,-324,7"/>
</Grid> </Grid>
<Grid x:Name="Output" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1"> <Grid x:Name="Output" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1">
<StackPanel Orientation="Horizontal" Margin="0,10,0,0"> <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<StackPanel> <StackPanel>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Preview' /> <TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Preview' />
<Canvas x:Name="previewCanvas2" Width="320" Height="240" Background="Gray"> <Canvas x:Name="previewCanvas2" Background="Gray">
<CaptureElement x:Name="previewElement2" Width="320" Height="240" /> <CaptureElement x:Name="previewElement2" />
</Canvas>
</StackPanel>
<StackPanel>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Captured Video' />
<Canvas x:Name='playbackCanvas2' Width='320' Height ='240' >
<MediaElement x:Name='playbackElement2' Width="320" Height="240" />
</Canvas>
</StackPanel>
<StackPanel>
<TextBlock Style="{StaticResource BasicTextStyle}" HorizontalAlignment='Center' VerticalAlignment='Center' TextAlignment='Center' Text='Captured Images' />
<Canvas x:Name="imageCanvas2" Width='320' Height ='240' >
<Image x:Name="imageElement2" Width="320" Height="240"/>
</Canvas> </Canvas>
</StackPanel> </StackPanel>
<StackPanel/>
<StackPanel/>
</StackPanel> </StackPanel>
</Grid> </Grid>
......
...@@ -49,18 +49,12 @@ namespace SDKSample ...@@ -49,18 +49,12 @@ namespace SDKSample
void ScenarioInit(); void ScenarioInit();
void ScenarioReset(); 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 Failed(Windows::Media::Capture::MediaCapture ^ mediaCapture, Windows::Media::Capture::MediaCaptureFailedEventArgs ^ args);
void btnStartDevice_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void btnStartDevice_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void btnStartPreview_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 btnTakePhoto_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void lstEnumedDevices_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e); void lstEnumedDevices_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e);
void EnumerateWebcamsAsync(); void EnumerateWebcamsAsync();
...@@ -72,7 +66,6 @@ namespace SDKSample ...@@ -72,7 +66,6 @@ namespace SDKSample
void ShowExceptionMessage(Platform::Exception^ ex); void ShowExceptionMessage(Platform::Exception^ ex);
void EnableButton(bool enabled, Platform::String ^name); void EnableButton(bool enabled, Platform::String ^name);
void SwitchRecordButtonContent();
task<Windows::Storage::StorageFile^> ReencodePhotoAsync( task<Windows::Storage::StorageFile^> ReencodePhotoAsync(
Windows::Storage::StorageFile ^tempStorageFile, Windows::Storage::StorageFile ^tempStorageFile,
...@@ -98,7 +91,8 @@ namespace SDKSample ...@@ -98,7 +91,8 @@ namespace SDKSample
bool m_bRotateVideoOnOrientationChange; bool m_bRotateVideoOnOrientationChange;
bool m_bReversePreviewRotation; bool m_bReversePreviewRotation;
Windows::Foundation::EventRegistrationToken m_orientationChangedEventToken; Windows::Foundation::EventRegistrationToken m_orientationChangedEventToken;
void EffectType_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e); void EffectTypeCombo_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e);
void Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
}; };
} }
} }
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
#include "pch.h" #include "pch.h"
#include "MainPage.xaml.h" #include "MainPage.xaml.h"
#include "AdvancedCapture.xaml.h"
#include "Common\SuspensionManager.h" #include "Common\SuspensionManager.h"
using namespace SDKSample; using namespace SDKSample;
using namespace SDKSample::Common; using namespace SDKSample::Common;
using namespace SDKSample::MediaCapture;
using namespace Concurrency; using namespace Concurrency;
using namespace Platform; using namespace Platform;
......
...@@ -93,7 +93,7 @@ void MainPage::InvalidateSize() ...@@ -93,7 +93,7 @@ void MainPage::InvalidateSize()
{ {
// Make us as big as the the left over space, factoring in the ListBox width, the ListBox margins. // Make us as big as the the left over space, factoring in the ListBox width, the ListBox margins.
// and the LayoutRoot's margins // and the LayoutRoot's margins
InputSection->Width = ((availableWidth) - InputSection->Width = ((availableWidth) -
(layoutRootMarginLeft + layoutRootMarginRight + listBoxMarginLeft + listBoxMarginRight)); (layoutRootMarginLeft + layoutRootMarginRight + listBoxMarginLeft + listBoxMarginRight));
} }
else else
...@@ -161,7 +161,7 @@ void MainPage::PopulateScenarios() ...@@ -161,7 +161,7 @@ void MainPage::PopulateScenarios()
} }
/// <summary> /// <summary>
/// This method is responsible for loading the individual input and output sections for each scenario. This /// This method is responsible for loading the individual input and output sections for each scenario. This
/// is based on navigating a hidden Frame to the ScenarioX.xaml page and then extracting out the input /// is based on navigating a hidden Frame to the ScenarioX.xaml page and then extracting out the input
/// and output sections into the respective UserControl on the main page. /// and output sections into the respective UserControl on the main page.
/// </summary> /// </summary>
...@@ -185,7 +185,7 @@ void MainPage::LoadScenario(String^ scenarioName) ...@@ -185,7 +185,7 @@ void MainPage::LoadScenario(String^ scenarioName)
if (input == nullptr) if (input == nullptr)
{ {
// Malformed input section. // Malformed input section.
NotifyUser("Cannot load scenario input section for " + scenarioName + NotifyUser("Cannot load scenario input section for " + scenarioName +
" Make sure root of input section markup has x:Name of 'Input'", NotifyType::ErrorMessage); " Make sure root of input section markup has x:Name of 'Input'", NotifyType::ErrorMessage);
return; return;
} }
...@@ -193,7 +193,7 @@ void MainPage::LoadScenario(String^ scenarioName) ...@@ -193,7 +193,7 @@ void MainPage::LoadScenario(String^ scenarioName)
if (output == nullptr) if (output == nullptr)
{ {
// Malformed output section. // Malformed output section.
NotifyUser("Cannot load scenario output section for " + scenarioName + NotifyUser("Cannot load scenario output section for " + scenarioName +
" Make sure root of output section markup has x:Name of 'Output'", NotifyType::ErrorMessage); " Make sure root of output section markup has x:Name of 'Output'", NotifyType::ErrorMessage);
return; return;
} }
...@@ -222,7 +222,7 @@ void MainPage::LoadScenario(String^ scenarioName) ...@@ -222,7 +222,7 @@ void MainPage::LoadScenario(String^ scenarioName)
else else
{ {
// Malformed Scenario file. // Malformed Scenario file.
NotifyUser("Cannot load scenario: " + scenarioName + ". Make sure root tag in the '" + NotifyUser("Cannot load scenario: " + scenarioName + ". Make sure root tag in the '" +
scenarioName + "' file has an x:Name of 'LayoutRoot'", NotifyType::ErrorMessage); scenarioName + "' file has an x:Name of 'LayoutRoot'", NotifyType::ErrorMessage);
} }
} }
...@@ -284,7 +284,7 @@ void MainPage::Footer_Click(Object^ sender, RoutedEventArgs^ e) ...@@ -284,7 +284,7 @@ void MainPage::Footer_Click(Object^ sender, RoutedEventArgs^ e)
/// session. This will be null the first time a page is visited.</param> /// session. This will be null the first time a page is visited.</param>
void MainPage::LoadState(Object^ navigationParameter, IMap<String^, Object^>^ pageState) void MainPage::LoadState(Object^ navigationParameter, IMap<String^, Object^>^ pageState)
{ {
(void) navigationParameter; // Unused parameter (void) navigationParameter; // Unused parameter
PopulateScenarios(); PopulateScenarios();
......
...@@ -122,9 +122,7 @@ ...@@ -122,9 +122,7 @@
<Page Include="Common\StandardStyles.xaml"> <Page Include="Common\StandardStyles.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
<Page Include="MainPage.xaml"> <Page Include="MainPage.xaml" />
<SubType>Designer</SubType>
</Page>
<Page Include="Sample-Utils\SampleTemplateStyles.xaml"> <Page Include="Sample-Utils\SampleTemplateStyles.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
......
...@@ -189,7 +189,7 @@ void TransformImage_NV12( ...@@ -189,7 +189,7 @@ void TransformImage_NV12(
CGrayscale::CGrayscale() : CGrayscale::CGrayscale() :
m_pSample(NULL), m_pInputType(NULL), m_pOutputType(NULL), m_pSample(NULL), m_pInputType(NULL), m_pOutputType(NULL),
m_imageWidthInPixels(0), m_imageHeightInPixels(0), m_cbImageSize(0), m_imageWidthInPixels(0), m_imageHeightInPixels(0), m_cbImageSize(0),
m_TransformType(Preview), m_rcDest(D2D1::RectU()), m_bStreamingInitialized(false), m_TransformType(Preview), m_bStreamingInitialized(false),
m_pAttributes(NULL) m_pAttributes(NULL)
{ {
InitializeCriticalSectionEx(&m_critSec, 3000, 0); InitializeCriticalSectionEx(&m_critSec, 3000, 0);
...@@ -219,7 +219,32 @@ STDMETHODIMP CGrayscale::RuntimeClassInitialize() ...@@ -219,7 +219,32 @@ STDMETHODIMP CGrayscale::RuntimeClassInitialize()
//------------------------------------------------------------------- //-------------------------------------------------------------------
HRESULT CGrayscale::SetProperties(ABI::Windows::Foundation::Collections::IPropertySet *pConfiguration) HRESULT CGrayscale::SetProperties(ABI::Windows::Foundation::Collections::IPropertySet *pConfiguration)
{ {
return S_OK; HRESULT hr = S_OK;
if (!pConfiguration)
return hr;
HSTRING key;
WindowsCreateString(L"{698649BE-8EAE-4551-A4CB-3EC98FBD3D86}", 38, &key);
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Collections::IMap<HSTRING, IInspectable *>> spSetting;
pConfiguration->QueryInterface(IID_PPV_ARGS(&spSetting));
boolean found;
spSetting->HasKey(key, &found);
if (found)
{
IInspectable* value;
spSetting->Lookup(key, &value);
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IReference<int>> ref;
value->QueryInterface(IID_PPV_ARGS(&ref));
int effect = InvalidEffect;
ref->get_Value(&effect);
if ((effect >= 0) && (effect < InvalidEffect))
{
m_TransformType = (ProcessingType)effect;
}
}
} }
// IMFTransform methods. Refer to the Media Foundation SDK documentation for details. // IMFTransform methods. Refer to the Media Foundation SDK documentation for details.
...@@ -1327,41 +1352,10 @@ HRESULT CGrayscale::BeginStreaming() ...@@ -1327,41 +1352,10 @@ HRESULT CGrayscale::BeginStreaming()
if (!m_bStreamingInitialized) if (!m_bStreamingInitialized)
{ {
// Get the configuration attributes.
// Get the destination rectangle.
RECT rcDest;
hr = m_pAttributes->GetBlob(MFT_GRAYSCALE_DESTINATION_RECT, (UINT8*)&rcDest, sizeof(rcDest), NULL);
if (hr == MF_E_ATTRIBUTENOTFOUND || !ValidateRect(rcDest))
{
// The client did not set this attribute, or the client provided an invalid rectangle.
// Default to the entire image.
m_rcDest = D2D1::RectU(0, 0, m_imageWidthInPixels, m_imageHeightInPixels);
hr = S_OK;
}
else if (SUCCEEDED(hr))
{
m_rcDest = D2D1::RectU(rcDest.left, rcDest.top, rcDest.right, rcDest.bottom);
}
else
{
goto done;
}
// Get the effect type
UINT32 effect = MFGetAttributeUINT32(m_pAttributes, MFT_IMAGE_EFFECT, 1);
if ((effect >= 0) && (effect < InvalidEffect))
{
m_TransformType = (ProcessingType)effect;
}
m_bStreamingInitialized = true; m_bStreamingInitialized = true;
hr = S_OK;
} }
done:
return hr; return hr;
} }
...@@ -1465,14 +1459,14 @@ HRESULT CGrayscale::OnProcessOutput(IMFMediaBuffer *pIn, IMFMediaBuffer *pOut) ...@@ -1465,14 +1459,14 @@ HRESULT CGrayscale::OnProcessOutput(IMFMediaBuffer *pIn, IMFMediaBuffer *pOut)
// RGB // RGB
for (int c=0; c<3; c++) for (int c=0; c<3; c++)
{ {
std::vector<int> hist; cv::Mat hist;
cv::calcHist(&BgrFrame, 1, channels[c], cv::Mat(), hist, 1, mHistSize, ranges); cv::calcHist(&BgrFrame, 1, channels[c], cv::Mat(), hist, 1, mHistSize, ranges);
cv::normalize(hist, hist, BgrFrame.rows/2, 0, cv::NORM_INF); cv::normalize(hist, hist, BgrFrame.rows/2, 0, cv::NORM_INF);
for(int h=0; h<mHistSizeNum; h++) { for(int h=0; h<mHistSizeNum; h++) {
cv::Point mP1, mP2; cv::Point mP1, mP2;
mP1.x = mP2.x = offset + (c * (mHistSizeNum + 10) + h) * thikness; mP1.x = mP2.x = offset + (c * (mHistSizeNum + 10) + h) * thikness;
mP1.y = BgrFrame.rows-1; mP1.y = BgrFrame.rows-1;
mP2.y = mP1.y - 2 - (int)hist[h]; mP2.y = mP1.y - 2 - hist.at<float>(h);
cv::line(BgrFrame, mP1, mP2, mColorsRGB[c], thikness); cv::line(BgrFrame, mP1, mP2, mColorsRGB[c], thikness);
} }
} }
......
...@@ -44,6 +44,7 @@ DEFINE_GUID(MFT_IMAGE_EFFECT, ...@@ -44,6 +44,7 @@ DEFINE_GUID(MFT_IMAGE_EFFECT,
enum ProcessingType enum ProcessingType
{ {
Preview,
GrayScale, GrayScale,
Canny, Canny,
Sobel, Sobel,
...@@ -232,7 +233,6 @@ private: ...@@ -232,7 +233,6 @@ private:
// Transformation parameters // Transformation parameters
ProcessingType m_TransformType; ProcessingType m_TransformType;
D2D_RECT_U m_rcDest; // Destination rectangle for the effect.
// Streaming // Streaming
bool m_bStreamingInitialized; bool m_bStreamingInitialized;
......
...@@ -22,9 +22,6 @@ ...@@ -22,9 +22,6 @@
</Application> </Application>
</Applications> </Applications>
<Capabilities> <Capabilities>
<Capability Name="picturesLibrary" />
<Capability Name="musicLibrary" />
<Capability Name="videosLibrary" />
<DeviceCapability Name="webcam" /> <DeviceCapability Name="webcam" />
<DeviceCapability Name="microphone" /> <DeviceCapability Name="microphone" />
</Capabilities> </Capabilities>
......
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