C#实现Image<byte>类人脸图片归一化 (图像处理)

使用C#和Microsoft SDK,将人脸图片进行归一化处理,确保左眼位于(196, 220),右眼位于(316, 220)。通过Image<byte>类实现图像操作。" 106296111,8296253,Pytorch实现自编码器:深度学习笔记,"['深度学习', 'Pytorch', '神经网络', '自编码器实现']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

归一化的结果是 让人脸图片中的两眼固定在 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值