Beispiel #1
0
        private void analysisTFIDF()
        {
            string content = textBox1.Text;
            var    dfs     = AnalyzeTool.loadDF();
            var    words   = AnalyzeTool.getTFIDF(content, dfs);
            string output  = "";

            foreach (var w in words)
            {
                output += string.Format("{0}-{1}\r\n", w.Word, w.Num);
            }
            printChangeResult(output);
        }
Beispiel #2
0
        private void analysisTF()
        {
            string          str   = textBox1.Text;
            List <WordPair> words = AnalyzeTool.getTFWithSort(str, true);

            string output = "";

            foreach (var w in words)
            {
                output += string.Format("{0} {1} {2}\r\n", w.Word, w.Flag, w.Num);
            }
            printChangeResult(output);
        }
Beispiel #3
0
        /// <summary>
        /// 文档词频预处理,得到一个文件 WordDFs.txt
        /// </summary>
        private void analysisDF()
        {
            string path = AnalyzeTool.dataDic;

            string[] files = Directory.GetFiles(path, "*.txt");
            for (int i = 0; i < files.Length; i++)
            {
                string f   = files[i];
                var    dfs = AnalyzeTool.loadDF();
                dfs = AnalyzeTool.getIDF(dfs, new string[] { f });
                AnalyzeTool.saveDF(dfs);
                print(string.Format("完成:{0}({1}/{2})", f, i + 1, files.Length));

                string tpath = "./backup/";
                if (!Directory.Exists(tpath))
                {
                    Directory.CreateDirectory(tpath);
                }
                File.Move(f, tpath + Path.GetFileName(f));
            }
            print(string.Format("over.({0})", files.Length));
        }
Beispiel #4
0
        private double outsideCanthusDistance; //外眦间距
        #endregion

        /// <summary>
        /// 初始化对象
        /// </summary>
        /// <param name="face"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        private void Init(Face face, int width, int height)
        {
            if (null == face || null == face.landmark || face.landmark.contour_chin.x == 0 || face.landmark.nose_contour_lower_middle.x == 0)
            {
                throw new Exception("face 数据为空!");
            }
            this.face       = face;
            this.landmark   = face.landmark;
            this.ima_width  = width;
            this.ima_height = height;

            //计算公共参数
            #region
            noseStartPoint         = Center(face.landmark.nose_contour_left1, face.landmark.nose_contour_right1);
            mouthMiddle            = Center(face.landmark.mouth_lower_lip_top, face.landmark.mouth_upper_lip_bottom);
            eyeBrowMiddle          = Center(face.landmark.left_eyebrow_right_corner, face.landmark.right_eyebrow_left_corner);
            eye_break_width        = Distance(face.landmark.left_eye_left_corner, face.landmark.left_eye_right_corner) * 0.5f + Distance(face.landmark.right_eye_left_corner, face.landmark.right_eye_right_corner) * 0.5f;
            eyeBallMiddle          = Center(face.landmark.left_eye_center, face.landmark.right_eye_center);
            outsideCanthusDistance = Distance(landmark.left_eye_left_corner, landmark.right_eye_right_corner);
            eyeBallDistance        = Distance(face.landmark.left_eye_pupil, face.landmark.right_eye_pupil);
            noseWidth  = Distance(landmark.nose_left, landmark.nose_right);
            faceWidth  = (double)Distance(face.landmark.contour_left2, face.landmark.contour_right2);
            mouthWidth = Distance(landmark.mouth_left_corner, landmark.mouth_right_corner);
            #endregion
            //计算面容参数,先计算各参数
            #region
            sOutLine.eyeballDistance             = eyeBallDistance;
            sOutLine.facial_width                = faceWidth;
            sOutLine.morphological_facial_height = (double)Distance(face.landmark.contour_chin, noseStartPoint);
            sOutLine.physiognomic_upper_height   = (double)Distance(noseStartPoint, mouthMiddle);
            sOutLine.facial_middle_lower_height  = (double)Distance(eyeBrowMiddle, face.landmark.contour_chin);
            sOutLine.facial_middle_height        = (double)Distance(eyeBrowMiddle, face.landmark.nose_contour_lower_middle);
            sOutLine.facial_lower_height         = (double)Distance(face.landmark.nose_contour_lower_middle, face.landmark.contour_chin);

            sOutLine.bigonial_breadth     = (double)Distance(face.landmark.contour_left5, face.landmark.contour_right5);
            sOutLine.left_bigonial_angle  = (double)Angle(face.landmark.contour_right5, face.landmark.contour_right4, face.landmark.contour_right6);
            sOutLine.right_bigonial_angle = (double)Angle(face.landmark.contour_left5, face.landmark.contour_left4, face.landmark.contour_left6);
            //计算面容指数,待所有参数计算完再计算指数,因为依赖的原因
            sOutLine.morphological_facial_index = sOutLine.morphological_facial_height / sOutLine.facial_width;
            sOutLine.bigonial_breadth_index     = sOutLine.bigonial_breadth / sOutLine.facial_width;
            sOutLine.three_part_rate            = sOutLine.facial_lower_height / sOutLine.facial_middle_height;//1.08为校正
            sOutLine.five_eye_rate =
                +.1 * Math.Abs(Distance(face.landmark.left_eye_left_corner, face.landmark.left_eye_right_corner) / Distance(face.landmark.left_eye_right_corner, face.landmark.right_eye_left_corner) - 1)
                + .1 * Math.Abs(Distance(face.landmark.right_eye_left_corner, face.landmark.left_eye_right_corner) / Distance(face.landmark.right_eye_left_corner, face.landmark.right_eye_right_corner) - 1);

            sOutLine.facial_width_compair_middle_lower_height = (double)(sOutLine.facial_width / sOutLine.facial_middle_lower_height / 1.08);//1.08为校正
            Point temp = new Point();
            temp.x = eyeBallMiddle.x; temp.y = face.landmark.contour_chin.y;

            sOutLine.left_bigonial_compair_right_bigonial = .25 * Math.Abs(Angle(landmark.contour_chin, landmark.contour_left5, eyeBallMiddle) / Angle(landmark.contour_chin, eyeBallMiddle, landmark.contour_right5) - 1)
                                                            + .25 * Math.Abs(Angle(landmark.contour_chin, landmark.contour_left3, eyeBallMiddle) / Angle(landmark.contour_chin, eyeBallMiddle, landmark.contour_right3) - 1)
                                                            + .25 * Math.Abs(Angle(landmark.contour_chin, landmark.contour_left7, eyeBallMiddle) / Angle(landmark.contour_chin, eyeBallMiddle, landmark.contour_right7) - 1)
                                                            + .25 * Math.Abs(Angle(landmark.contour_chin, landmark.contour_left9, eyeBallMiddle) / Angle(landmark.contour_chin, eyeBallMiddle, landmark.contour_right9) - 1);
            sOutLine.bigonial_angle = (double)(sOutLine.left_bigonial_angle * 0.5 + sOutLine.right_bigonial_angle * 0.5);
            sOutLine.chin_angle     = Angle(AnalyzeTool.FacePoit_To_SystemPoint(landmark.contour_chin, ima_width, ima_height), AnalyzeTool.FacePoit_To_SystemPoint(landmark.contour_left9, ima_width, ima_height), AnalyzeTool.FacePoit_To_SystemPoint(landmark.contour_right9, ima_width, ima_height));
            #endregion
            //计算眉参数
            #region
            sEyebrow.eyebrow_distance                 = (double)Distance(landmark.left_eyebrow_right_corner, landmark.right_eyebrow_left_corner);
            sEyebrow.left_eyebrow_angle               = Angle(landmark.right_eyebrow_left_corner, landmark.right_eyebrow_right_corner, eyeBrowMiddle);
            sEyebrow.right_eyebrow_angle              = Angle(landmark.left_eyebrow_right_corner, landmark.left_eyebrow_left_corner, eyeBrowMiddle);
            sEyebrow.left_eyebrow_nose_angle          = (double)Angle(landmark.right_eyebrow_left_corner, landmark.right_eyebrow_right_corner, landmark.nose_right);
            sEyebrow.right_eyebrow_nose_angle         = (double)Angle(landmark.left_eyebrow_right_corner, landmark.left_eyebrow_left_corner, landmark.nose_left);
            sEyebrow.left_eyebrowEnd_eyeEnd_noseWing  = (double)Angle(landmark.right_eye_right_corner, landmark.right_eyebrow_right_corner, landmark.nose_right);
            sEyebrow.right_eyebrowEnd_eyeEnd_noseWing = (double)Angle(landmark.left_eye_left_corner, landmark.left_eyebrow_left_corner, landmark.nose_left);
            sEyebrow.eyebrow_compair_nose_distance    = sEyebrow.eyebrow_distance / noseWidth;
            sEyebrow.eyebrow_angle = .5f * sEyebrow.left_eyebrow_angle + .5f * sEyebrow.right_eyebrow_angle;
            #endregion
            //计算眼参数
            #region
            sEye.left_eye_break_hight             = Distance(landmark.right_eye_top, landmark.right_eye_bottom);
            sEye.right_eye_break_hight            = Distance(landmark.left_eye_bottom, landmark.left_eye_top);
            sEye.left_eye_break_width             = Distance(landmark.right_eye_left_corner, landmark.right_eye_right_corner);
            sEye.right_eye_break_width            = Distance(landmark.left_eye_right_corner, landmark.left_eye_left_corner);
            sEye.inner_canthus_distance           = Distance(landmark.left_eye_right_corner, landmark.right_eye_left_corner);
            sEye.outside_canthus_distance         = outsideCanthusDistance;
            sEye.left_inner_outside_anthus_angle  = Angle(landmark.right_eye_left_corner, Center(landmark.right_eye_left_corner, landmark.left_eye_right_corner), landmark.right_eye_right_corner);
            sEye.right_inner_outside_anthus_angle = Angle(landmark.left_eye_right_corner, Center(landmark.right_eye_left_corner, landmark.left_eye_right_corner), landmark.left_eye_left_corner);
            sEye.inner_outside_anthus_angle       = sEye.left_inner_outside_anthus_angle * .5f + sEye.right_inner_outside_anthus_angle * .5f;
            sEye.eye_break_WH_rate = eye_break_width / (.5f * sEye.left_eye_break_hight + .5f * sEye.right_eye_break_hight);
            sEye.eye_break_compair_inner_canthus = eye_break_width / sEye.inner_canthus_distance;
            sEye.eye_face_index = sEye.outside_canthus_distance / Distance(landmark.contour_left1, landmark.contour_right1);
            #endregion
            //计算鼻参数
            #region
            sNose.nose_width                      = noseWidth;
            sNose.nose_body_width                 = Distance(landmark.nose_contour_left2, landmark.nose_contour_right2);
            sNose.nose_height                     = Distance(noseStartPoint, landmark.nose_contour_lower_middle);
            sNose.nose_width_compair_body         = sNose.nose_width / sNose.nose_body_width;
            sNose.nose_width_compair_facial_width = sNose.nose_width / faceWidth;
            Point noseMiddleLeft = new Point();
            noseMiddleLeft.x = landmark.nose_contour_lower_middle.x - 50;
            noseMiddleLeft.y = landmark.nose_contour_lower_middle.y;
            Point noseMiddleRight = new Point();
            noseMiddleRight.x = landmark.nose_contour_lower_middle.x + 50;
            noseMiddleRight.y = landmark.nose_contour_lower_middle.y;

            sNose.nose_height_compair_facial_width = faceWidth / sNose.nose_height;
            sNose.nose_index       = sNose.nose_width / sNose.nose_height;
            sNose.nose_mouth_index = sNose.nose_width / mouthWidth;
            #endregion
            //计算口参数
            #region
            sMouth.mouth_width                          = mouthWidth;
            sMouth.mouth_chin_distance                  = Distance(mouthMiddle, landmark.contour_chin);
            sMouth.nose_mouth_distance                  = Distance(landmark.nose_contour_lower_middle, mouthMiddle);
            sMouth.nose_chin_distance                   = Distance(landmark.nose_contour_lower_middle, landmark.contour_chin);
            sMouth.lip_hight                            = Distance(Center(landmark.mouth_lower_lip_bottom, landmark.mouth_lower_lip_top), Center(landmark.mouth_upper_lip_bottom, landmark.mouth_upper_lip_top));
            sMouth.mouth_width_compair_mouth_chin       = mouthWidth / sMouth.mouth_chin_distance;
            sMouth.nose_mouth_compair_nose_chin         = sMouth.nose_mouth_distance / sMouth.nose_chin_distance;
            sMouth.mouth_width_compair_eyeBall_distance = mouthWidth / eyeBallDistance;
            sMouth.mouth_index                          = sMouth.lip_hight / mouthWidth;
            sMouth.lip_eye_index                        = mouthWidth / outsideCanthusDistance;
            sMouth.smile = (double)face.attribute.smiling.value;

            sMouth.mouth_angle = .5f * Angle(mouthMiddle, landmark.mouth_left_corner, eyeBallMiddle) + .5f * Angle(mouthMiddle, landmark.mouth_right_corner, eyeBallMiddle);
            sMouth.lip_index   = Distance(landmark.mouth_upper_lip_bottom, landmark.mouth_upper_lip_top) / Distance(landmark.mouth_lower_lip_bottom, landmark.mouth_lower_lip_top);
            sMouth.delta_MBCMC = .819f * (sMouth.mouth_width_compair_mouth_chin - 1.218f) / 1.218f;
            sMouth.delta_NMCNC = .382f * (sMouth.nose_mouth_compair_nose_chin - .36f) / .36f;
            sMouth.delta_MBCED = .618f * (sMouth.mouth_width_compair_eyeBall_distance - .819f) / .819f;
            sMouth.delta_MI    = .218f * (sMouth.mouth_index - .182f) / .182f;
            sMouth.delta_LEI   = .382f * (sMouth.lip_eye_index - .56f) / .56f;
            sMouth.delta_LI    = .382f * (sMouth.lip_index - .618f) / .618f;
            sMouth.delta_MA    = 1.5f * (sMouth.mouth_angle - 82) / 82;
            sMouth.delta_S     = .1f * ((.6f + .4f * sMouth.smile / 100) - 1);


            #endregion
            //计算轮廓部分偏差
            #region
            sOutLine.delta_BBI    = 1.5 * ((sOutLine.bigonial_breadth_index - 0.819) / 0.819); //两颌间角距离指数与标准差值
            sOutLine.delta_TPR    = (double)((sOutLine.three_part_rate - 0.95) / 0.95);        //三庭指标与标准值差距
            sOutLine.delta_FER    = sOutLine.five_eye_rate;
            sOutLine.delta_FWCMLH = sOutLine.facial_width_compair_middle_lower_height - 1;
            sOutLine.delta_LBCRB  = 2 * sOutLine.left_bigonial_compair_right_bigonial;
            sOutLine.delta_BA     = 2 * (168 - sOutLine.bigonial_angle) / 168;
            sOutLine.delta_CA     = (sOutLine.chin_angle - 146) / 146;

            #endregion
            //计算眉偏差
            #region
            sEyebrow.delta_LEEN = (sEyebrow.left_eyebrowEnd_eyeEnd_noseWing - 180) / 180;//5为校正
            sEyebrow.delta_REEN = (sEyebrow.right_eyebrowEnd_eyeEnd_noseWing - 180) / 180;
            sEyebrow.delta_LENA = .5F * (sEyebrow.left_eyebrow_nose_angle - 90) / 90;
            sEyebrow.delta_RENA = .5f * (sEyebrow.right_eyebrow_nose_angle - 90) / 90;
            sEyebrow.delta_ECND = .2f * (sEyebrow.eyebrow_compair_nose_distance - .9f) / .9f;

            sEyebrow.delta_EA = 6.18f * (sEyebrow.eyebrow_angle - 180) / 180;

            #endregion
            //计算眼部分偏差
            #region
            sEye.delta_EBWR  = (sEye.eye_break_WH_rate - 2.618f) / 2.618f;
            sEye.delta_EBCIC = .5F * (sEye.eye_break_compair_inner_canthus - .9F) / .9F;
            sEye.delta_IACO  = 2 * (sEye.inner_outside_anthus_angle - 170) / 170;
            sEye.delta_EFI   = .5F * (sEye.eye_face_index - .618f) / .618F;

            #endregion
            //计算鼻偏差
            #region
            sNose.delta_NWWCB = .618f * (sNose.nose_width_compair_body - 1.318f) / 1.318f;
            sNose.delta_NWCFW = .618f * (sNose.nose_width_compair_facial_width - .232f) / .232f;

            sNose.delta_NHCFW = (sNose.nose_height_compair_facial_width - 3.18f) / 3.18f;
            sNose.delta_NI    = .618f * (sNose.nose_index - .732f) / .732f;
            sNose.delta_NMI   = .618f * (sNose.nose_mouth_index - .68f) / .68f;

            #endregion


            Calculate();
        }