归一化的结果是 让人脸图片中的两眼固定在 512*512图片(结果图片)的特定位置。左眼固定在 (196,220),右眼固定在(316,220)。
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.ComponentModel;
using Microsoft.FaceSdk.ImageHelper;
using Microsoft.FaceSdk.Common;
using System.Collections.ObjectModel;
using Microsoft.FaceSdk.Image;
using System.IO;
using System.IO.IsolatedStorage;
using Microsoft.Xna.Framework.Media;
//combine C# and microsoft sdk
/**sourceBitmap: source image.
*desBitmp: result image
* eyeCenter: a array with two points. pointF[0] is left right center point, pointF[1] is left eye center.
*Image<byte> is a class from microsoft sdk library. For other use, you can replace this class with comparable image class, such as CImage, IplImage, e.t..
*/
void regularizeImage(Image<byte> sourceBitmap, Image<Byte> desBitmap, PointF[] eyeCenter)
{double M, x0, y0, alpha, sin, cos;
M = 120.0 / Math.Sqrt((eyeCenter[0].X - eyeCenter[1].X) * (eyeCenter[0].X - eyeCenter[1].X) + (eyeCenter[0].Y - eyeCenter[1].Y) * (eyeCenter[0].Y - eyeCenter[1].Y));
alpha = Math.Atan((eyeCenter[0].Y - eyeCenter[1].Y) / (eyeCenter[0].X - eyeCenter[1].X));
sin = Math.Sin(alpha); cos = Math.Cos(alpha);
x0 = 196 - M * cos * eyeCenter[1].X - M * sin * eyeCenter[1].Y;
y0 = 219 - M * cos * eyeCenter[1].Y + M * sin * eyeCenter[1].X;
for (int i = 0; i < desBitmap.Width; i++)
{
&nbs