windows phone 实现mjpeg流视频的人脸识别

先上图片,看看效果

首先是wp有自带的mjpeg解码功能
能输出WriteableBitmap格式,方便接下来进行图像分析
速度还行,最大也只是100多MS的延迟
接收图像方法

public void recVideo()
        {
            string sourceURL = "图片流地址";
            while (true)
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(sourceURL));
                req.BeginGetResponse(new AsyncCallback(resResult), req);
                //Thread.Sleep(10);
            }
        }



异步调用方法

      private void resResult(IAsyncResult ir)
        {
            try
            {
                HttpWebRequest req = ir.AsyncState as HttpWebRequest;
                WebResponse resp = req.EndGetResponse(ir);
                Stream stream = resp.GetResponseStream();
                Dispatcher.BeginInvoke(() =>
                {
                    WriteableBitmap myBitmap = PictureDecoder.DecodeJpeg(stream);    这里就是自带的解码方法,一句话就行了,如果只要实现视频输出,下面图像识别就可以删掉了
                    image1.Source = myBitmap;
                    #region 图像识别
                    var w = myBitmap.PixelWidth;
                    var h = myBitmap.PixelHeight;
                    if (_pixelDataGray == null || _pixelDataGray.Length != h * w)
                    {
//定义了几个数组
                        _pixelDataGray = new byte[w / _downsampleFactor * h / _downsampleFactor];
                        _pixelDataDownsampled =
                            new byte[w / _downsampleFactor * h / _downsampleFactor];
                        _pixelDataGrayInt = new int[w / _downsampleFactor * h / _downsampleFactor];
                        _wb = new WriteableBitmap(w / _downsampleFactor, w / _downsampleFactor);
                    }
//另外写了几个类。Utils 和 FaceDetection,其中FaceDetection的检测算法是跟opencv学的
                    Utils.DownSample(myBitmap.Pixels, w, h, ref _pixelDataGrayInt, _downsampleFactor);
                    Utils.ARGBToGreyScale(_pixelDataGrayInt, ref _pixelDataGray);
                    //_pixelDataGray = e.FrameBuffer;
                    Utils.HistogramEqualization(ref _pixelDataGray);
                    Utils.GrayToARGB(_pixelDataGray, ref _pixelDataGrayInt);
                    List<FaceDetection.Rectangle> faces =
                        _detector.getFaces(
                        _pixelDataGrayInt,
                        w / _downsampleFactor,
                        h / _downsampleFactor,
                        2f, 1.25f, 0.1f, 1, false, true);
                    _pixelDataGrayInt.CopyTo(_wb.Pixels, 0);
                    _wb.Invalidate();
//image控件上覆盖了个 canvas控件,用来画圆圈
                    cnvsFaceRegions.Children.Clear();
                    foreach (var r in faces)
                    {
                        Ellipse el = new Ellipse();
                        TranslateTransform loc = new TranslateTransform();
                        loc.X = r.X * _downsampleFactor / (double)w * cnvsFaceRegions.Width;
                        loc.Y = r.Y * _downsampleFactor / (double)w * cnvsFaceRegions.Height;
                        el.RenderTransform = loc;
                        el.Width = r.Width * _downsampleFactor *2;
                        el.Height = r.Height * _downsampleFactor *2;
                        el.Stroke = new SolidColorBrush(Colors.Red);
                        cnvsFaceRegions.Children.Add(el);
                    }
                    #endregion
                });
            }
            catch (Exception ex)
            {
                Dispatcher.BeginInvoke(() => sysInfo.Text = ex.Message);
            }
        }


 


相关类:
到我的资源下载

http://download.csdn.net/detail/cooska/4895104

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值