C#图片处理 解决左右镜像相反(旋转图片)

        /// <summary>
        /// aforge摄像框控件:捕捉识别绘制人脸框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="image"></param>
        ///                                                  
        private void camerSourcePlayer_NewFrame(object sender, ref Bitmap image)
        {
            //解决左右镜像相反问题
            if (image != null)
            {
                //顺时针旋转90度     RotateFlipType.Rotate90FlipNone
                //逆时针旋转90度     RotateFlipType.Rotate270FlipNone
                //水平翻转           RotateFlipType.Rotate180FlipY
                //垂直翻转           RotateFlipType.Rotate180FlipX
                //RotateFlipType.RotateNoneFlipX 按X轴翻转
                image.RotateFlip(RotateFlipType.RotateNoneFlipX);
            } 
            if (isFaceAlgOK == false)
            { return; }

            MemoryStream ms = new MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] bytes = ms.ToArray();
            ms.Close();           

            //输入算法 检测人脸 为检测出的人脸数    
            int ret = TcFace.face_get_pos_from_image(bytes, bytes.Length, detectFaces);

            //检测出人脸
            if (ret > 0)
            {
                //计算原始人脸框
                int x = detectFaces[0];
                int y = detectFaces[1];
                int width = detectFaces[2] - detectFaces[0];
                int height = detectFaces[3] - detectFaces[1];

                //按比例扩展人脸前端显示范围
                int x_front = x - (int)(width * 0.1);
                int y_front = y - (int)(height * 0.15);
                int width_front = width + (int)(width * 0.2);
                int height_front = height + (int)(height * 0.3);

                //按比例扩展人脸后台比对范围
                int x_back = x - (int)(width * 0.3);
                int y_back = y - (int)(height * 0.8);
                int width_back = width + (int)(width * 0.6);
                int height_back = height + (int)(height * 1.2);

                检测到读卡后 截取人脸比对 开始一轮比对
                if (isStartVerify == true)
                {
                    isStartVerify = false; //在进行一轮的比对中 不在接收新的验证 状态将改为false
                    resultFace = CaptureImage(image, width_back, height_back, x_back, y_back);    
                    currentFrame = (Bitmap)image.Clone();
                    verifyThread = new Thread(FaceVerify);
                    verifyThread.IsBackground = true;
                    verifyThread.Start();
                }

                //画人脸框
                try
                {
                    Graphics g = Graphics.FromImage(image);
                    Rectangle faceRect = new Rectangle(x_front, y_front, width_front, height_front);
                    DrawFaceRect(g, faceRect);
                    g.Dispose();
                }
                catch (Exception ex)
                {
                    //当人脸靠近边框时会卡住,屏蔽该异常
                }

            }

            //直接画人脸框
            try
            {
                Graphics g = Graphics.FromImage(image);
                g.DrawImage(bmpFaceLine, 0, 0, camerWidth, camerHeight);
                g.Dispose();
                g = null;
            }
            catch (Exception ex)
            {
                //当人脸靠近边框时会卡住,屏蔽该异常
            }

        }

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zero-To-One

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值