×
Namespaces

Variants
Actions
(Difference between revisions)

Enabling wallet payment by face recognition

From Nokia Developer Wiki
Jump to: navigation, search
galazzo (Talk | contribs)
m (Galazzo -)
jaaura (Talk | contribs)
m (Jaaura -)
(8 intermediate revisions by one user not shown)
Line 3: Line 3:
 
Although it is still possible to greatly improve the algorithm the results already achieved are very good. Anyway it's important to understand that results are strongly influenced by the background, how the face is rotated or light conditions when compared to the master image. Provided that there is no method completely safe, the proposed solution is intended as an additional method to the normal safety systems not necessarily as a substitute. The choice depends most on the security level you want to achieve regard to the data that you want to protect.}}
 
Although it is still possible to greatly improve the algorithm the results already achieved are very good. Anyway it's important to understand that results are strongly influenced by the background, how the face is rotated or light conditions when compared to the master image. Provided that there is no method completely safe, the proposed solution is intended as an additional method to the normal safety systems not necessarily as a substitute. The choice depends most on the security level you want to achieve regard to the data that you want to protect.}}
  
{{Note|This is a community entry in the [[Windows Phone 8 Wiki Competition 2012Q4]].}}
 
 
{{ArticleMetaData <!-- v1.2 -->
 
{{ArticleMetaData <!-- v1.2 -->
 
|sourcecode= [http://projects.developer.nokia.com/DSP/files/FaceWallet.zip Face Wallet]
 
|sourcecode= [http://projects.developer.nokia.com/DSP/files/FaceWallet.zip Face Wallet]
Line 30: Line 29:
 
* [[http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206987%28v=vs.105%29.aspx Auto-launching apps using file and URI associations for Windows Phone 8]]
 
* [[http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206987%28v=vs.105%29.aspx Auto-launching apps using file and URI associations for Windows Phone 8]]
 
* [[http://msdn.microsoft.com/en-US/library/Microsoft.Phone.Wallet.aspx Microsoft.Phone.Wallet Namespace]]
 
* [[http://msdn.microsoft.com/en-US/library/Microsoft.Phone.Wallet.aspx Microsoft.Phone.Wallet Namespace]]
 +
* [[http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207001%28v=vs.105%29.aspx How to use the add Wallet item task for Windows Phone]]
 +
* [[http://msdn.microsoft.com/en-US/library/windowsphone/develop/microsoft.phone.secureelement.secureelementsession(v=vs.105).aspx SecureElementSession]]
 +
* [http://www.heraldsun.com.au/news/national/paypal-set-to-launch-facial-recognition-for-ins-store-purchasing-via-smartphones/story-fndo471r-1226516195461 PayPal set to launch facial-recognition for ins-store purchasing via smartphones ]
 
}}
 
}}
  
Line 59: Line 61:
 
|}
 
|}
  
{{Warning|To deploy or submit an app that uses {{Icode|ID_CAP_WALLET_SECUREELEMENT}} or {{Icode|ID_CAP_WALLET_PAYMENTINSTRUMENTS}}, you must request special permissions and have that permission applied to your developer account.}}
+
{{Warning|To deploy or submit an app that uses {{Icode|ID_CAP_WALLET_SECUREELEMENT}} or {{Icode|ID_CAP_WALLET_PAYMENTINSTRUMENTS}}, you must request special permissions and have that permission applied to your developer account. As reported by [[http://msdn.microsoft.com/en-US/library/windowsphone/develop/microsoft.phone.secureelement.secureelementsession(v=vs.105).aspx documentation]] contact the [[https://dev.windowsphone.com/en-us/support developer support]]}}
  
 
== Creating the UI ==
 
== Creating the UI ==
Line 80: Line 82:
  
 
=== Remapping URI ===
 
=== Remapping URI ===
n Windows Phone 8 we can use URI associations to automatically launch our app from another app launches with a specific file type or URI scheme. When launched, a deep link URI is used to send the file (a reference to the file) or URI to your app.
+
In Windows Phone 8 we can use URI associations to automatically launch our app from another app launches with a specific file type or URI scheme. When launched, a deep link URI is used to send the file (a reference to the file) or URI to your app.
 
We use URI scheme feature in order to open the {{Icode|Wallet.xaml}} when the app is called from the Wallet, MainPage.xaml else. We need to choose a parameter to intercept,{{Icode|PaymentInstrument}} in our sample, but you can choose your own name. So we need also to create a class that inherits UriMapperBase. The object created from this class will be delegated to manage page switching.
 
We use URI scheme feature in order to open the {{Icode|Wallet.xaml}} when the app is called from the Wallet, MainPage.xaml else. We need to choose a parameter to intercept,{{Icode|PaymentInstrument}} in our sample, but you can choose your own name. So we need also to create a class that inherits UriMapperBase. The object created from this class will be delegated to manage page switching.
  
Line 239: Line 241:
  
 
== Wallet:PaymentInstruments ==
 
== Wallet:PaymentInstruments ==
 +
The following code is needed to register our application into the wallet in order to be able to call it from the Wallet. First we need to create a [http://msdn.microsoft.com/en-US/library/microsoft.phone.wallet.paymentinstrument.aspx {{Icode|PaymentInstruments}}] object whose methods are intuitive enough.
 +
Created the Item we use [http://msdn.microsoft.com/en-US/library/windowsphone/develop/microsoft.phone.tasks.addwalletitemtask%28v=vs.105%29.aspx AddWalletItemTask] allowing our application to launch the Wallet application.<br />
 +
The provided Wallet item is displayed to the user and the user can choose to add the item to his or her Wallet.
  
 
Include the following namespaces:
 
Include the following namespaces:
Line 249: Line 254:
 
</code>
 
</code>
  
 
The following code is needed to register our application into the wallet in order to be able to call it from the Wallet.
 
 
<code csharp>
 
<code csharp>
 
private void Wallet_CreateNewPaymentInstrument()
 
private void Wallet_CreateNewPaymentInstrument()
Line 257: Line 260:
 
             if ((Microsoft.Phone.Wallet.Wallet.FindItem("facedetectionwallet") as PaymentInstrument) == null)
 
             if ((Microsoft.Phone.Wallet.Wallet.FindItem("facedetectionwallet") as PaymentInstrument) == null)
 
             {
 
             {
 +
              // Create the PaymentInstruments object
 
                 var item = new PaymentInstrument()
 
                 var item = new PaymentInstrument()
 
                 {                 
 
                 {                 
Line 278: Line 282:
 
                     NavigationUri = new Uri("/mainpage.xaml?wallet=PaymentInstrument", UriKind.Relative)
 
                     NavigationUri = new Uri("/mainpage.xaml?wallet=PaymentInstrument", UriKind.Relative)
 
                 };
 
                 };
 +
                // Assign an ID we use to avoid duplication of our App into the Wallet
 
                 item.UpdateId("facedetectionwallet");
 
                 item.UpdateId("facedetectionwallet");
 +
 +
                // Create the task able to register into the Wallet the Item created above
 
                 AddWalletItemTask task = new AddWalletItemTask()
 
                 AddWalletItemTask task = new AddWalletItemTask()
 
                 {
 
                 {
 
                         Item = item
 
                         Item = item
 
                 };
 
                 };
 +
               
 +
                // The code to execute when the registration task is completed
 
                 task.Completed += (s, args) => MessageBox.Show(args.TaskResult.ToString());
 
                 task.Completed += (s, args) => MessageBox.Show(args.TaskResult.ToString());
 +
               
 
                 task.Show();
 
                 task.Show();
  
Line 299: Line 309:
 
  }
 
  }
 
</code>
 
</code>
 
  
 
== Wallet.xaml ==
 
== Wallet.xaml ==
This page is opened when the application is called from Wallet. Most of the code is in common with '''MainPage.xaml''' except {{Icode|cam_CaptureImageAvailable}} code and the lack of {{Icode|Wallet_CreateNewPaymentInstrument}} that is needed to register application into the wallet but unnecessary here.
+
This page is opened when the application is called from Wallet. Most of the code is in common with '''MainPage.xaml''' except {{Icode|cam_CaptureImageAvailable}} code and the lack of {{Icode|Wallet_CreateNewPaymentInstrument}} that is needed to register application into the wallet but unnecessary here.<br />
 +
The sample code stops after the recognition process and it's limited to display just a {{Icode|MessageBox}}. This is because from this point onwards you put your own implementation based on your needs. In the same way when recognition fails you can choose to simply  stop the process or start another action. An idea could be for example to send an alert email  after three attemps attaching the photo of the face is trying to access, assuming is an unauthorized person that wants to access to your data.
  
 
<code csharp>
 
<code csharp>
Line 396: Line 406:
 
                 if (mse < 55)
 
                 if (mse < 55)
 
                 {
 
                 {
 +
                  // There was a recognition. You can proceed with your payment implementation.
 
                     MessageBox.Show("You have been recognized!\nMSE:" + mse + "\nWe can proceed with payment");
 
                     MessageBox.Show("You have been recognized!\nMSE:" + mse + "\nWe can proceed with payment");
 
                 }
 
                 }
 
                 else
 
                 else
 
                 {
 
                 {
 +
                    // There wasn't a recognition. You can choose to simply stop the payment or start another process based on your needs
 
                     MessageBox.Show("You have not been recognized!\nMSE:"+mse+"\nWe can't proceed with payment.\nIf you are the correct people, please retry to shoot a new photo with different environment conditions.");
 
                     MessageBox.Show("You have not been recognized!\nMSE:"+mse+"\nWe can't proceed with payment.\nIf you are the correct people, please retry to shoot a new photo with different environment conditions.");
 
                 }
 
                 }
Line 418: Line 430:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! MainPage.xaml<br />Acquiring the sample image !! MainPage.xaml<br/>Updated the face into file !! Wallet.xaml<br/>Recognition process
+
! MainPage.xaml<br />Acquiring the sample image !! MainPage.xaml<br/>Updated the face into file !! How Application looks into Wallet !! Wallet.xaml<br/>Recognition process
 
|-
 
|-
| [[File:FaceWallet-01.png|310x420px]] || [[File:FaceWallet-02.png|310x420px]] || [[File:FaceWallet-03.png|310x420px]]
+
| [[File:FaceWallet-01.png|310x420px]] || [[File:FaceWallet-02.png|310x420px]] || [[File:Face-wallet-08.png|310x420px]] ||  [[File:FaceWallet-03.png|310x420px]]
 
|}
 
|}
  
 
{{Warning|Please be aware that recognition process is strongly influenced by the background, how the face is rotated or light conditions. When {{Icode|Skin Detection}} will be available we can count on better performance}}
 
{{Warning|Please be aware that recognition process is strongly influenced by the background, how the face is rotated or light conditions. When {{Icode|Skin Detection}} will be available we can count on better performance}}
 +
 +
== Interesting links ==
 +
* [http://www.heraldsun.com.au/news/national/paypal-set-to-launch-facial-recognition-for-ins-store-purchasing-via-smartphones/story-fndo471r-1226516195461 PayPal set to launch facial-recognition for ins-store purchasing via smartphones]

Revision as of 17:08, 9 January 2013

This article shows how you can use face recognition to authorize a wallet payment. This is the second of a series of articles based on the DSP project and focused on face recognition. Although it is still possible to greatly improve the algorithm the results already achieved are very good. Anyway it's important to understand that results are strongly influenced by the background, how the face is rotated or light conditions when compared to the master image. Provided that there is no method completely safe, the proposed solution is intended as an additional method to the normal safety systems not necessarily as a substitute. The choice depends most on the security level you want to achieve regard to the data that you want to protect.

WP Metro Icon Multimedia.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
Article Metadata
Code Example
Source file: Face Wallet
Tested with
Devices(s): Nokia Lumia
Compatibility
Platform(s): Windows Phone 8
Windows Phone 8
Article
Keywords: Wallet, Payment, Face Recognition
Created: galazzo (11 Dec 2012)
Last edited: jaaura (09 Jan 2013)

Contents

Introduction

A new interesting feature of Windows Phone 8 is certainly the Wallet and Deals APIs which allows users to do the following:

  • Collect coupons, credit cards, memberships, loyalty cards, and more in one place.
  • Manage the payment instruments that they use in the app and music store.
  • Link items in the Wallet to apps on their phone.
  • Make contact-less transactions, using Near-Field Communication (NFC), in some markets.

The Wallet API offers full programmatic access to the Wallet. It allows you to create, read, update, and delete Wallet items to implement Deals or Payments.

Deals are useful to manage coupons, loyalty cards, Payment instrument manage a balance on an account maintained by your back-end.

The sample application we will create first acquires the face sample to compare and store it into a file. Through RootFrame.UriMapper rewriting when the app is called from Wallet before to process payment is required to compare your face with the one saved into the system. If there is a match payment process can continue else is stopped.

Required capabilities

In order to use Wallet API in Windows Phone 8 you need to specify in the WMAppManifest.xml the following required capabilities otherwise your app might not work correctly or it might fail the process of submission to the Store.

Capability API that requires this capability
ID_CAP_WALLET Required for all Wallet API, which is anything in Microsoft.Phone.Wallet or Microsoft.Phone.SecureElement.
ID_CAP_WALLET_PAYMENTINSTRUMENTS Required for PaymentInstrument and OnlinePaymentInstrument.
ID_CAP_WALLET_SECUREELEMENT Required for SecureElementSession, SecureElementChannel and SecureElementReader.

Warning.pngWarning: To deploy or submit an app that uses ID_CAP_WALLET_SECUREELEMENT or ID_CAP_WALLET_PAYMENTINSTRUMENTS, you must request special permissions and have that permission applied to your developer account. As reported by [documentation] contact the [developer support]

Creating the UI

The following code create the object to display the camera video flow and the snap button to save the captured image, compute or save it. Besides MainPage.xml the same code is needed for the secondary screen called Wallet.xaml we need to create to be opened when the application is called from the wallet.

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Grid.Background>
<VideoBrush x:Name="viewfinderBrush">
<VideoBrush.RelativeTransform>
<CompositeTransform CenterY="0.5" CenterX="0.5" Rotation="-90"/>
</VideoBrush.RelativeTransform>
</VideoBrush>
</Grid.Background>
</Grid>
<Button Content="Snap Picture" Click="SaveImage" Margin="0,624,0,0" Grid.Row="1" />
<!--Application progress bar.-->
<ProgressBar Height="10" Name="progressBar" Width="460" Visibility="Collapsed" Margin="12,365,8,286" Grid.Row="1" IsIndeterminate="True" />

Remapping URI

In Windows Phone 8 we can use URI associations to automatically launch our app from another app launches with a specific file type or URI scheme. When launched, a deep link URI is used to send the file (a reference to the file) or URI to your app. We use URI scheme feature in order to open the Wallet.xaml when the app is called from the Wallet, MainPage.xaml else. We need to choose a parameter to intercept,PaymentInstrument in our sample, but you can choose your own name. So we need also to create a class that inherits UriMapperBase. The object created from this class will be delegated to manage page switching.

Into App.xaml.cs add the following code:

class MyAppUriMapper : UriMapperBase
{
public override Uri MapUri(Uri uri)
{
string tempUri = uri.ToString();
// Check if the URI contains the parameter we choosed.
// If yes return a new URI corresponding to the .xaml we want to open when the App is called from another App
// else the uri is unchanged
if (tempUri.Contains("PaymentInstrument"))
{
return new Uri("/Wallet.xaml", UriKind.Relative);
}
else
{
return uri;
}
}
}
 
public partial class App : Application
{
..........
 
public App()
{
..........
// Override the application UriMapper
RootFrame.UriMapper = new MyAppUriMapper();
}
}

Camera

In common with Wallet.xaml.

using Microsoft.Devices; // Needed for PhotoCamera
using Microsoft.Xna.Framework.Media;
 
using System.Windows.Media.Imaging;
using Microsoft.Phone; // Needed for PictureDecoder
using System.IO;

public partial class MainPage : PhoneApplicationPage
{
PhotoCamera cam;
MediaLibrary library = new MediaLibrary();
 
public MainPage()
{
InitializeComponent();
this.Loaded += Page_Loaded;
}
 
void Page_Loaded(object sender, RoutedEventArgs e)
{
if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing))
{
cam = new Microsoft.Devices.PhotoCamera(CameraType.FrontFacing);
cam.CaptureImageAvailable += cam_CaptureImageAvailable;
viewfinderBrush.SetSource(cam);
} else
if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
{
cam = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
 
cam.CaptureImageAvailable += cam_CaptureImageAvailable;
viewfinderBrush.SetSource(cam);
}
}
 
private void SaveImage(object sender, RoutedEventArgs e)
{
cam.CaptureImage();
}
}

Face Recognition Support

For a deeper understanding of face recognition please refer to Face Recognition using 2D Fast Fourier Transform.

  • Download DSP.cs and add it into your project. DSP.cs provides a namespace called DSP and a class FourierTransform containing a set of functions to compute the FFT.

Include the namespace DSP:

using DSP;

Add the following lines to MainPage.xaml, in common with Wallet.xaml.

public partial class MainPage : PhoneApplicationPage
{
PhotoCamera cam;
MediaLibrary library = new MediaLibrary();
 
public static WriteableBitmap CapturedImage;
private static int W = 256;
private static int H = 256;
private static int matchSamples = 25;
 
private double[] compareSignal = new Double[matchSamples];
 
private Double[] pRealIn = new Double[W * H];
private Double[] pImagIn = new Double[W * H];
private Double[] pRealOut = new Double[W * H];
private Double[] pImagOut = new Double[W * H];
private Double[] pRealOut2 = new Double[W * H];
private Double[] pImagOut2 = new Double[W * H];
 
private const string faceFileName = "face.csv";
.......

 void cam_CaptureImageAvailable(object sender, ContentReadyEventArgs e)
{
//Take JPEG stream and decode into a WriteableBitmap object
Deployment.Current.Dispatcher.BeginInvoke(delegate()
{
MainPage.CapturedImage = PictureDecoder.DecodeJpeg(e.ImageStream, W, H);
 
//Collapse visibility on the progress bar once writeable bitmap is visible.
progressBar.Visibility = Visibility.Collapsed;
 
int[] pixel = MainPage.CapturedImage.Pixels;
 
int color = 0;
for (int y = 0; y < MainPage.CapturedImage.PixelHeight; y++)
{
for (int x = 0; x < MainPage.CapturedImage.PixelWidth; x++)
{
color = MainPage.CapturedImage.Pixels[x + (y * MainPage.CapturedImage.PixelWidth)];
pRealIn[x + (y * MainPage.CapturedImage.PixelWidth)] = DSP.Utilities.ColorToGray(color) & 0xFF;
 
}
}
 
Double[] signal;
 
System.Diagnostics.Debug.WriteLine("Using Fourier");
DSP.FourierTransform.Compute2D((uint)W, (uint)H, ref pRealIn, null, ref pRealOut, ref pImagOut, false);
signal = DSP.Utilities.triangularExtraction(ref pRealOut, (uint)W, (uint)H, (uint)matchSamples, 0);
 
DSP.Utilities.saveSignal(ref signal, faceFileName);
 
Wallet_CreateNewPaymentInstrument();
 
});
 
}

Wallet:PaymentInstruments

The following code is needed to register our application into the wallet in order to be able to call it from the Wallet. First we need to create a PaymentInstruments object whose methods are intuitive enough. Created the Item we use AddWalletItemTask allowing our application to launch the Wallet application.
The provided Wallet item is displayed to the user and the user can choose to add the item to his or her Wallet.

Include the following namespaces:

using System.Windows.Media.Imaging;
using Windows.System;
using Microsoft.Phone.Tasks;
using Microsoft.Phone.Wallet;
using System.Windows.Media;
private void Wallet_CreateNewPaymentInstrument()
{
// Check if the object is already created
if ((Microsoft.Phone.Wallet.Wallet.FindItem("facedetectionwallet") as PaymentInstrument) == null)
{
// Create the PaymentInstruments object
var item = new PaymentInstrument()
{
IssuerName = "sebastiano.galazzo@gmail.com",
CustomerName = "Sebastiano Galazzo",
ExpirationDate = DateTime.Now.AddDays(1),
PaymentInstrumentKinds = PaymentInstrumentKinds.Debit,
DisplayName = "Face Recognition Wallet",
Logo99x99 = GetBitmapSource("99x99.png"),
Logo336x336 = GetBitmapSource("336x336.png"),
Logo159x159 = GetBitmapSource("159x159.png"),
DisplayAvailableBalance = "50€?",
DisplayBalance = "100€?",
DisplayCreditLimit = "1000€",
DisplayAvailableCredit = "1000€",
BackgroundColor = Color.FromArgb(255, 70, 150, 250),
Nickname = "Bino",
Message = "Face recognition based wallet.",
MemberSince = DateTime.Now.AddYears(-1),
AccountNumber = "12345679",
NavigationUri = new Uri("/mainpage.xaml?wallet=PaymentInstrument", UriKind.Relative)
};
// Assign an ID we use to avoid duplication of our App into the Wallet
item.UpdateId("facedetectionwallet");
 
// Create the task able to register into the Wallet the Item created above
AddWalletItemTask task = new AddWalletItemTask()
{
Item = item
};
 
// The code to execute when the registration task is completed
task.Completed += (s, args) => MessageBox.Show(args.TaskResult.ToString());
 
task.Show();
 
} else {
MessageBox.Show("Face updated!");
}
Launcher.LaunchUriAsync(new Uri("wallet://", UriKind.RelativeOrAbsolute));
}
 
private BitmapSource GetBitmapSource(string url)
{
var bmp = new BitmapImage();
bmp.SetSource(Application.GetResourceStream(new Uri(url, UriKind.Relative)).Stream);
return bmp;
}

Wallet.xaml

This page is opened when the application is called from Wallet. Most of the code is in common with MainPage.xaml except cam_CaptureImageAvailable code and the lack of Wallet_CreateNewPaymentInstrument that is needed to register application into the wallet but unnecessary here.
The sample code stops after the recognition process and it's limited to display just a MessageBox. This is because from this point onwards you put your own implementation based on your needs. In the same way when recognition fails you can choose to simply stop the process or start another action. An idea could be for example to send an alert email after three attemps attaching the photo of the face is trying to access, assuming is an unauthorized person that wants to access to your data.

using DSP;
 
namespace FaceWallet
{
public partial class Wallet : PhoneApplicationPage
{
PhotoCamera cam;
MediaLibrary library = new MediaLibrary();
 
public static WriteableBitmap CapturedImage;
private static int W = 256;
private static int H = 256;
private static int matchSamples = 25;
 
private double[] compareSignal = new Double[matchSamples];
 
private Double[] pRealIn = new Double[W * H];
private Double[] pImagIn = new Double[W * H];
private Double[] pRealOut = new Double[W * H];
private Double[] pImagOut = new Double[W * H];
private Double[] pRealOut2 = new Double[W * H];
private Double[] pImagOut2 = new Double[W * H];
 
private const string faceFileName = "face.csv";
 
public Wallet()
{
InitializeComponent();
this.Loaded += Page_Loaded;
}
 
void Page_Loaded(object sender, RoutedEventArgs e)
{
if ((compareSignal = DSP.Utilities.loadSignal(faceFileName)) == null) { MessageBox.Show("Face to recognize has not been sampled.\nPlease procedd to sampling before continue."); return; }
 
if (PhotoCamera.IsCameraTypeSupported(CameraType.FrontFacing))
{
cam = new Microsoft.Devices.PhotoCamera(CameraType.FrontFacing);
cam.CaptureImageAvailable += cam_CaptureImageAvailable;
viewfinderBrush.SetSource(cam);
}
else
if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
{
cam = new Microsoft.Devices.PhotoCamera(CameraType.Primary);
 
cam.CaptureImageAvailable += cam_CaptureImageAvailable;
viewfinderBrush.SetSource(cam);
}
}
 
void cam_CaptureImageAvailable(object sender, ContentReadyEventArgs e)
{
Deployment.Current.Dispatcher.BeginInvoke(delegate()
{
//Take JPEG stream and decode into a WriteableBitmap object
MainPage.CapturedImage = PictureDecoder.DecodeJpeg(e.ImageStream, W, H);
 
//Collapse visibility on the progress bar once writeable bitmap is visible.
progressBar.Visibility = Visibility.Collapsed;
 
int[] pixel = MainPage.CapturedImage.Pixels;
 
int color = 0;
for (int y = 0; y < MainPage.CapturedImage.PixelHeight; y++)
{
for (int x = 0; x < MainPage.CapturedImage.PixelWidth; x++)
{
color = MainPage.CapturedImage.Pixels[x + (y * MainPage.CapturedImage.PixelWidth)];
pRealIn[x + (y * MainPage.CapturedImage.PixelWidth)] = DSP.Utilities.ColorToGray(color) & 0xFF;
}
}
 
Double[] match;
double mse = 0;
 
System.Diagnostics.Debug.WriteLine("Using Fourier");
DSP.FourierTransform.Compute2D((uint)W, (uint)H, ref pRealIn, null, ref pRealOut, ref pImagOut, false);
match = DSP.Utilities.triangularExtraction(ref pRealOut, (uint)W, (uint)H, (uint)matchSamples, 0);
 
mse = DSP.Utilities.MSE(ref compareSignal, ref match, (int)matchSamples);
 
// Normalize Fourier result
mse /= 1000000000;
 
mse = Math.Round(mse);
 
System.Diagnostics.Debug.WriteLine("MSE:" + mse);
 
if (mse < 55)
{
// There was a recognition. You can proceed with your payment implementation.
MessageBox.Show("You have been recognized!\nMSE:" + mse + "\nWe can proceed with payment");
}
else
{
// There wasn't a recognition. You can choose to simply stop the payment or start another process based on your needs
MessageBox.Show("You have not been recognized!\nMSE:"+mse+"\nWe can't proceed with payment.\nIf you are the correct people, please retry to shoot a new photo with different environment conditions.");
}
 
});
}
 
private void SaveImage(object sender, RoutedEventArgs e)
{
cam.CaptureImage();
}
 
}
}

Screenshots

MainPage.xaml
Acquiring the sample image
MainPage.xaml
Updated the face into file
How Application looks into Wallet Wallet.xaml
Recognition process
FaceWallet-01.png FaceWallet-02.png Face-wallet-08.png FaceWallet-03.png

Warning.pngWarning: Please be aware that recognition process is strongly influenced by the background, how the face is rotated or light conditions. When Skin Detection will be available we can count on better performance

Interesting links

299 page views in the last 30 days.