C# OpenCvSharp DNN Gaze Estimation

目录

介绍

效果

模型信息

项目

代码

frmMain.cs

GazeEstimation.cs

下载


C# OpenCvSharp DNN Gaze Estimation

介绍

训练源码地址:https://github.com/deepinsight/insightface/tree/master/reconstruction/gaze

效果

模型信息

Inputs
-------------------------
name:input
tensor:Float[1, 3, 160, 160]
---------------------------------------------------------------

Outputs
-------------------------
name:output
tensor:Float[1, 962, 3]
---------------------------------------------------------------

项目

代码

frmMain.cs

using OpenCvSharp;
using OpenCvSharp.Dnn;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace OpenCvSharp_Yolov8_Demo
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";
        string startupPath;
        Mat image;
        Mat result_image;

        YOLOv8_face face_detector = new YOLOv8_face("model/yolov8n-face.onnx", 0.45f, 0.5f);
        GazeEstimation gaze_predictor=new GazeEstimation("model/generalizing_gaze_estimation_with_weak_supervision_from_synthetic_views_1x3x160x160.onnx");

        private void Form1_Load(object sender, EventArgs e)
        {

            image_path = "img_test/1.jpg";
            pictureBox1.Image = new Bitmap(image_path);
            image = new Mat(image_path);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;
            pictureBox1.Image = null;
            image_path = ofd.FileName;
            pictureBox1.Image = new Bitmap(image_path);
            textBox1.Text = "";
            pictureBox2.Image = null;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }
            textBox1.Text = "";
            pictureBox2.Image = null;
            button2.Enabled = false;
            Application.DoEvents();

            image = new Mat(image_path);
            List<Face> ltFace = face_detector.Detect(new Mat(image_path));

            if (ltFace.Count > 0)
            {
                result_image = image.Clone();
                //face_detector.DrawPred(ltFace, result_image);
                String info = "";
                foreach (Face item in ltFace)
                {
                    gaze_predictor.Detect(image, item);
                    result_image = gaze_predictor.DrawOn(result_image, item,out info);
                }
                pictureBox2.Image = new Bitmap(result_image.ToMemoryStream());
                textBox1.Text = info;
            }
            else
            {
                textBox1.Text = "无信息";
            }

            button2.Enabled = true;
        }

    }
}
 

using OpenCvSharp;
using OpenCvSharp.Dnn;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;namespace OpenCvSharp_Yolov8_Demo
{public partial class frmMain : Form{public frmMain(){InitializeComponent();}string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";string image_path = "";string startupPath;Mat image;Mat result_image;YOLOv8_face face_detector = new YOLOv8_face("model/yolov8n-face.onnx", 0.45f, 0.5f);GazeEstimation gaze_predictor=new GazeEstimation("model/generalizing_gaze_estimation_with_weak_supervision_from_synthetic_views_1x3x160x160.onnx");private void Form1_Load(object sender, EventArgs e){image_path = "img_test/1.jpg";pictureBox1.Image = new Bitmap(image_path);image = new Mat(image_path);}private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = fileFilter;if (ofd.ShowDialog() != DialogResult.OK) return;pictureBox1.Image = null;image_path = ofd.FileName;pictureBox1.Image = new Bitmap(image_path);textBox1.Text = "";pictureBox2.Image = null;}private void button2_Click(object sender, EventArgs e){if (image_path == ""){return;}textBox1.Text = "";pictureBox2.Image = null;button2.Enabled = false;Application.DoEvents();image = new Mat(image_path);List<Face> ltFace = face_detector.Detect(new Mat(image_path));if (ltFace.Count > 0){result_image = image.Clone();//face_detector.DrawPred(ltFace, result_image);String info = "";foreach (Face item in ltFace){gaze_predictor.Detect(image, item);result_image = gaze_predictor.DrawOn(result_image, item,out info);}pictureBox2.Image = new Bitmap(result_image.ToMemoryStream());textBox1.Text = info;}else{textBox1.Text = "无信息";}button2.Enabled = true;}}
}

GazeEstimation.cs

 unsafe public class GazeEstimation
    {

        float[] mean = new float[] { 0.5f, 0.5f, 0.5f };
        float[] std = new float[] { 0.5f, 0.5f, 0.5f };
        int[] iris_idx_481 = new int[] { 248, 252, 224, 228, 232, 236, 240, 244 };
        int num_eye = 481;
        int input_size = 160;
        float[] eye_kps;
        Net net;

        public GazeEstimation(string modelpath)
        {
            net = CvDnn.ReadNetFromOnnx(modelpath);
            eye_kps = new float[num_eye * 2 * 3];
        }

        public void Detect(Mat img, Face box)
        {

            Point kps_right_eye = box.kpt[1];
            Point kps_left_eye = box.kpt[0];
            float[] center = new float[] { (kps_right_eye.X + kps_left_eye.X) * 0.5f, (kps_right_eye.Y + kps_left_eye.Y) * 0.5f };
            float _size = (float)(Math.Max(box.rect.Width / 1.5f, Math.Abs(kps_right_eye.X - kps_left_eye.X)) * 1.5f);

            float _scale = input_size / _size;
            //transform
            float cx = center[0] * _scale;
            float cy = center[1] * _scale;

            float[] data = new float[] { _scale, 0, (float)(-cx + input_size * 0.5), 0, _scale, (float)(-cy + input_size * 0.5) };
            Mat M = new Mat(2, 3, MatType.CV_32F, data);

            Mat cropped = new Mat();
            Cv2.WarpAffine(img, cropped, M, new Size(input_size, input_size));

            Mat rgbimg = new Mat();
            Cv2.CvtColor(cropped, rgbimg, ColorConversionCodes.BGR2RGB);

            Mat normalized_mat = Normalize(rgbimg);

            Mat blob = CvDnn.BlobFromImage(normalized_mat);

            net.SetInput(blob);

            Mat[] outs = new Mat[3] { new Mat(), new Mat(), new Mat() };
            string[] outBlobNames = net.GetUnconnectedOutLayersNames().ToArray();

            net.Forward(outs, outBlobNames);

            float* opred = (float*)outs[0].Data;//outs[0]的形状是(1,962,3)
            Mat IM = new Mat();
            Cv2.InvertAffineTransform(M, IM);
            //trans_points
            float scale = (float)Math.Sqrt(IM.At<float>(0, 0) * IM.At<float>(0, 0) + IM.At<float>(0, 1) * IM.At<float>(0, 1));
            int row = outs[0].Size(1);
            int col = outs[0].Size(2);

            for (int i = 0; i < row; i++)
            {
                eye_kps[i * 3] = IM.At<float>(0, 0) * opred[i * 3] + IM.At<float>(0, 1) * opred[i * 3 + 1] + IM.At<float>(0, 2);
                eye_kps[i * 3 + 1] = IM.At<float>(1, 0) * opred[i * 3] + IM.At<float>(1, 1) * opred[i * 3 + 1] + IM.At<float>(1, 2);
                eye_kps[i * 3 + 2] = opred[i * 3 + 2] * scale;
            }

        }

        public Mat DrawOn(Mat srcimg, Face box, out string info)
        {
            StringBuilder sb = new StringBuilder();

            float rescale = 300.0f / box.rect.Width;
            Mat eimg = new Mat();
            Cv2.Resize(srcimg, eimg, new Size(), rescale, rescale);
            //draw_item
            int row = num_eye * 2;
            for (int i = 0; i < row; i++)
            {
                float tmp = eye_kps[i * 3];
                eye_kps[i * 3] = eye_kps[i * 3 + 1] * rescale;
                eye_kps[i * 3 + 1] = tmp * rescale;
                eye_kps[i * 3 + 2] *= rescale;
            }
            //angles_and_vec_from_eye
            int slice = num_eye * 3;
            float[] theta_x_y_vec_l = new float[5];

            float[] eye_kps_l = new float[481 * 3];
            float[] eye_kps_r = new float[481 * 3];

            Array.Copy(eye_kps, 0, eye_kps_l, 0, 481 * 3);
            Array.Copy(eye_kps, 481 * 3, eye_kps_r, 0, 481 * 3);

            angles_and_vec_from_eye(eye_kps_l, iris_idx_481, theta_x_y_vec_l);
            float[] theta_x_y_vec_r = new float[5];

            angles_and_vec_from_eye(eye_kps_r, iris_idx_481, theta_x_y_vec_r);

            float[] gaze_pred = new float[] { (float)((theta_x_y_vec_l[0] + theta_x_y_vec_r[0]) * 0.5), (float)((theta_x_y_vec_l[1] + theta_x_y_vec_r[1]) * 0.5) };

            float diag = (float)Math.Sqrt((float)eimg.Rows * eimg.Cols);

            float[] eye_pos_left = new float[] { 0, 0 };
            float[] eye_pos_right = new float[] { 0, 0 };
            for (int i = 0; i < 8; i++)
            {
                int ind = iris_idx_481[i];
                eye_pos_left[0] += eye_kps[ind * 3];
                eye_pos_left[1] += eye_kps[ind * 3 + 1];
                eye_pos_right[0] += eye_kps[slice + ind * 3];
                eye_pos_right[1] += eye_kps[slice + ind * 3 + 1];
            }
            eye_pos_left[0] /= 8;
            eye_pos_left[1] /= 8;
            eye_pos_right[0] /= 8;
            eye_pos_right[1] /= 8;

            float dx = (float)(0.4 * diag * Math.Sin(theta_x_y_vec_l[1]));
            float dy = (float)(0.4 * diag * Math.Sin(theta_x_y_vec_l[0]));
            Point eye_left_a = new Point(eye_pos_left[1], eye_pos_left[0]);  左眼的箭头线的起始点坐标
            Point eye_left_b = new Point(eye_pos_left[1] + dx, eye_pos_left[0] + dy);   左右的箭头线的终点坐标

            Cv2.ArrowedLine(eimg, eye_left_a, eye_left_b, new Scalar(0, 0, 255), 5, LineTypes.AntiAlias, 0, 0.18);
            float yaw_deg_l = (float)(theta_x_y_vec_l[1] * (180 / Math.PI));
            float pitch_deg_l = (float)(-theta_x_y_vec_l[0] * (180 / Math.PI));

            dx = (float)(0.4 * diag * Math.Sin(theta_x_y_vec_r[1]));
            dy = (float)(0.4 * diag * Math.Sin(theta_x_y_vec_r[0]));

            Point eye_right_a = new Point(eye_pos_right[1], eye_pos_right[0]);  右眼的箭头线的起始点坐标
            Point eye_right_b = new Point(eye_pos_right[1] + dx, eye_pos_right[0] + dy);  右眼的箭头线的终点坐标
            Cv2.ArrowedLine(eimg, eye_right_a, eye_right_b, new Scalar(0, 0, 255), 5, LineTypes.AntiAlias, 0, 0.18);

            float yaw_deg_r = (float)(theta_x_y_vec_r[1] * (180 / Math.PI));
            float pitch_deg_r = (float)(-theta_x_y_vec_r[0] * (180 / Math.PI));

            Cv2.Resize(eimg, eimg, new Size(srcimg.Cols, srcimg.Rows));
            //draw Yaw, Pitch
            string label = String.Format("L-Yaw : {0:f2}", yaw_deg_l);
            sb.AppendLine(label);
            Cv2.PutText(eimg, label, new Point(eimg.Cols - 200, 30), HersheyFonts.HersheySimplex, 0.7, new Scalar(0, 255, 0), 2);

            label = String.Format("L-Pitch :{0:f2}", pitch_deg_l);
            sb.AppendLine(label);
            Cv2.PutText(eimg, label, new Point(eimg.Cols - 200, 60), HersheyFonts.HersheySimplex, 0.7, new Scalar(0, 255, 0), 2);

            label = String.Format("R-Yaw : {0:f2}", yaw_deg_r);
            sb.AppendLine(label);
            Cv2.PutText(eimg, label, new Point(eimg.Cols - 200, 90), HersheyFonts.HersheySimplex, 0.7, new Scalar(0, 255, 0), 2);

            label = String.Format("R-Pitch : {0:f2}", pitch_deg_r);
            sb.AppendLine(label);
            Cv2.PutText(eimg, label, new Point(eimg.Cols - 200, 120), HersheyFonts.HersheySimplex, 0.7, new Scalar(0, 255, 0), 2);

            info = sb.ToString();

            return eimg;

        }

        public Mat Normalize(Mat src)
        {
            Mat[] bgr = src.Split();
            for (int i = 0; i < bgr.Length; ++i)
            {
                bgr[i].ConvertTo(bgr[i], MatType.CV_32FC1, 1.0 / (255.0 * std[i]), (0.0 - mean[i]) / std[i]);
            }

            Cv2.Merge(bgr, src);

            foreach (Mat channel in bgr)
            {
                channel.Dispose();
            }

            return src;
        }

        /// <summary>
        /// 输入参数eye的形状是(481,3)
        /// 输入参数iris_lms_idx的长度shi
        /// 输出theta_x_y_vec的长度是5, 分别是theta_x, theta_y, vec[0], vec[1], vec[2]
        /// </summary>
        void angles_and_vec_from_eye(float[] eye, int[] iris_lms_idx, float[] theta_x_y_vec)
        {

            float[] mean = new float[] { 0, 0, 0 };
            for (int i = 0; i < 32; i++)
            {
                mean[0] += eye[i * 3];
                mean[1] += eye[i * 3 + 1];
                mean[2] += eye[i * 3 + 2];
            }
            mean[0] /= 32;
            mean[1] /= 32;
            mean[2] /= 32;

            float[] p_iris = new float[8 * 3];
            for (int i = 0; i < 8; i++)
            {
                int ind = iris_lms_idx[i];
                p_iris[i * 3] = eye[ind * 3] - mean[0];
                p_iris[i * 3 + 1] = eye[ind * 3 + 1] - mean[1];
                p_iris[i * 3 + 2] = eye[ind * 3 + 2] - mean[2];
            }

            float[] mean_p_iris = new float[] { 0, 0, 0 };
            for (int i = 0; i < 8; i++)
            {
                mean_p_iris[0] += p_iris[i * 3];
                mean_p_iris[1] += p_iris[i * 3 + 1];
                mean_p_iris[2] += p_iris[i * 3 + 2];
            }
            mean_p_iris[0] /= 8;
            mean_p_iris[1] /= 8;
            mean_p_iris[2] /= 8;

            float l2norm_p_iris = (float)Math.Sqrt(mean_p_iris[0] * mean_p_iris[0] + mean_p_iris[1] * mean_p_iris[1] + mean_p_iris[2] * mean_p_iris[2]);
            theta_x_y_vec[2] = mean_p_iris[0] / l2norm_p_iris;  ///vec[0]
            theta_x_y_vec[3] = mean_p_iris[1] / l2norm_p_iris;  ///vec[1]
            theta_x_y_vec[4] = mean_p_iris[2] / l2norm_p_iris;  ///vec[2]

            //angles_from_vec
            float x = -theta_x_y_vec[4];
            float y = theta_x_y_vec[3];
            float z = -theta_x_y_vec[2];
            float theta = (float)Math.Atan2(y, x);
            float phi = (float)(Math.Atan2(Math.Sqrt(x * x + y * y), z) - Math.PI * 0.5);
            theta_x_y_vec[0] = phi;
            theta_x_y_vec[1] = theta;
        }

    }

 unsafe public class GazeEstimation{float[] mean = new float[] { 0.5f, 0.5f, 0.5f };float[] std = new float[] { 0.5f, 0.5f, 0.5f };int[] iris_idx_481 = new int[] { 248, 252, 224, 228, 232, 236, 240, 244 };int num_eye = 481;int input_size = 160;float[] eye_kps;Net net;public GazeEstimation(string modelpath){net = CvDnn.ReadNetFromOnnx(modelpath);eye_kps = new float[num_eye * 2 * 3];}public void Detect(Mat img, Face box){Point kps_right_eye = box.kpt[1];Point kps_left_eye = box.kpt[0];float[] center = new float[] { (kps_right_eye.X + kps_left_eye.X) * 0.5f, (kps_right_eye.Y + kps_left_eye.Y) * 0.5f };float _size = (float)(Math.Max(box.rect.Width / 1.5f, Math.Abs(kps_right_eye.X - kps_left_eye.X)) * 1.5f);float _scale = input_size / _size;//transformfloat cx = center[0] * _scale;float cy = center[1] * _scale;float[] data = new float[] { _scale, 0, (float)(-cx + input_size * 0.5), 0, _scale, (float)(-cy + input_size * 0.5) };Mat M = new Mat(2, 3, MatType.CV_32F, data);Mat cropped = new Mat();Cv2.WarpAffine(img, cropped, M, new Size(input_size, input_size));Mat rgbimg = new Mat();Cv2.CvtColor(cropped, rgbimg, ColorConversionCodes.BGR2RGB);Mat normalized_mat = Normalize(rgbimg);Mat blob = CvDnn.BlobFromImage(normalized_mat);net.SetInput(blob);Mat[] outs = new Mat[3] { new Mat(), new Mat(), new Mat() };string[] outBlobNames = net.GetUnconnectedOutLayersNames().ToArray();net.Forward(outs, outBlobNames);float* opred = (float*)outs[0].Data;//outs[0]的形状是(1,962,3)Mat IM = new Mat();Cv2.InvertAffineTransform(M, IM);//trans_pointsfloat scale = (float)Math.Sqrt(IM.At<float>(0, 0) * IM.At<float>(0, 0) + IM.At<float>(0, 1) * IM.At<float>(0, 1));int row = outs[0].Size(1);int col = outs[0].Size(2);for (int i = 0; i < row; i++){eye_kps[i * 3] = IM.At<float>(0, 0) * opred[i * 3] + IM.At<float>(0, 1) * opred[i * 3 + 1] + IM.At<float>(0, 2);eye_kps[i * 3 + 1] = IM.At<float>(1, 0) * opred[i * 3] + IM.At<float>(1, 1) * opred[i * 3 + 1] + IM.At<float>(1, 2);eye_kps[i * 3 + 2] = opred[i * 3 + 2] * scale;}}public Mat DrawOn(Mat srcimg, Face box, out string info){StringBuilder sb = new StringBuilder();float rescale = 300.0f / box.rect.Width;Mat eimg = new Mat();Cv2.Resize(srcimg, eimg, new Size(), rescale, rescale);//draw_itemint row = num_eye * 2;for (int i = 0; i < row; i++){float tmp = eye_kps[i * 3];eye_kps[i * 3] = eye_kps[i * 3 + 1] * rescale;eye_kps[i * 3 + 1] = tmp * rescale;eye_kps[i * 3 + 2] *= rescale;}//angles_and_vec_from_eyeint slice = num_eye * 3;float[] theta_x_y_vec_l = new float[5];float[] eye_kps_l = new float[481 * 3];float[] eye_kps_r = new float[481 * 3];Array.Copy(eye_kps, 0, eye_kps_l, 0, 481 * 3);Array.Copy(eye_kps, 481 * 3, eye_kps_r, 0, 481 * 3);angles_and_vec_from_eye(eye_kps_l, iris_idx_481, theta_x_y_vec_l);float[] theta_x_y_vec_r = new float[5];angles_and_vec_from_eye(eye_kps_r, iris_idx_481, theta_x_y_vec_r);float[] gaze_pred = new float[] { (float)((theta_x_y_vec_l[0] + theta_x_y_vec_r[0]) * 0.5), (float)((theta_x_y_vec_l[1] + theta_x_y_vec_r[1]) * 0.5) };float diag = (float)Math.Sqrt((float)eimg.Rows * eimg.Cols);float[] eye_pos_left = new float[] { 0, 0 };float[] eye_pos_right = new float[] { 0, 0 };for (int i = 0; i < 8; i++){int ind = iris_idx_481[i];eye_pos_left[0] += eye_kps[ind * 3];eye_pos_left[1] += eye_kps[ind * 3 + 1];eye_pos_right[0] += eye_kps[slice + ind * 3];eye_pos_right[1] += eye_kps[slice + ind * 3 + 1];}eye_pos_left[0] /= 8;eye_pos_left[1] /= 8;eye_pos_right[0] /= 8;eye_pos_right[1] /= 8;float dx = (float)(0.4 * diag * Math.Sin(theta_x_y_vec_l[1]));float dy = (float)(0.4 * diag * Math.Sin(theta_x_y_vec_l[0]));Point eye_left_a = new Point(eye_pos_left[1], eye_pos_left[0]);  左眼的箭头线的起始点坐标Point eye_left_b = new Point(eye_pos_left[1] + dx, eye_pos_left[0] + dy);   左右的箭头线的终点坐标Cv2.ArrowedLine(eimg, eye_left_a, eye_left_b, new Scalar(0, 0, 255), 5, LineTypes.AntiAlias, 0, 0.18);float yaw_deg_l = (float)(theta_x_y_vec_l[1] * (180 / Math.PI));float pitch_deg_l = (float)(-theta_x_y_vec_l[0] * (180 / Math.PI));dx = (float)(0.4 * diag * Math.Sin(theta_x_y_vec_r[1]));dy = (float)(0.4 * diag * Math.Sin(theta_x_y_vec_r[0]));Point eye_right_a = new Point(eye_pos_right[1], eye_pos_right[0]);  右眼的箭头线的起始点坐标Point eye_right_b = new Point(eye_pos_right[1] + dx, eye_pos_right[0] + dy);  右眼的箭头线的终点坐标Cv2.ArrowedLine(eimg, eye_right_a, eye_right_b, new Scalar(0, 0, 255), 5, LineTypes.AntiAlias, 0, 0.18);float yaw_deg_r = (float)(theta_x_y_vec_r[1] * (180 / Math.PI));float pitch_deg_r = (float)(-theta_x_y_vec_r[0] * (180 / Math.PI));Cv2.Resize(eimg, eimg, new Size(srcimg.Cols, srcimg.Rows));//draw Yaw, Pitchstring label = String.Format("L-Yaw : {0:f2}", yaw_deg_l);sb.AppendLine(label);Cv2.PutText(eimg, label, new Point(eimg.Cols - 200, 30), HersheyFonts.HersheySimplex, 0.7, new Scalar(0, 255, 0), 2);label = String.Format("L-Pitch :{0:f2}", pitch_deg_l);sb.AppendLine(label);Cv2.PutText(eimg, label, new Point(eimg.Cols - 200, 60), HersheyFonts.HersheySimplex, 0.7, new Scalar(0, 255, 0), 2);label = String.Format("R-Yaw : {0:f2}", yaw_deg_r);sb.AppendLine(label);Cv2.PutText(eimg, label, new Point(eimg.Cols - 200, 90), HersheyFonts.HersheySimplex, 0.7, new Scalar(0, 255, 0), 2);label = String.Format("R-Pitch : {0:f2}", pitch_deg_r);sb.AppendLine(label);Cv2.PutText(eimg, label, new Point(eimg.Cols - 200, 120), HersheyFonts.HersheySimplex, 0.7, new Scalar(0, 255, 0), 2);info = sb.ToString();return eimg;}public Mat Normalize(Mat src){Mat[] bgr = src.Split();for (int i = 0; i < bgr.Length; ++i){bgr[i].ConvertTo(bgr[i], MatType.CV_32FC1, 1.0 / (255.0 * std[i]), (0.0 - mean[i]) / std[i]);}Cv2.Merge(bgr, src);foreach (Mat channel in bgr){channel.Dispose();}return src;}/// <summary>/// 输入参数eye的形状是(481,3)/// 输入参数iris_lms_idx的长度shi/// 输出theta_x_y_vec的长度是5, 分别是theta_x, theta_y, vec[0], vec[1], vec[2]/// </summary>void angles_and_vec_from_eye(float[] eye, int[] iris_lms_idx, float[] theta_x_y_vec){float[] mean = new float[] { 0, 0, 0 };for (int i = 0; i < 32; i++){mean[0] += eye[i * 3];mean[1] += eye[i * 3 + 1];mean[2] += eye[i * 3 + 2];}mean[0] /= 32;mean[1] /= 32;mean[2] /= 32;float[] p_iris = new float[8 * 3];for (int i = 0; i < 8; i++){int ind = iris_lms_idx[i];p_iris[i * 3] = eye[ind * 3] - mean[0];p_iris[i * 3 + 1] = eye[ind * 3 + 1] - mean[1];p_iris[i * 3 + 2] = eye[ind * 3 + 2] - mean[2];}float[] mean_p_iris = new float[] { 0, 0, 0 };for (int i = 0; i < 8; i++){mean_p_iris[0] += p_iris[i * 3];mean_p_iris[1] += p_iris[i * 3 + 1];mean_p_iris[2] += p_iris[i * 3 + 2];}mean_p_iris[0] /= 8;mean_p_iris[1] /= 8;mean_p_iris[2] /= 8;float l2norm_p_iris = (float)Math.Sqrt(mean_p_iris[0] * mean_p_iris[0] + mean_p_iris[1] * mean_p_iris[1] + mean_p_iris[2] * mean_p_iris[2]);theta_x_y_vec[2] = mean_p_iris[0] / l2norm_p_iris;  ///vec[0]theta_x_y_vec[3] = mean_p_iris[1] / l2norm_p_iris;  ///vec[1]theta_x_y_vec[4] = mean_p_iris[2] / l2norm_p_iris;  ///vec[2]//angles_from_vecfloat x = -theta_x_y_vec[4];float y = theta_x_y_vec[3];float z = -theta_x_y_vec[2];float theta = (float)Math.Atan2(y, x);float phi = (float)(Math.Atan2(Math.Sqrt(x * x + y * y), z) - Math.PI * 0.5);theta_x_y_vec[0] = phi;theta_x_y_vec[1] = theta;}}

下载

源码下载

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/231143.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【RabbitMQ】1 消息中间件MQ概述

目录 什么是消息中间件为什么使用消息中间件流量削峰应用解耦异步处理 主流消息中间件及选型选取原则RabbitMQRocketMQKafka如何选择 消息中间件应用场景电商秒杀案例拉勾B端C端数据同步案例支付宝购买电影票 什么是消息中间件 维基百科对消息中间件的解释&#xff1a;面向消息…

pandas保存style到excel文件中

更多pandas style用法请参考&#xff1a;https://pandas.liuzaoqi.com/doc/chapter8/style.html 示例程序 import numpy as np import pandas as pd# 示例数据 dataframe pd.DataFrame({"date": pd.date_range("2024-01-01", "2024-02-01"),&…

MyBatis标签及其应用示例

MyBatis标签及其应用示例 1. select 1.1 标签属性 id唯一的标识符parameterType传给此语句的参数的全路径名或别名如&#xff1a;com.xxx.xxx.demo.entity.User或userresultType语句返回值类型或别名。如果是集合List&#xff0c;此处填写集合的泛型T&#xff0c;而不是集合…

紫光展锐5G扬帆出海 | 东南亚成为5G新热土

东南亚是一块充满活力和潜力的市场&#xff0c;这里人口基数大、年轻消费群体占比高&#xff0c;电子市场在过去几年显著增长。 增速“狂飙”的东南亚手游 近年来&#xff0c;东南亚手游下载量逐年增长&#xff0c;2023 年第一季度下载量突破 21 亿次&#xff0c;贡献了全球近…

Python split()方法详解:分割字符串

Python 中&#xff0c;除了可以使用一些内建函数获取字符串的相关信息外&#xff08;例如 len() 函数获取字符串长度&#xff09;&#xff0c;字符串类型本身也拥有一些方法供我们使用。 注意&#xff0c;这里所说的方法&#xff0c;指的是字符串类型 str 本身所提供的&#x…

Selenium-java 定位元素时切换iFrame时的方法

具体方法如下图所示&#xff0c;如果iFrame中嵌套多层iFrame需要逐层定位到需要的那一层iFrame,完成操作后&#xff0c;执行该代码&#xff1a;driver.switchTo() .defaultContent() ; 是返回最顶部的frame

vue-vant组件库

组件库&#xff1a;第三方封装好了很多很多的组件&#xff0c;整合到一起就是一个组件库。 官网&#xff1a;Vant 2 - Mobile UI Components built on Vue vant支持vue2&#xff0c;也支持vue3&#xff1b;vant2支持vue2&#xff0c;vant3、vant4支持vue3 分类 vue的组件库…

【中小型企业网络实战案例 八】配置映射内网服务器和公网多出口、业务测试和保存配置

相关学习文章&#xff1a; 【中小型企业网络实战案例 一】规划、需求和基本配置 【中小型企业网络实战案例 二】配置网络互连互通【中小型企业网络实战案例 三】配置DHCP动态分配地址 【中小型企业网络实战案例 四】配置OSPF动态路由协议【中小型企业网络实战案例 五】配置可…

CH08_管理状态

Observer 模式 观察者模式&#xff08;Observer&#xff09;&#xff0c;又叫发布订阅模式&#xff08;Publish/Sunscribe&#xff09;模式&#xff0c;定义了一种一对多的依赖关系&#xff0c;让多个观察者对象同时监听某一个主题对象。这个主题对象在状态发生变化时&#xf…

LiveSIPB流媒体国网B接口功能-国网B接口服务安装使用说明

LiveSIPB 国网B接口服务安装使用说明 1、服务说明1.1、安装包说明1.2、国网B接口信令服务1.3、国网B接口流媒体服务1.4、配置信令服务(LiveCMS)1.5、配置流媒体服务(LiveSMS) 2、服务运行2.1、Windows2.2、Linux 3、配置设备接入3.1、海康STATE_GRID接入示例 4、平台使用4.1、管…

全网唯一值得推荐的C/C++框架和库

全网唯一值得推荐的C/C框架和库 C程序员开发指南 ​ 关注我&#xff0c;天天分享C/C开发技术干货&#xff01; ​关注他 30 人赞同了该文章 ​ 目录 收起 标准库 C通用框架和库 人工智能 异步事件循环 音频 生态学 压缩 并发性 容器 数据库 调试 游戏引擎 图…

【C语言】指针小结

一、指针是什么&#xff1f; 可以通过运算符&来取得变量实际保存的起始地址。 &#xff08;这个地址是虚拟地址&#xff0c;并不是真正物理内存上的地址。&#xff09; **数据类型 *标识符 &变量;** **int pa &a; int pa NULL; (NULL表示地址为0的内存空间…

(15)微信自动化测试-针对微信主窗体的行为控制

应一位药厂的朋友咨询&#xff0c;他说他想知道如何实现下面的功能&#xff0c;都是针对微信主窗体的一些控制&#xff01;今天我就给他解惑并安排&#xff01; 微信主窗体是否当前处于最小化。微信主窗体是否隐藏到了系统托盘。最小化微信主窗体。最大化微信主窗体。微信主窗…

媒体捕捉-拍照

引言 在项目开发中&#xff0c;从媒体库中选择图片或使用相机拍摄图片是一个极为普遍的需求。通常&#xff0c;我们使用UIImagePickerController来实现单张图片选择或启动相机拍照。整个拍照过程由UIImagePickerController内部实现&#xff0c;无需我们关心细节&#xff0c;只…

了解近20年临床检验结果互认的推动-九五小庞

检验结果互认的政策沿革 新冠核酸检测可以说是第一个全国范围内&#xff0c;各医疗机构之间的结果互认项目&#xff0c;也是ICL对于检验结果互认的一个实践。我们对于检验结果互认早在2000年&#xff0c;就已经引起了国家层面的重视&#xff0c;并且联合多部委发布了相关指导意…

docker容器化部署及数据持久化

1、加载MySQL 5.7的镜像 docker load -i mysql-5.7.tar.gz 2、执⾏命令启动MySQL容器&#xff1a; sh start-mysql.sh docker run -itd \ --name mysql \ --restart always \ -p 30036:3306 \ -v $PWD/mysql/config-file.cnf:/etc/mysql/conf.d/config-file.cnf \ -v $PWD/m…

【竞技宝】DOTA2:二号位地位发生变化 圣斧、血棘助法核重回巅峰!

北京时间2024年1月5日&#xff0c;目前国服已经更新7.35b版本一段时间了&#xff0c;在这段时间里&#xff0c;各位看官是否感受到了比赛节奏和英雄胜率方面的变化呢&#xff1f;从全分段的出场率以及胜率的变化来看&#xff0c;二号位在游戏内的地位已经发生了很大的变化。 在…

小兔鲜儿 uniapp - SKU 模块

目录 存货单位&#xff08;SKU&#xff09;​ 插件市场​ 下载 SKU 插件​ 使用 SKU 插件​ 插件类型问题​ 核心业务​ 渲染商品规格​ 打开弹窗交互​ 渲染被选中的值​ 存货单位&#xff08;SKU&#xff09;​ SKU 概念 存货单位&#xff08;Stock Keeping Unit&a…

论Acrel-2000MG微电网能量管理系统在储能行业的应用-安科瑞 蒋静

一、概述: 在新型电力系统中新能源装机容量逐年提高&#xff0c;但是新能源比如光伏发电、风力发电是不稳定的能源&#xff0c;所以要维持电网稳定&#xff0c;促进新能源发电的消纳&#xff0c;储能将成为至关重要的一环&#xff0c;是分布式光伏、风电等新能源消纳以及电网安…