Beispiel #1
0
        public void Exec(String input, String output)
        {
            this.InputFileList = input;
            this.OutPutFolda   = output;

            //学習するファイルを読み込む
            ReadFileList();

            FaceFeature face_feature = new FaceFeature();

            face_feature.FaceList    = this.FaceList;
            face_feature.IDList      = this.IDList;
            face_feature.OutPutFolda = this.OutPutFolda;

            //特徴点を出す
            face_feature.DetectFacePoint();


            //学習実行
            SVMManage svm_manage = new SVMManage();

            svm_manage.TrainingExec(face_feature.FeatuerValueList);

            //学習ファイルをxmlに書き出す
            String xml_name = @"SvmLearning.xml";

            svm_manage.svm.Save(xml_name);
//            svm_manage.SVMJudge();
        }
Beispiel #2
0
        public void Exec(String input, String output)
        {
            this.InputFileList = input;
            this.OutPutFolda = output;

            //学習するファイルを読み込む
            ReadFileList();

            FaceFeature face_feature = new FaceFeature();
            face_feature.FaceList = this.FaceList;
            face_feature.IDList = this.IDList;
            face_feature.OutPutFolda = this.OutPutFolda;

            //特徴点を出す
            face_feature.DetectFacePoint();


            //学習実行
            SVMManage svm_manage = new SVMManage();
            svm_manage.TrainingExec(face_feature.FeatuerValueList);

            //学習ファイルをxmlに書き出す
            String xml_name = @"SvmLearning.xml";
            svm_manage.svm.Save(xml_name);
//            svm_manage.SVMJudge();
            
        }
Beispiel #3
0
        //SVM判定
        public int SVMPredict(FaceFeature.FeatureValue feature)
        {
            //学習ファイルを読み込んでいなかったらロード
            if (this.LoadFlag == false)
            {
                this.libSVM_model_1 = SVM.LoadModel(@"model_Feature_L_EYE_NOSE.xml");
                this.libSVM_model_2 = SVM.LoadModel(@"model_Feature_L_EYE_MOUTH.xml");
                this.libSVM_model_3 = SVM.LoadModel(@"model_Feature_R_EYE_MOUTH.xml");
                this.LoadFlag = true;
            }

            double[] feature_array = new double[2];
            int[] answer = new int[3];

            {
                SetFeatureToArray(feature, ref feature_array, LEARNING_TYPE.L_EYE_NOSE);

                //問題を作成
                SVMNode[] node_array = new SVMNode[2];
                node_array[0] = new SVMNode(1, feature_array[0]);
                node_array[1] = new SVMNode(2, feature_array[1]);

                answer[0] = (int)SVM.Predict(libSVM_model_1, node_array);
                return answer[0];
            }
/*
            {
                SetFeatureToArray(feature, ref feature_array, LEARNING_TYPE.L_EYE_MOUTH);

                //問題を作成
                SVMNode[] node_array = new SVMNode[2];
                node_array[0] = new SVMNode(1, feature_array[0]);
                node_array[1] = new SVMNode(2, feature_array[1]);

                answer[1] = (int)SVM.Predict(libSVM_model_2, node_array);
            }
            {
                SetFeatureToArray(feature, ref feature_array, LEARNING_TYPE.R_EYE_MOUTH);

                //問題を作成
                SVMNode[] node_array = new SVMNode[2];
                node_array[0] = new SVMNode(1, feature_array[0]);
                node_array[1] = new SVMNode(2, feature_array[1]);

                answer[2] = (int)SVM.Predict(libSVM_model_2, node_array);
            }
*/

            int final = answer[0] + answer[1] + answer[2];

            if(final < 5) { final = 1; }
            else { final = 2; }
            return final;
        }
Beispiel #4
0
        //リストから学習を行う
        private void buttonTrainFile_Click(object sender, EventArgs e)
        {
            //ファイルを選択
            OpenFileDialog ofd = new OpenFileDialog();

            //はじめのファイル名を指定する
            //はじめに「ファイル名」で表示される文字列を指定する
            ofd.FileName = "";
            //はじめに表示されるフォルダを指定する
            //指定しない(空の文字列)の時は、現在のディレクトリが表示される
            ofd.InitialDirectory = @"";
            //[ファイルの種類]に表示される選択肢を指定する
            //指定しないとすべてのファイルが表示される
            ofd.Filter =
                "学習用ファイルリスト|*.txt";
            //[ファイルの種類]ではじめに
            //「すべてのファイル」が選択されているようにする
            ofd.FilterIndex = 2;
            //タイトルを設定する
            ofd.Title = "判定する画像ファイルを選択して下さい";
            ofd.RestoreDirectory = true;
            ofd.CheckFileExists = true;
            ofd.CheckPathExists = true;

            //ダイアログを表示する
            if (ofd.ShowDialog() == DialogResult.OK)
            {

            }

            //出力用のフォルダを設定する
            InputFileList = ofd.FileName;
            OutPutFolda = @"D:\myprog\github\svm_out"; // 仮設定

            //学習するファイルを読み込む
            ReadFileList();

            FaceFeature face_feature = new FaceFeature();
            face_feature.FaceList = this.FaceList;
            face_feature.IDList = this.IDList;
            face_feature.OutPutFolda = this.OutPutFolda;

            //特徴点を出す
            face_feature.DetectFacePoint();

            //学習実行
            SVMManage svm_manage = new SVMManage();
            svm_manage.TrainingExec(face_feature.FeatuerValueList);

            //エラー表示
            MessageBox.Show("lisvm_model.xmlを作成しました",
            "完了",
            MessageBoxButtons.OK
            );

        }
Beispiel #5
0
        /// <summary>
        /// 単体の特徴量構造体を配列に直す  要検討
        /// </summary>
        /// <param name="feature"></param>
        /// <param name="value_array"></param>
        private void SetFeatureToArray(FaceFeature.FeatureValue feature, ref double[] value_array)
        {
            int idx = 0;
            value_array[idx++] = (feature.LeftEyeValueL);
//            value_array[idx++] = (feature.LeftEyeValueR);
//            value_array[idx++] = (feature.RightEyeValueL);
//            value_array[idx++] = (feature.RightEyeValueR);
            value_array[idx++] = (feature.NoseLValueL);
//            value_array[idx++] = (feature.NoseLValueR);
//            value_array[idx++] = (feature.MouthLValueL);
//            value_array[idx++] = (feature.MouthLValueR);
        }
Beispiel #6
0
        //SVM判定
        public int SVMPredict(FaceFeature.FeatureValue feature)
        {
            double[] feature_array = new double[2];
            SetFeatureToArray(feature, ref feature_array);
            CvMat dataMat = new CvMat(1, 2, MatrixType.F32C1, feature_array, true);

            //学習ファイルを読み込んでいなかったらロード
            if (this.LoadFlag == false)
            {
                svm.Load(@"SvmLearning.xml");
                this.LoadFlag = true;
            }

            return (int)this.svm.Predict(dataMat);
        }
Beispiel #7
0
        /// <summary>
        /// 単体の特徴量構造体を配列に直す  要検討
        /// </summary>
        /// <param name="feature"></param>
        /// <param name="value_array"></param>
        private void SetFeatureToArray(FaceFeature.FeatureValue feature, ref double[] value_array, LEARNING_TYPE type)
        {
            int idx = 0;
            if (type == LEARNING_TYPE.L_EYE_NOSE)
            {
                value_array[idx++] = (feature.LeftEyeValueL);
                //            value_array[idx++] = (feature.LeftEyeValueR);
                //            value_array[idx++] = (feature.RightEyeValueL);
                //            value_array[idx++] = (feature.RightEyeValueR);
                value_array[idx++] = (feature.NoseLValueL);
                //            value_array[idx++] = (feature.NoseLValueR);
                //            value_array[idx++] = (feature.MouthLValueL);
                //            value_array[idx++] = (feature.MouthLValueR);
            }
            else if (type == LEARNING_TYPE.L_EYE_MOUTH)
            {
                value_array[idx++] = (feature.LeftEyeValueL);
                //            value_array[idx++] = (feature.LeftEyeValueR);
                //            value_array[idx++] = (feature.RightEyeValueL);
                //            value_array[idx++] = (feature.RightEyeValueR);
                //value_array[idx++] = (feature.NoseLValueL);
                //            value_array[idx++] = (feature.NoseLValueR);
                value_array[idx++] = (feature.MouthLValueL);
                //            value_array[idx++] = (feature.MouthLValueR);

            }
            else if (type == LEARNING_TYPE.R_EYE_MOUTH)
            {
                //value_array[idx++] = (feature.LeftEyeValueL);
                //            value_array[idx++] = (feature.LeftEyeValueR);
                value_array[idx++] = (feature.RightEyeValueL);
                //            value_array[idx++] = (feature.RightEyeValueR);
                //value_array[idx++] = (feature.NoseLValueL);
                //            value_array[idx++] = (feature.NoseLValueR);
                value_array[idx++] = (feature.MouthLValueL);
                //            value_array[idx++] = (feature.MouthLValueR);
            }
        }