Ejemplo n.º 1
0
        public static List <UKI_DataRaw> BVH_convert(String path_origin)
        {
            List <UKI_DataRaw> list_raw     = new List <UKI_DataRaw>();
            List <MocapNode[]> list_nodeSet = new List <MocapNode[]>();

            try
            {
                List <string> data_origin = TheTool.read_File_getListString(path_origin);
                Boolean       start       = false;
                int           row_i       = 0;
                foreach (string row in data_origin)
                {
                    if (start)
                    {
                        BVH_readRow(ref list_raw, ref list_nodeSet, row_i, row);
                        row_i++;
                    }
                    if (!start && row.Contains("Frame Time"))
                    {
                        start = true;
                    }
                }
            }
            catch (Exception ex) { TheSys.showError(ex); }
            //Scale = http://mocap.cs.cmu.edu/faqs.php : /.45 * 0.0254
            TheUKI.UKI_DataRaw_scaling(ref list_raw, 0.05644444444444444444444444444444, 0);
            return(list_raw);
        }
Ejemplo n.º 2
0
        //Modeling transition patterns between events for temporal human action segmentation and classification
        public static List <int[]> extractKeyPose_Angular(Instance inst)
        {
            List <int[]>          list_keyPose    = new List <int[]>();
            List <UKI_DataDouble> list_dataAngles = new List <UKI_DataDouble>();
            List <string>         output_print    = new List <string>();

            foreach (UKI_DataRaw d in inst.getDataRaw(false))
            {
                UKI_DataDouble dataAngles = new UKI_DataDouble();
                dataAngles.id = d.id;
                dataAngles.data.Add(ThePostureCal.calAngle_3Points(d.Spine, d.ShoulderLeft, d.ElbowLeft));
                dataAngles.data.Add(ThePostureCal.calAngle_3Points(d.ShoulderLeft, d.ElbowLeft, d.WristLeft));
                dataAngles.data.Add(ThePostureCal.calAngle_3Points(d.Spine, d.ShoulderRight, d.ElbowRight));
                dataAngles.data.Add(ThePostureCal.calAngle_3Points(d.ShoulderRight, d.ElbowRight, d.WristRight));
                dataAngles.data.Add(ThePostureCal.calAngle_3Points(d.Spine, d.HipLeft, d.KneeLeft));
                dataAngles.data.Add(ThePostureCal.calAngle_3Points(d.HipLeft, d.KneeLeft, d.AnkleLeft));
                dataAngles.data.Add(ThePostureCal.calAngle_3Points(d.Spine, d.HipRight, d.KneeRight));
                dataAngles.data.Add(ThePostureCal.calAngle_3Points(d.HipLeft, d.KneeLeft, d.AnkleLeft));
                dataAngles.data.Add(ThePostureCal.calAngle_3Points(d.Head, d.ShoulderCenter, d.Spine));
            }
            if (path_saveFolder != "")
            {
                output_print.Add("id,ShouldL,ElbowL,ShouldR,ElbowR,HipL,KneeL,HipR,KneeR,Neck");
                output_print.AddRange(TheUKI.UKI_DataDouble_convertToListString(list_dataAngles));
                TheTool.exportCSV_orTXT(path_saveFolder + @"/" + inst.name + ".csv", output_print, false);
            }
            return(list_keyPose);
        }
Ejemplo n.º 3
0
        public static List <int[]> extractKeyPose_SamAlgo(Instance inst)
        {
            List <int[]>  list_keyPose_preCombine   = new List <int[]>();
            List <int[]>  list_keyPose_afterCombine = new List <int[]>();
            List <string> output_print  = new List <string>();
            List <string> output_print2 = new List <string>();
            //----------
            List <UKI_DataDouble> list_data  = TheUKI.UKI_DataDouble_ChangeBwFrame(inst.getDataNorm());
            List <UKI_DataDouble> list_data2 = TheUKI.UKI_DataDouble_MVA(list_data, 25);

            list_keyPose_preCombine.AddRange(TheUKI.UKI_DataDouble_getKeyPose_CrossThreshold(list_data2, samAlgo_threshold));
            list_keyPose_preCombine   = TheTool.listArray_sort(list_keyPose_preCombine, 0);
            list_keyPose_afterCombine = TheUKI.keyPose_Combine_longestPath(list_keyPose_preCombine);
            if (path_saveFolder != "")
            {
                output_print.Add("id,Head,ShoulderCenter,ShoulderLeft,ShoulderRight,ElbowLeft,ElbowRight,WristLeft,WristRight,HandLeft,HandRight,Spine,HipCenter,HipLeft,HipRight,KneeLeft,KneeRight,AnkleLeft,AnkleRight,FootLeft,FootRight");
                output_print.AddRange(TheUKI.UKI_DataDouble_convertToListString(list_data));
                TheTool.exportCSV_orTXT(path_saveFolder + @"/" + inst.name + " 1 (Change).csv", output_print, false);
                output_print2.Add("id,Head,ShoulderCenter,ShoulderLeft,ShoulderRight,ElbowLeft,ElbowRight,WristLeft,WristRight,HandLeft,HandRight,Spine,HipCenter,HipLeft,HipRight,KneeLeft,KneeRight,AnkleLeft,AnkleRight,FootLeft,FootRight");
                output_print2.AddRange(TheUKI.UKI_DataDouble_convertToListString(list_data2));
                TheTool.exportCSV_orTXT(path_saveFolder + @"/" + inst.name + " 2 (MVA).csv", output_print2, false);
                TheUKI.exportKey(path_saveFolder + @"/" + inst.name + " 1 (uncombined).key", list_keyPose_preCombine);
                TheUKI.exportKey(path_saveFolder + @"/" + inst.name + " 2 (combined).key", list_keyPose_afterCombine);
            }
            return(list_keyPose_afterCombine);
        }
Ejemplo n.º 4
0
        //INPUT : raw or raw concat
        public static DataTable getDatatable_centered(List <UKI_DataRaw> list_raw, Boolean extraColumn)
        {
            List <UKI_DataRaw> list_raw_centered = TheUKI.raw_centerBodyJoint(list_raw, centerTechnique);
            DataTable          dt_raw_center     = TheUKI.convert_UKI_DataRaw_toDataTable(list_raw_centered, centerTechnique, extraColumn);//raw

            return(dt_raw_center);
        }
Ejemplo n.º 5
0
        public static void UKI_CalEntropy_Eu(String path_saveTo, String path_loadFrom, List <int[]> keyPostureRange)
        {
            List <string> final_output = new List <string>();              //Data

            final_output.Add("id," + TheUKI.getHeader_20Joint("_dist_H")); //Header
            final_output.AddRange(TheEntropy.calEntropy_MotionData(path_loadFrom, keyPostureRange, 2, 3));
            TheTool.exportCSV_orTXT(path_saveTo, final_output, false);
        }
Ejemplo n.º 6
0
 public List <UKI_DataMovement> getDataMove()
 {
     if (this.data_movement_adj.Count == 0)
     {
         UKI_Offline uki = new UKI_Offline();
         uki.UKI_OfflineProcessing(getDataRaw(true), -1);//previously use -1
         this.data_movement_adj = TheUKI.adjustMovementData(uki.data.data_movement);
     }
     return(this.data_movement_adj);
 }
Ejemplo n.º 7
0
 private void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
 {
     try
     {
         skel               = data_skel[(int)slider.Value];
         skel_centered      = TheUKI.UKI_DataRaw_centerize(skel, 3);
         txtCurrent.Content = skel.id;
         update();
     }
     catch { }
 }
Ejemplo n.º 8
0
 //load on request
 public List <UKI_DataRaw> getDataRaw(Boolean extraFeature)
 {
     if (this.data_raw.Count == 0)
     {
         this.data_raw = TheUKI.csv_loadFileTo_DataRaw(path, skip);
     }
     if (extraFeature_isAvailable == false)
     {
         TheUKI.DataRaw_AddExtraFeature(this.data_raw);
         extraFeature_isAvailable = true;
     }
     return(this.data_raw);
 }
Ejemplo n.º 9
0
 public List <keyPoseGT> getKeyPoseGT(Boolean reload)
 {
     if (keyPoseGT.Count() == 0 || reload)
     {
         string path_gt = TheTool.getDirectory_byPath(path) + @"\" + TheTool.getFileName_byPath(path) + ".gt";
         keyPoseGT = TheUKI.loadKeyPoseGT(path_gt);
     }
     if (TheUKI.captureJump && motion_id == 1)
     {
         foreach (keyPoseGT gt in keyPoseGT)
         {
             int end_avg = (gt.end[0] + gt.end[1]) / 2;
             gt.end[0] = end_avg;
             gt.end[1] = end_avg;
         }
     }
     return(this.keyPoseGT);
 }
Ejemplo n.º 10
0
 //recompute = compute even data is already exist
 public List <int[]> getKeyPose(Boolean recompute, Boolean saveData)
 {
     if (Path.GetExtension(path_key) != ThePosExtract.extension_key)
     {
         path_key = ""; this.keyPose.Clear();
     }
     if (recompute)
     {
         this.keyPose.Clear();
     }
     if (this.keyPose.Count == 0)
     {
         if (path_key == "")
         {
             path_key  = TheTool.getFilePathExcludeExtension_byPath(path) + ThePosExtract.extension_key;
             path_keyJ = TheTool.getFilePathExcludeExtension_byPath(path) + ".j";
         }
         if (recompute == false)
         {
             this.keyPose     = TheUKI.loadKeyPose(path_key);// .key is exist
             this.keyPoseJump = TheUKI.loadKeyJump(path_keyJ);
         }
         if (recompute || (this.keyPose.Count == 0 && !TheTool.checkPathExist(path_key)))
         {
             if (recompute == false && !TheTool.checkPathExist(path_key))
             {
                 TheSys.showError("Not Found: " + path_key);
             }
             this.keyPose     = ThePosExtract.extractKeyPose(this);
             this.keyPoseJump = new List <int_double>();
             this.keyPoseJump.AddRange(ThePosExtract.list_jump_selected);
             if (saveData)
             {
                 TheUKI.exportKey(path_key, keyPose);
                 if (ThePosExtract.capJumping)
                 {
                     TheUKI.exportKeyJ(path_keyJ, keyPoseJump);
                 }
             }
         }
     }
     return(keyPose);
 }
Ejemplo n.º 11
0
 private void butConvertMSRAction_Click(object sender, RoutedEventArgs e)
 {
     foreach (DataRow r in dataTable.Rows)
     {
         try
         {
             string path_origin = r[col_path].ToString();
             TheTool.Folder_CreateIfMissing(path_folder_convert);
             //-----------
             string sub_folder = path_folder_convert + "MSRAction " + TheTool.splitText(TheTool.getFileName_byPath(path_origin), "_")[0];
             TheTool.Folder_CreateIfMissing(sub_folder);
             //-----------
             string path_save = sub_folder + @"\" + TheTool.getFileName_byPath(path_origin) + ".csv";
             TheUKI.saveData_Raw(path_save, TheConverter.MSRAction_convert(path_origin));
         }
         catch (Exception ex) { TheSys.showError(r[col_path].ToString() + " : " + ex.ToString()); }
     }
     System.Windows.MessageBox.Show(@"Save to file\[Convert]\");
 }
Ejemplo n.º 12
0
 public void process01_calVariable_ver1_optional(UKI_DataRaw current_data)
 {
     cur_bendAngle   = ThePostureCal.calAngle_3D(current_data.Head, current_data.Spine, 2);
     facing_Angle    = ThePostureCal.calAngle_3D(current_data.ShoulderLeft, current_data.ShoulderRight, 2);
     diff_bend_Angle = cur_bendAngle - initial_bend_ang;
     diff_kneeL_Y    = current_data.KneeLeft[1] - initial_knee_y;
     diff_kneeR_Y    = current_data.KneeRight[1] - initial_knee_y;
     //
     diff_hL_sC_X = current_data.HandLeft[0] - current_data.ShoulderCenter[0];
     diff_hL_sC_Y = current_data.HandLeft[1] - current_data.ShoulderCenter[1];
     diff_hL_sC_Z = current_data.HandLeft[2] - current_data.ShoulderCenter[2];
     diff_hR_sC_X = current_data.HandRight[0] - current_data.ShoulderCenter[0];
     diff_hR_sC_Y = current_data.HandRight[1] - current_data.ShoulderCenter[1];
     diff_hR_sC_Z = current_data.HandRight[2] - current_data.ShoulderCenter[2];
     //Additional
     diff_fL_kL_Z = current_data.FootLeft[2] - current_data.KneeLeft[2];
     diff_fR_kR_Z = current_data.FootRight[2] - current_data.KneeRight[2];
     //
     diff_handLR_eu = TheUKI.getDist(current_data.HandLeft, current_data.HandRight);
     diff_footLR_Z  = current_data.FootLeft[2] - current_data.FootRight[2];
 }
Ejemplo n.º 13
0
 //Motion Recognition
 private void butMR_test_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         String path_RawData;
         foreach (DataRow r in dataTable.Rows)
         {
             try
             {
                 path_RawData = r[col_path].ToString();
                 string      folderName = TheTool.getFileName_byPath(path_RawData);
                 UKI_Offline mr         = new UKI_Offline();
                 mr.UKI_OfflineProcessing(TheUKI.csv_loadFileTo_DataRaw(path_RawData, 0), 1);
                 mr.data.exportFile(folderName, "UKI_", true, true, false);
             }
             catch (Exception ex) { TheSys.showError(r[col_path].ToString() + " : " + ex.ToString()); }
         }
         System.Windows.MessageBox.Show(@"Save to file", "Export Data");
     }
     catch (Exception ex) { TheSys.showError(ex); }
 }
Ejemplo n.º 14
0
        //Motion Analysis on 1 File
        //All Data (Whole Sequence) - All Motion
        //Output: Matrix
        static public string motionAnalysis(String path_load, String path_save, List <m_Motion> list_motions)
        {
            string              currentFileName = TheTool.getFileName_byPath(path_load);
            string              matrix_data     = currentFileName;
            List <UKI_DataRaw>  list_raw        = TheUKI.csv_loadFileTo_DataRaw(path_load, 0);
            List <logDetection> log_list        = new List <logDetection>();//keep output summary
            //--- Preprocess to obtain BasePosture Data
            UKI_Offline mr = new UKI_Offline();

            mr.UKI_OfflineProcessing(list_raw, 0);
            List <UKI_Data_AnalysisForm> data = TheUKI.getData_AnalysisForm(mr.data.data_raw, mr.data.data_bp);

            //--- Analysis Motion by Motion
            foreach (m_Motion motion in list_motions)
            {
                Boolean      detected = TheRuleTester.testDetectMotion(data, motion.inputs);
                logDetection log      = TheRuleTester.temp_log;
                //
                log.info = motion.name + " ( " + log.info + " )";
                if (detected)
                {
                    log.info = "[" + log.detectAt + "] " + log.info;
                }
                else
                {
                    log.info = "[X] " + log.info;
                }
                log_list.Add(log);
                matrix_data += "," + TheTool.convertBoolean_01(detected);
            }
            //--------------------------------
            TheSys.showError("File: " + currentFileName);
            foreach (logDetection s in log_list.OrderBy(o => o.detectAt).ThenBy(o => o.num_pose))
            {
                TheSys.showError(s.info);
            }
            TheSys.showError("---------------------");
            return(matrix_data);
        }
Ejemplo n.º 15
0
        private void butBrowse_Click(object sender, RoutedEventArgs e)
        {
            Nullable <bool> openDialog = TheTool.openFileDialog_01(false, ".*", "");

            if (openDialog == true && TheTool.dialog.FileNames.Count() > 0)
            {
                this.fileFullPath = TheTool.dialog.FileNames[0];
                this.fileFolder   = System.IO.Path.GetDirectoryName(fileFullPath);
                this.fileName     = TheTool.getFileName_byPath(fileFullPath);
                Title             = TheTool.getFileName_byPath(fileName);
                List <UKI_DataRaw> data = new List <UKI_DataRaw>();
                if (TheTool.getExtension_byPath(this.fileFullPath) == ".csv")
                {
                    data.AddRange(TheUKI.csv_loadFileTo_DataRaw(fileFullPath, 0));
                    if (checkFPSauto.IsChecked.Value)
                    {
                        txtFPS.Text = "20";
                    }
                }
                else if (TheTool.getExtension_byPath(this.fileFullPath) == ".bvh")
                {
                    data.AddRange(TheConverter.BVH_convert(fileFullPath));
                    TheUKI.saveData_Raw(fileFolder + @"/" + fileName + "(copy).csv", data);
                    if (checkFPSauto.IsChecked.Value)
                    {
                        txtFPS.Text = "120";
                    }
                }
                if (checkCamera.IsChecked.Value)
                {
                    data = TheUKI.UKI_DataRaw_centerize(data, 3);
                }
                loadData(data);
                txtMark.Text = "";
                mark_count   = 0;
            }
        }
Ejemplo n.º 16
0
        void analyze_combined()
        {
            try
            {
                TheSys.showError("=================================");
                string fileName        = DateTime.Now.ToString("MMdd_HHmmss");
                string path_saveFolder = path_root + "Combine " + fileName + (" (FS)");
                //
                double partition_range = TheTool.getDouble(txtPartitionRange);
                path_saveFolder += "(p=" + partition_range + ")";
                //
                TheTool.Folder_CreateIfMissing(path_saveFolder); path_saveFolder = path_saveFolder + @"\";
                //-----------------
                motionModel_reset();
                summary_total.Clear();
                summary_total.Add(fileName + " Combination");
                if (checkSegment.IsChecked == false)
                {
                    string             path_raw_centered = path_saveFolder + "Combine " + fileName + " (center" + TheUKI.getCenterTechqName(centerTechnique) + ").csv";
                    List <UKI_DataRaw> list_raw_concat   = new List <UKI_DataRaw>();
                    foreach (Instance inst in container.list_inst)
                    {
                        list_raw_concat.AddRange(inst.getDataRaw(true));
                        summary_total.Add("- " + inst.name);
                    }
                    //----- Load Data >> Build Centered Data ---------------------------------------
                    DataTable dt_raw_center = UKI_ThePreprocessor.getDatatable_centered(list_raw_concat, checkExtraFeature.IsChecked.Value);//raw
                    TheTool.export_dataTable_to_CSV(path_raw_centered, dt_raw_center);
                    //----- Process  ---------------------------------------
                    //DataTable dt_raw = CSVReader.ReadCSVFile(path_raw_centered, true);//raw
                    //
                    DataTable dt_threshold_pose1 = dt_raw_center.Clone();
                    dt_threshold_pose1.Rows.Add(dt_raw_center.Rows[0].ItemArray);
                    DataTable dt_threshold_pose2 = dt_raw_center.Clone();
                    dt_threshold_pose2.Rows.Add(dt_raw_center.Rows[dt_raw_center.Rows.Count - 1].ItemArray);

                    analyze_Table(dt_raw_center, path_saveFolder, dt_threshold_pose1, dt_threshold_pose2);
                    motionModel_exportAll(path_saveFolder, "");
                    motionModel_evaluationAll();
                    TheSys.showError(summary_total);
                    TheTool.exportFile(summary_total, path_saveFolder + "result (combined).txt", false);
                }
                else
                {
                    //Assumption: all given Instance has same class
                    List <DataTable> dt_centered_concat_list = new List <DataTable>();
                    List <DataTable> dt_threshold            = new List <DataTable>();
                    UKI_ThePreprocessor.preprocess_CombinedSegmented(container.list_inst, checkExtraFeature.IsChecked.Value, ref dt_centered_concat_list, ref dt_threshold);
                    //-----
                    summary_total.AddRange(UKI_ThePreprocessor.temp_summary);
                    int[] mode  = UKI_ThePreprocessor.temp_mode;
                    int   p_key = 0;
                    foreach (DataTable dt_1pose in dt_centered_concat_list)
                    {
                        //1 Posture of Motion
                        int    p_id                = p_key + 1;
                        string subFolder           = "Pose " + p_id;
                        string path_saveFolder_sub = path_saveFolder + @"\" + subFolder;
                        TheTool.Folder_CreateIfMissing(path_saveFolder_sub);
                        path_saveFolder_sub += @"\";
                        string path_raw_centered = path_saveFolder_sub + " Combine " + fileName + " (center" + TheUKI.getCenterTechqName(centerTechnique) + ").csv";
                        TheTool.export_dataTable_to_CSV(path_raw_centered, dt_1pose);
                        //----------
                        summary_total.Add("");
                        summary_total.Add("Pose" + p_id + ":");
                        foreach (Instance inst in container.list_inst)
                        {
                            if (inst.keyPose.Count() == mode[0])
                            {
                                summary_total.Add("- " + inst.keyPose[p_key][0]
                                                  + "-" + inst.keyPose[p_key][1]
                                                  + " of " + inst.name);
                            }
                        }
                        analyze_Table(dt_1pose, path_saveFolder_sub, dt_threshold[0], dt_threshold[p_id]);
                        p_key++;
                    }
                    motionModel_exportAll(path_saveFolder, " (segmented combined)");
                    motionModel_evaluationAll();
                    summary_total.Add("");
                    //
                    List <string> threshold_data = TheTool.dataTable_CombineShuffle_getListString(dt_threshold);
                    TheTool.exportFile(threshold_data, path_saveFolder + "threshold.csv", false);
                    //
                    TheTool.exportFile(summary_total, path_saveFolder + "result (segmented combined).txt", false);
                    TheSys.showError(summary_total);
                }
            }
            catch (Exception ex)
            {
                TheSys.showError("Combined Analysis : " + ex.ToString());
            }
        }
Ejemplo n.º 17
0
 //INPUT = All , Output = All
 void analyze_1By1()
 {
     foreach (Instance inst in container.list_inst)
     {
         //Per File (1 Whole Motion)
         try
         {
             TheSys.showError("=================================");
             string fileName        = TheTool.getFileName_byPath(inst.path);
             string path_saveFolder = path_root + fileName + (" (FS)");
             TheTool.Folder_CreateIfMissing(path_saveFolder); path_saveFolder = path_saveFolder + @"\";
             string path_raw_centered = path_saveFolder + fileName + " (center" + TheUKI.getCenterTechqName(centerTechnique) + ").csv";
             //-----------------
             motionModel_reset();
             //----- Load Data >> Build Centered Data ---------------------------------------
             DataTable dt_raw_center = UKI_ThePreprocessor.getDatatable_centered(inst.getDataRaw(checkExtraFeature.IsChecked.Value), checkExtraFeature.IsChecked.Value);//raw
             //----- Process  ---------------------------------------
             TheTool.export_dataTable_to_CSV(path_raw_centered, dt_raw_center);
             summary_total.Clear();
             summary_total.Add(fileName);
             if (checkSegment.IsChecked == false)
             {
                 DataTable dt_threshold_pose1 = dt_raw_center.Clone();
                 dt_threshold_pose1.Rows.Add(dt_raw_center.Rows[0].ItemArray);
                 DataTable dt_threshold_pose2 = dt_raw_center.Clone();
                 dt_threshold_pose2.Rows.Add(dt_raw_center.Rows[dt_raw_center.Rows.Count - 1].ItemArray);
                 analyze_Table(dt_raw_center, path_saveFolder, dt_threshold_pose1, dt_threshold_pose2);
                 motionModel_exportAll(path_saveFolder, "");
                 motionModel_evaluationAll();
                 summary_total.Add("");
                 TheSys.showError(summary_total);
                 TheTool.exportFile(summary_total, path_saveFolder + "result.txt", false);
             }
             else
             {
                 int          pose_number = 0;
                 List <int[]> key_pose    = inst.getKeyPose();
                 summary_total.Add((key_pose.Count - 1) + " Key Postures");
                 List <DataTable> dt_1pose_list      = TheTool.dataTable_split(dt_raw_center, key_pose);
                 DataTable        dt_threshold_pose1 = dt_raw_center.Clone();
                 dt_threshold_pose1.Rows.Add(dt_1pose_list.First().Rows[0].ItemArray);
                 foreach (DataTable dt_1pose in dt_1pose_list)
                 {
                     DataTable dt_threshold_pose2 = dt_raw_center.Clone();
                     dt_threshold_pose2.Rows.Add(dt_1pose.Rows[dt_1pose.Rows.Count - 1].ItemArray);
                     int    p_id  = pose_number + 1;
                     int    start = inst.keyPose[pose_number][0];
                     int    end   = inst.keyPose[pose_number][1];
                     string txt1  = "Pose" + p_id + ": " + start + "-" + end;
                     summary_total.Add("");
                     summary_total.Add(txt1);
                     //
                     string subFolder           = "Pose" + p_id + " (" + start + "-" + end + ")";
                     string path_saveFolder_sub = path_saveFolder + subFolder;
                     TheTool.Folder_CreateIfMissing(path_saveFolder_sub);
                     path_saveFolder_sub = path_saveFolder_sub + @"\";
                     //TheTool.export_dataTable_to_CSV(path_saveFolder_sub + "data.csv", dt);
                     analyze_Table(dt_1pose, path_saveFolder_sub, dt_threshold_pose1, dt_threshold_pose2);
                     pose_number++;
                 }
                 motionModel_exportAll(path_saveFolder, " (segmented)");
                 motionModel_evaluationAll();
                 summary_total.Add("");
                 TheSys.showError(summary_total);
                 TheTool.exportFile(summary_total, path_saveFolder + "result (segmented).txt", false);
             }
         }
         catch (Exception ex) { TheSys.showError(inst.path + " : " + ex.ToString()); }
     }
 }
Ejemplo n.º 18
0
        public static int[] temp_mode            = new int[2];//most occurance value

        //List<DataTable> dt_sequence : 1 DataTable = Concated Sequences of 1 Posture (For Entropy Analysis)
        //List<DataTable> dt_threshold : 1 DataTable = 1 Pose (1 Row for 1 Inst) >> List<DataTable> = Motion
        //Hadoulen #dt_sequence = 2 , #dt_threshold = 3
        //Assumption: all given Instance has same class
        public static List <DataTable> preprocess_CombinedSegmented(List <Instance> list_inst, Boolean extraColumn,
                                                                    ref List <DataTable> dt_sequence, ref List <DataTable> dt_threshold)
        {
            List <DataTable> output = new List <DataTable>();

            temp_summary.Clear();
            //-- Check Pose consist in each Instance ---------
            List <int> count_keyPose = new List <int>();

            foreach (Instance inst in list_inst)
            {
                int p_count = inst.getKeyPose().Count();
                count_keyPose.Add(p_count);
                temp_summary.Add("- " + inst.name + " : " + (p_count - 1) + " Postures");
            }
            List <int[]> occurance_counter = TheTool.listInt_countOccurance(count_keyPose);

            temp_mode = TheTool.findMode(occurance_counter); // int [ Number of Keypose , Occurance ] (Hadouken = 3)
            int key_count  = temp_mode[0];                   //(Hadouken = 3)
            int pose_count = key_count - 1;                  //(Hadouken = 2)

            temp_summary.Add("Most Common: " + pose_count + " Postures");
            //-- Build Concat DataRaw for each Posture
            if (temp_mode[1] < 1)
            {
                foreach (Instance inst in list_inst)
                {
                    TheSys.showError(inst.name + " : " + inst.getKeyPose().Count());
                }
                TheSys.showError("Cannot find Most Common Number-of-Postures");
            }
            else
            {
                //-- Prepare Concat Table
                List <UKI_DataRaw>[] list_raw_seq       = new List <UKI_DataRaw> [pose_count];
                List <UKI_DataRaw>[] list_raw_threshold = new List <UKI_DataRaw> [key_count];
                for (int i = 0; i < list_raw_seq.Count(); i++)
                {
                    list_raw_seq[i] = new List <UKI_DataRaw>();
                }
                for (int i = 0; i < list_raw_threshold.Count(); i++)
                {
                    list_raw_threshold[i] = new List <UKI_DataRaw>();
                }
                foreach (Instance inst in list_inst)
                {
                    if (inst.keyPose.Count() == temp_mode[0])
                    {
                        int key_number = 0;
                        foreach (int[] keyPose in inst.getKeyPose())
                        {
                            if (key_number > 0)
                            {
                                List <UKI_DataRaw> selectedRange = TheUKI.UKI_DataRaw_selectRow(inst.getDataRaw(extraColumn), keyPose[0], keyPose[1]);
                                list_raw_seq[key_number - 1].AddRange(selectedRange);
                                if (key_number == 1)
                                {
                                    list_raw_threshold[0].Add(selectedRange.First());
                                }
                                list_raw_threshold[key_number].Add(selectedRange.Last());
                            }
                            key_number++;
                        }
                    }
                }
                foreach (List <UKI_DataRaw> sequences in list_raw_seq)
                {
                    dt_sequence.Add(getDatatable_centered(sequences, extraColumn));
                }
                foreach (List <UKI_DataRaw> thresholds in list_raw_threshold)
                {
                    dt_threshold.Add(getDatatable_centered(thresholds, extraColumn));
                }
            }
            return(output);
        }
Ejemplo n.º 19
0
        //==============================================

        public static void BVH_convertFile(String path_origin, String path_save)
        {
            TheUKI.saveData_Raw(path_save, BVH_convert(path_origin));
        }
Ejemplo n.º 20
0
 //covert MSR to UKI format
 //MSR data http://research.microsoft.com/en-us/um/people/zliu/ActionRecoRsrc/default.htm
 public static void MSR_convertFile(String path_origin, String path_save)
 {
     try
     {
         List <string> data_origin = TheTool.read_File_getListString(path_origin);
         List <string> data_final  = new List <String>();
         data_final.Add(TheUKI.data_raw_Header);
         //-------------------------------------------------
         int joint_id = 1; Boolean skip = false;
         UKI_DataRaw_String data_raw = new UKI_DataRaw_String();
         DateTime           time_similated = DateTime.Now;//similated time
         //
         foreach (string s in data_origin.Skip(1))
         {
             if (s == "40" || s == "80")
             {
                 data_raw       = new UKI_DataRaw_String();
                 joint_id       = 1; skip = false;
                 time_similated = time_similated.AddMilliseconds(40);
             }
             else if (joint_id <= 20)
             {
                 if (skip)
                 {
                     skip = false;
                 }
                 else
                 {
                     skip = true;
                     string[] r = TheTool.splitText(s, " ");
                     if (joint_id == 1)
                     {
                         data_raw.HipCenter = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 2)
                     {
                         data_raw.Spine = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 3)
                     {
                         data_raw.ShoulderCenter = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 4)
                     {
                         data_raw.Head = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 5)
                     {
                         data_raw.ShoulderLeft = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 6)
                     {
                         data_raw.ElbowLeft = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 7)
                     {
                         data_raw.WristLeft = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 8)
                     {
                         data_raw.HandLeft = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 9)
                     {
                         data_raw.ShoulderRight = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 10)
                     {
                         data_raw.ElbowRight = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 11)
                     {
                         data_raw.WristRight = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 12)
                     {
                         data_raw.HandRight = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 13)
                     {
                         data_raw.HipLeft = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 14)
                     {
                         data_raw.KneeLeft = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 15)
                     {
                         data_raw.AnkleLeft = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 16)
                     {
                         data_raw.FootLeft = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 17)
                     {
                         data_raw.HipRight = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 18)
                     {
                         data_raw.KneeRight = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 19)
                     {
                         data_raw.AnkleRight = "," + r[0] + "," + r[1] + "," + r[2];
                     }
                     else if (joint_id == 20)
                     {
                         data_raw.FootRight = "," + r[0] + "," + r[1] + "," + r[2];
                         //
                         data_raw.id   = (data_final.Count() - 1).ToString();
                         data_raw.time = "," + time_similated.ToString("ddHHmmssff");
                         data_final.Add(TheUKI.get_UKI_DataRaw_String(data_raw));
                     }
                     joint_id++;
                 }
             }
         }
         //-------------------------------------------------
         TheTool.exportCSV_orTXT(path_save, data_final, false);
     }
     catch (Exception ex) {
         TheSys.showError(TheTool.getFileName_byPath(path_origin) + " : " + ex);
     }
 }
Ejemplo n.º 21
0
        public static Boolean testDetectMotion(List <UKI_DataRaw> data, List <m_If> list_rule_motion)
        {
            List <UKI_Data_AnalysisForm> data_forAnalysis = TheUKI.getData_AnalysisForm(data);

            return(testDetectMotion(data_forAnalysis, list_rule_motion));
        }
Ejemplo n.º 22
0
        int ang_techq    = TheUKI.angTechq_SC_HC;    //center to SC-HC
        public void exportFile(string fileName, string folderPrefix, Boolean posture_extraction, Boolean useGlobalMinMax, Boolean showDialog)
        {
            try
            {
                if (data_raw.Count() > 0)
                {
                    List <string> temp;
                    string        folderPath         = TheURL.url_saveFolder + folderPrefix + fileName;
                    string        folderPath_oth     = folderPath + @"\oth";
                    string        path_raw           = folderPath + @"\" + fileName + ".csv";
                    string        path_center_suffix = " (center" + TheUKI.getCenterTechqName(center_techq) + ")";
                    string        path_raw_centered  = folderPath + @"\" + fileName + path_center_suffix + ".csv";
                    string        path_bp            = folderPath + @"\" + fileName + " Atomic.csv";
                    string        path_log           = folderPath_oth + @"\" + fileName + " Log.csv";
                    string        path_plus          = folderPath_oth + @"\" + fileName + " Plus.csv";
                    string        path_movement      = folderPath_oth + @"\" + fileName + " Movement.csv";
                    string        path_GlobalMM      = TheURL.url_saveFolder + "[MinMax].csv";//in case Global
                    if (useGlobalMinMax == false)
                    {
                        path_GlobalMM = "";
                    }
                    TheTool.Folder_CreateIfMissing(folderPath);
                    TheTool.Folder_CreateIfMissing(folderPath_oth);
                    //--- RAW -------------------------------------------
                    TheUKI.saveData_Raw(path_raw, data_raw);
                    //--- RAW center to HipC ----------------------------
                    List <UKI_DataRaw> data_raw_centered = TheUKI.raw_centerBodyJoint(data_raw, center_techq);
                    TheUKI.saveData_Raw_centered(path_raw_centered, data_raw_centered, center_techq);
                    //--- Basic Posture ---------------------------------
                    List <string> data_bp_final = new List <string>();
                    data_bp_final.Add(TheUKI.data_bp_header());
                    data_bp_final.AddRange(TheUKI.getBasicPostureData(data_bp));
                    TheTool.exportCSV_orTXT(path_bp, data_bp_final, false);
                    //--- Log : Additional Data (Non-Analysis) ----------
                    List <string> data_log_final = new List <string>();
                    data_log_final.Add(TheUKI.data_log_header);
                    data_log_final.AddRange(data_log);
                    TheTool.exportCSV_orTXT(path_log, data_log_final, false);
                    //----- Movement Data ---------------------------
                    List <UKI_DataMovement> data_movement_adjusted = TheUKI.adjustMovementData(data_movement);
                    if (!posture_extraction)
                    {
                        TheUKI.exportData_Movement(data_movement_adjusted, path_movement, false);
                    }
                    //--- Additional Data For Analysis -----------------------
                    List <string> data_addition_full = TheUKI.createData_Additional(data_raw, data_raw_centered, data_add_01, center_techq);
                    temp = new List <string>();//data_addition_full with header
                    temp.Add(TheUKI.data_addition_full_header);
                    temp.AddRange(data_addition_full);
                    TheTool.exportCSV_orTXT(path_plus, temp, false);

                    //===================================================================
                    if (posture_extraction)
                    {
                        string folderPath_PE      = folderPath + @"\PosExtract";
                        string folderPath_Sparse  = folderPath + @"\Sparse";
                        string folderPath_Entropy = folderPath + @"\Entropy";
                        //
                        string path_note          = folderPath + @"\note.txt";
                        string path_plus_normal   = folderPath_oth + @"\" + fileName + " Plus Normal.csv";
                        string path_plus_discrete = folderPath_oth + @"\" + fileName + " Plus Descrete.csv";
                        string path_ang           = folderPath_oth + @"\" + fileName + " ANG(" + TheUKI.getAngTechqName(ang_techq) + ").csv";
                        //
                        string path_PE_raw_centered_extract = folderPath_PE + @"\" + fileName + " Extracted-01" + path_center_suffix + ".csv";
                        string path_PE_addition_extract     = folderPath_PE + @"\" + fileName + " Extracted-02 Plus.csv";
                        //
                        string path_raw_en           = folderPath_Entropy + @"\" + fileName + " Entropy-01 RAW.csv";
                        string path_raw_centered_en  = folderPath_Entropy + @"\" + fileName + " Entropy-02 RAW" + path_center_suffix + ".csv";
                        string path_plus_normal_en   = folderPath_Entropy + @"\" + fileName + " Entropy-03 Plus Normal.csv";
                        string path_plus_discrete_en = folderPath_Entropy + @"\" + fileName + " Entropy-04 Plus Discrete.csv";
                        string path_ang_en           = folderPath_Entropy + @"\" + fileName + " Entropy-11 ANG.csv";
                        string path_dist_en          = folderPath_Entropy + @"\" + fileName + " Entropy-12 Dist.csv";
                        //
                        TheTool.Folder_CreateIfMissing(folderPath_PE);
                        TheTool.Folder_CreateIfMissing(folderPath_Sparse);
                        TheTool.Folder_CreateIfMissing(folderPath_Entropy);
                        //--- Normalize & Discretize -------------------------
                        DataTable data_addition_normalized = ThePosExtract.getNormalizedTable(path_plus, path_GlobalMM, true);
                        TheTool.export_dataTable_to_CSV(path_plus_normal, data_addition_normalized);
                        DataTable data_discritized = TheTool.dataTable_discritize10Partition(data_addition_normalized);
                        TheTool.export_dataTable_to_CSV(path_plus_discrete, data_discritized);
                        //----- Angle Data ----------------------------------------
                        List <UKI_DataAngular> data_ang = TheUKI.calAngle_fromRaw(data_raw, ang_techq);
                        TheUKI.saveData_Ang(path_ang, data_ang);//save original
                        //----- (Prepare Key List) ----------------------
                        List <int[]> list_keyPose_Range = new List <int[]>();
                        list_keyPose_Range.AddRange(ThePosExtract.extractKeyPose_MyAlgo(data_movement_adjusted));
                        List <int> list_keyPose_ID = new List <int>();
                        list_keyPose_ID.AddRange(ThePosExtract.getKeyPose_ID_StartEnd(list_keyPose_Range));
                        //----- Movement Data ---------------------------
                        TheUKI.exportData_Movement(data_movement_adjusted, path_movement, true);//must be after "calMinimaMaxima"
                        //----- Basic Posture Analysis ------------------
                        List <UKI_Data_BasicPose> data_bp_selected = TheTool.list_SelectRow(data_bp, list_keyPose_ID);
                        ThePosExtract.BasicPostureAnalysis(data_bp_selected, true);
                        TheTool.exportFile(ThePosExtract.log_BasicPostureAnalysis, path_note, false);
                        TheSys.showError(ThePosExtract.log_BasicPostureAnalysis);
                        //----- Raw Extracted Data ----------------------------
                        List <UKI_DataRaw> data_raw_selected = TheTool.list_SelectRow(data_raw_centered, list_keyPose_ID);
                        TheUKI.saveData_Raw_centered(path_PE_raw_centered_extract, data_raw_selected, center_techq);
                        //----- Addition Extracted Data ----------------------------
                        List <String> data_addition_selected = TheTool.list_SelectRow(data_addition_full, list_keyPose_ID);
                        temp = new List <string>();//data_addition_full with header
                        temp.Add(TheUKI.data_addition_full_header);
                        temp.AddRange(data_addition_selected);
                        TheTool.exportCSV_orTXT(path_PE_addition_extract, temp, false);
                        //======= Feature Selecting Using Delta Analysis ==========================
                        ThePosExtract.ChangeAnalysis(path_PE_addition_extract, path_GlobalMM, folderPath_PE, fileName);
                        //======= Feature Selecting Using MI ======================================

                        //======= Entropy =========================================================
                        ThePosExtract.UKI_CalEntropy_Angle(path_ang_en, path_ang, list_keyPose_Range);
                        ThePosExtract.UKI_CalEntropy_Eu(path_dist_en, path_raw, list_keyPose_Range);
                        ThePosExtract.UKI_CalEntropy_1By1(path_raw_en, path_raw, list_keyPose_Range);
                        ThePosExtract.UKI_CalEntropy_1By1(path_raw_centered_en, path_raw_centered, list_keyPose_Range);
                        ThePosExtract.UKI_CalEntropy_1By1(path_plus_normal_en, path_plus_normal, list_keyPose_Range);
                        ThePosExtract.UKI_CalEntropy_1By1(path_plus_discrete_en, path_plus_discrete, list_keyPose_Range);
                        //======= Oth =========================================================
                        //---- Paper : Sparse ---------------------
                        CalSparse_XYZ.calSparse(data_raw_selected, folderPath_Sparse + @"\", fileName);//cal & export
                    }
                    if (showDialog)
                    {
                        System.Windows.MessageBox.Show(@"Save to '" + folderPath + "'", "Export Data");
                    }
                }
            }
            catch (Exception ex) { TheSys.showError("Export: " + ex); }
        }
Ejemplo n.º 23
0
        private void butUKIconvert_Click(object sender, RoutedEventArgs e)
        {
            String fileName;
            String path_raw;
            String path_raw_centered;
            String path_ang;
            String path_ang_en;
            String path_raw_en;
            String path_dist_en;
            int    ang_techq    = comboAngTech.SelectedIndex;   //center of angle
            int    center_techq = comboRawCenter.SelectedIndex; //center of body position

            foreach (DataRow r in dataTable.Rows)
            {
                path_raw = r[col_path].ToString();
                fileName = TheTool.getFileName_byPath(path_raw);
                TheTool.Folder_CreateIfMissing(path_folder_convert + fileName);
                String path_sub_folder = path_folder_convert + fileName + @"\";
                path_raw_centered = path_sub_folder + fileName + " (center" + TheUKI.getCenterTechqName(center_techq) + ").csv";
                path_ang          = path_sub_folder + fileName + " ANG(" + TheUKI.getAngTechqName(ang_techq) + ").csv";
                path_ang_en       = path_sub_folder + fileName + " ANG_Entropy.csv";
                path_raw_en       = path_sub_folder + fileName + " RAW_Entropy.csv";
                path_dist_en      = path_sub_folder + fileName + " Dist_Entropy.csv";
                if (center_techq > 0)
                {
                    path_raw_en = path_sub_folder + fileName +
                                  " (center" + TheUKI.getCenterTechqName(center_techq) + ") RAW_Entropy.csv";
                }
                //----- Raw -----
                List <UKI_DataRaw> list_raw = TheUKI.csv_loadFileTo_DataRaw(path_raw, 0);
                //----- Angle ---------
                List <UKI_DataAngular> list_ang = TheUKI.calAngle_fromRaw(list_raw, ang_techq);
                if (checkUKI_Angle.IsChecked.Value || checkUKI_E_Angle.IsChecked.Value)
                {
                    TheUKI.saveData_Ang(path_ang, list_ang);
                }
                //---------------------
                //List<int> keyPostureId = UKI_getKeyPostureId();
                List <int[]> keyPostureRange = ThePosExtract.getKetPose_Range_from1String(txtUKI_keyID.Text);
                //----- Angle Entropy ---------
                if (checkUKI_E_Angle.IsChecked.Value)
                {
                    ThePosExtract.UKI_CalEntropy_Angle(path_ang_en, path_ang, keyPostureRange);
                }
                //----- Dist ---------
                if (checkUKI_E_Dist.IsChecked.Value)
                {
                    ThePosExtract.UKI_CalEntropy_Eu(path_dist_en, path_raw, keyPostureRange);
                }
                //----- XYZ Entropy ---------
                if (checkUKI_E_XYZ.IsChecked.Value)
                {
                    if (center_techq > 0)
                    {
                        List <UKI_DataRaw> list_raw_centered = TheUKI.raw_centerBodyJoint(list_raw, center_techq);
                        TheUKI.saveData_Raw_centered(path_raw_centered, list_raw_centered, center_techq);
                        ThePosExtract.UKI_CalEntropy_1By1(path_raw_en, path_raw_centered, keyPostureRange);
                    }
                    else
                    {
                        ThePosExtract.UKI_CalEntropy_1By1(path_raw_en, path_raw, keyPostureRange);
                    }
                }
            }
            System.Windows.MessageBox.Show(@"Save to file\[Convert]");
        }