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 @@
</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"/>
<StackPanel Orientation="Horizontal" Grid.Row="1" Margin="0,10,0,0">
<ListBox x:Name="EnumedDeviceList2" SelectionChanged="lstEnumedDevices_SelectionChanged" ></ListBox>
<Button x:Name="btnStartDevice2" Click="btnStartDevice_Click" IsEnabled="true" Margin="0,0,10,0">StartDevice</Button>
<Button x:Name="btnStartPreview2" Click="btnStartPreview_Click" IsEnabled="true" Margin="0,0,10,0">StartPreview</Button>
<Button x:Name="btnStartStopRecord2" Click="btnStartStopRecord_Click" IsEnabled="false" Margin="0,0,10,0">StartRecord</Button>
<Button x:Name="btnTakePhoto2" Click="btnTakePhoto_Click" IsEnabled="false" Margin="0,0,10,0">TakePhoto</Button>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="2" Margin="0,10,0,0">
<CheckBox x:Name="chkAddRemoveEffect" Margin="0,0,10,0" Content="Add Effect" IsEnabled="False" Checked="chkAddRemoveEffect_Checked" Unchecked="chkAddRemoveEffect_Unchecked"/>
<ComboBox Width="120"/>
<ListBox x:Name="EnumedDeviceList2" SelectionChanged="lstEnumedDevices_SelectionChanged" />
<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" Content="StartPreview"/>
<ComboBox x:Name="EffectTypeCombo" Width="120" SelectedIndex="0">
<ComboBoxItem Content="Preview"/>
<ComboBoxItem Content="Grayscale"/>
<ComboBoxItem Content="Canny"/>
<ComboBoxItem Content="Sobel"/>
<ComboBoxItem Content="Histogram"/>
</ComboBox>
<Button Content="Apply" HorizontalAlignment="Stretch" VerticalAlignment="Top" Click="Button_Click"/>
</StackPanel>
<StackPanel x:Name="EffectTypeCombo1" Orientation="Horizontal" Grid.Row="1" Margin="324,5,-324,7"/>
</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="previewCanvas2" Width="320" Height="240" Background="Gray">
<CaptureElement x:Name="previewElement2" Width="320" Height="240" />
</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 x:Name="previewCanvas2" Background="Gray">
<CaptureElement x:Name="previewElement2" />
</Canvas>
</StackPanel>
<StackPanel/>
<StackPanel/>
</StackPanel>
</Grid>
......
......@@ -49,18 +49,12 @@ namespace SDKSample
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 btnTakePhoto_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void lstEnumedDevices_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e);
void EnumerateWebcamsAsync();
......@@ -72,7 +66,6 @@ namespace SDKSample
void ShowExceptionMessage(Platform::Exception^ ex);
void EnableButton(bool enabled, Platform::String ^name);
void SwitchRecordButtonContent();
task<Windows::Storage::StorageFile^> ReencodePhotoAsync(
Windows::Storage::StorageFile ^tempStorageFile,
......@@ -98,7 +91,8 @@ namespace SDKSample
bool m_bRotateVideoOnOrientationChange;
bool m_bReversePreviewRotation;
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 @@
#include "pch.h"
#include "MainPage.xaml.h"
#include "AdvancedCapture.xaml.h"
#include "Common\SuspensionManager.h"
using namespace SDKSample;
using namespace SDKSample::Common;
using namespace SDKSample::MediaCapture;
using namespace Concurrency;
using namespace Platform;
......
......@@ -122,9 +122,7 @@
<Page Include="Common\StandardStyles.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="MainPage.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="MainPage.xaml" />
<Page Include="Sample-Utils\SampleTemplateStyles.xaml">
<SubType>Designer</SubType>
</Page>
......
......@@ -189,7 +189,7 @@ void TransformImage_NV12(
CGrayscale::CGrayscale() :
m_pSample(NULL), m_pInputType(NULL), m_pOutputType(NULL),
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)
{
InitializeCriticalSectionEx(&m_critSec, 3000, 0);
......@@ -219,7 +219,32 @@ STDMETHODIMP CGrayscale::RuntimeClassInitialize()
//-------------------------------------------------------------------
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.
......@@ -1327,41 +1352,10 @@ HRESULT CGrayscale::BeginStreaming()
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;
hr = S_OK;
}
done:
return hr;
}
......@@ -1465,14 +1459,14 @@ HRESULT CGrayscale::OnProcessOutput(IMFMediaBuffer *pIn, IMFMediaBuffer *pOut)
// RGB
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::normalize(hist, hist, BgrFrame.rows/2, 0, cv::NORM_INF);
for(int h=0; h<mHistSizeNum; h++) {
cv::Point mP1, mP2;
mP1.x = mP2.x = offset + (c * (mHistSizeNum + 10) + h) * thikness;
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);
}
}
......
......@@ -44,6 +44,7 @@ DEFINE_GUID(MFT_IMAGE_EFFECT,
enum ProcessingType
{
Preview,
GrayScale,
Canny,
Sobel,
......@@ -232,7 +233,6 @@ private:
// Transformation parameters
ProcessingType m_TransformType;
D2D_RECT_U m_rcDest; // Destination rectangle for the effect.
// Streaming
bool m_bStreamingInitialized;
......
......@@ -22,9 +22,6 @@
</Application>
</Applications>
<Capabilities>
<Capability Name="picturesLibrary" />
<Capability Name="musicLibrary" />
<Capability Name="videosLibrary" />
<DeviceCapability Name="webcam" />
<DeviceCapability Name="microphone" />
</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