Updated sample to showcase highgui WinRT usage
Signed-off-by: Maxim Kostin <v-maxkos@microsoft.com>
This commit is contained in:
@@ -1,16 +1,34 @@
|
||||
<Page
|
||||
x:Class="FaceDetection.MainPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:FaceDetection"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
<Page x:Class="FaceDetection.MainPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="using:FaceDetection"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<Button x:Name="InitBtn" Content="Initialize" HorizontalAlignment="Left" Height="67" Margin="69,81,0,0" VerticalAlignment="Top" Width="218" Click="InitBtn_Click"/>
|
||||
<Button x:Name="detectBtn" Content="Detect Faces" HorizontalAlignment="Left" Height="67" Margin="69,168,0,0" VerticalAlignment="Top" Width="218" Click="detectBtn_Click"/>
|
||||
<Image x:Name="img1" HorizontalAlignment="Left" Height="446" Margin="354,84,0,0" VerticalAlignment="Top" Width="883"/>
|
||||
<Button x:Name="InitBtn"
|
||||
Width="218"
|
||||
Height="67"
|
||||
Margin="69,81,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Click="InitBtn_Click"
|
||||
Content="Initialize" />
|
||||
<Button x:Name="detectBtn"
|
||||
Width="218"
|
||||
Height="67"
|
||||
Margin="69,168,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Click="detectBtn_Click"
|
||||
Content="Detect Faces" />
|
||||
<StackPanel x:Name="cvContainer"
|
||||
Width="883"
|
||||
Height="446"
|
||||
Margin="354,84,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top" />
|
||||
|
||||
</Grid>
|
||||
</Page>
|
||||
|
@@ -10,6 +10,8 @@
|
||||
#include <opencv2\imgcodecs\imgcodecs.hpp>
|
||||
#include <opencv2\core\core.hpp>
|
||||
#include <opencv2\imgproc\imgproc.hpp>
|
||||
#include <opencv2\highgui.hpp>
|
||||
#include <opencv2\highgui\highgui_winrt.hpp>
|
||||
|
||||
#include <Robuffer.h>
|
||||
|
||||
@@ -33,6 +35,7 @@ using namespace Microsoft::WRL;
|
||||
|
||||
// Name of the resource classifier used to detect human faces (frontal)
|
||||
cv::String face_cascade_name = "Assets/haarcascade_frontalface_alt.xml";
|
||||
cv::String window_name = "Faces";
|
||||
|
||||
MainPage::MainPage()
|
||||
{
|
||||
@@ -45,7 +48,8 @@ void FaceDetection::MainPage::InitBtn_Click(Platform::Object^ sender, Windows::U
|
||||
cv::Mat image = cv::imread("Assets/group1.jpg");
|
||||
groupFaces = cv::Mat(image.rows, image.cols, CV_8UC4);
|
||||
cv::cvtColor(image, groupFaces, CV_BGR2BGRA);
|
||||
UpdateImage(groupFaces);
|
||||
cv::winrt_initContainer(cvContainer);
|
||||
cv::imshow(window_name, groupFaces);
|
||||
|
||||
if (!face_cascade.load(face_cascade_name)) {
|
||||
Windows::UI::Popups::MessageDialog("Couldn't load face detector \n").ShowAsync();
|
||||
@@ -70,29 +74,8 @@ void FaceDetection::MainPage::detectBtn_Click(Platform::Object^ sender, Windows:
|
||||
cv::rectangle(groupFaces, face, cv::Scalar(0, 255, 255), 5);
|
||||
}
|
||||
|
||||
UpdateImage(groupFaces);
|
||||
cv::imshow(window_name, groupFaces);
|
||||
} else {
|
||||
Windows::UI::Popups::MessageDialog("Initialize image before processing \n").ShowAsync();
|
||||
}
|
||||
}
|
||||
|
||||
void FaceDetection::MainPage::UpdateImage(const cv::Mat& image) {
|
||||
// Create the WriteableBitmap
|
||||
WriteableBitmap^ bitmap = ref new WriteableBitmap(image.cols, image.rows);
|
||||
|
||||
// Get access to the pixels
|
||||
IBuffer^ buffer = bitmap->PixelBuffer;
|
||||
unsigned char* dstPixels;
|
||||
|
||||
// Obtain IBufferByteAccess
|
||||
ComPtr<IBufferByteAccess> pBufferByteAccess;
|
||||
ComPtr<IInspectable> pBuffer((IInspectable*)buffer);
|
||||
pBuffer.As(&pBufferByteAccess);
|
||||
|
||||
// Get pointer to pixel bytes
|
||||
pBufferByteAccess->Buffer(&dstPixels);
|
||||
memcpy(dstPixels, image.data, image.step.buf[1] * image.cols*image.rows);
|
||||
|
||||
// Set the bitmap to the Image element
|
||||
img1->Source = bitmap;
|
||||
}
|
@@ -2,13 +2,14 @@
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ImportGroup Label="PropertySheets" />
|
||||
<PropertyGroup Label="UserMacros">
|
||||
<OpenCV_Bin>$(OPENCV_WINRT_INSTALL_DIR)\WS\8.1\$(PlatformTarget)\$(PlatformTarget)\vc12\bin\</OpenCV_Bin>
|
||||
<OpenCV_Lib>$(OPENCV_WINRT_INSTALL_DIR)\WS\8.1\$(PlatformTarget)\$(PlatformTarget)\vc12\lib\</OpenCV_Lib>
|
||||
<OpenCV_Include>$(OPENCV_WINRT_INSTALL_DIR)\WS\8.1\$(PlatformTarget)\include\</OpenCV_Include>
|
||||
<Runtime Condition="'$(ApplicationType)'=='Windows Phone'">WP</Runtime>
|
||||
<Runtime Condition="'$(ApplicationType)'=='Windows Store'">WS</Runtime>
|
||||
<OpenCV_Bin>$(OPENCV_WINRT_INSTALL_DIR)\$(Runtime)\8.1\$(PlatformTarget)\$(PlatformTarget)\vc12\bin\</OpenCV_Bin>
|
||||
<OpenCV_Lib>$(OPENCV_WINRT_INSTALL_DIR)\$(Runtime)\8.1\$(PlatformTarget)\$(PlatformTarget)\vc12\lib\</OpenCV_Lib>
|
||||
<OpenCV_Include>$(OPENCV_WINRT_INSTALL_DIR)\$(Runtime)\8.1\$(PlatformTarget)\include\</OpenCV_Include>
|
||||
<!--debug suffix for OpenCV dlls and libs -->
|
||||
<DebugSuffix Condition="'$(Configuration)'=='Debug'">d</DebugSuffix>
|
||||
<DebugSuffix Condition="'$(Configuration)'!='Debug'">
|
||||
</DebugSuffix>
|
||||
<DebugSuffix Condition="'$(Configuration)'!='Debug'"></DebugSuffix>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<!--Add required OpenCV dlls here-->
|
||||
@@ -33,14 +34,20 @@
|
||||
<None Include="$(OpenCV_Bin)opencv_objdetect300$(DebugSuffix).dll">
|
||||
<DeploymentContent>true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="$(OpenCV_Bin)opencv_videoio300$(DebugSuffix).dll">
|
||||
<DeploymentContent>true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="$(OpenCV_Bin)opencv_highgui300$(DebugSuffix).dll">
|
||||
<DeploymentContent>true</DeploymentContent>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(OpenCV_Include);$(ProjectDir);$(GeneratedFilesDir);$(IntDir);%(AdditionalIncludeDirectories);</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(OpenCV_Include);%(AdditionalIncludeDirectories);</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<!--Add required OpenCV libs here-->
|
||||
<AdditionalDependencies>opencv_core300$(DebugSuffix).lib;opencv_imgcodecs300$(DebugSuffix).lib;opencv_imgproc300$(DebugSuffix).lib;opencv_features2d300$(DebugSuffix).lib;opencv_flann300$(DebugSuffix).lib;opencv_ml300$(DebugSuffix).lib;opencv_imgcodecs300$(DebugSuffix).lib;opencv_objdetect300$(DebugSuffix).lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>opencv_core300$(DebugSuffix).lib;opencv_imgproc300$(DebugSuffix).lib;opencv_imgcodecs300$(DebugSuffix).lib;opencv_flann300$(DebugSuffix).lib;opencv_videoio300$(DebugSuffix).lib;opencv_features2d300$(DebugSuffix).lib;opencv_objdetect300$(DebugSuffix).lib;opencv_ml300$(DebugSuffix).lib;opencv_highgui300$(DebugSuffix).lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(OpenCV_Lib);%(AdditionalLibraryDirectories);</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
|
Reference in New Issue
Block a user