예제 #1
0
        public static string getAOIsofFile_OpenFace(Constants.FilesForAOIDetection filesforAOIDetection, ImageConversion imageConversion)
        {
            string line_features, line_raw_data;

            char[] delimiterChars = { ' ', '\t', ',' };

            string[] words_features;
            int      frame_num, success;

            string[] words_eye_tracker_generated_file;
            string   fixation_type = "", raw_x = "", raw_y = "";
            int      frame_num_raw_data = 0;

            string AOIs            = "";
            string writeToFile_str = "";


            if (filesforAOIDetection.file_2d_landmarks != null)
            {
                filesforAOIDetection.file_2d_landmarks.ReadLine(); //skip header row,
            }
            while ((line_features = filesforAOIDetection.file_2d_landmarks.ReadLine()) != null)
            {
                words_features = line_features.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
                frame_num      = Convert.ToInt32(words_features[0]);

                line_raw_data = filesforAOIDetection.file_gaze_raw_data.ReadLine();


                Dictionary <int, string> manually_tracked_dict = null;
                string letter = "";
                if (!String.IsNullOrEmpty(filesforAOIDetection.file_manuallyLabelledAOIs_path) && !String.IsNullOrWhiteSpace(filesforAOIDetection.file_manuallyLabelledAOIs_path))
                {
                    string[] manually_tracked_lines = File.ReadAllLines(filesforAOIDetection.file_manuallyLabelledAOIs_path);

                    manually_tracked_dict = new Dictionary <int, string>();
                    foreach (string line in manually_tracked_lines)
                    {
                        if (!String.IsNullOrEmpty(line) && !String.IsNullOrWhiteSpace(line))
                        {
                            int frameNo = Convert.ToInt32(line.Split(' ')[0]);
                            letter = line.Split(' ')[1];
                            UtilityFunctions.addOrUpdateDictionary(manually_tracked_dict, frameNo, letter);
                        }
                    }
                }

                bool         gaze_raw_data_empty = false, face_detection_empty = false;
                List <Point> face = new List <Point>();
                List <Point> nose_rect  = new List <Point>();
                List <Point> eye_rect   = new List <Point>();
                List <Point> mouth_rect = new List <Point>();
                if (line_raw_data != null)
                {
                    words_eye_tracker_generated_file = line_raw_data.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);

                    frame_num_raw_data = Convert.ToInt32(words_eye_tracker_generated_file[0]);
                    while (frame_num_raw_data > frame_num)
                    {
                        writeToFile_str += frame_num + " " + "\n";
                        line_features    = filesforAOIDetection.file_2d_landmarks.ReadLine();
                        words_features   = line_features.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
                        frame_num        = Convert.ToInt32(words_features[0]);
                    }
                    if (frame_num != frame_num_raw_data)
                    {
                        throw new Exception("There is a problem in the size of 2dLandmarks file and eye tracker generated raw gaze data file. Please be sure you import the accurate files!!");
                    }

                    fixation_type       = words_eye_tracker_generated_file[1];
                    success             = Convert.ToInt32(words_features[3]);
                    gaze_raw_data_empty = false; face_detection_empty = false;
                    if ((fixation_type == Constants.EyeTrackerNotEmptyLineTxt))
                    {
                        raw_x = words_eye_tracker_generated_file[2];
                        raw_y = words_eye_tracker_generated_file[3];
                    }
                    else
                    {
                        gaze_raw_data_empty = true;
                    }

                    int total_num_of_empy = 0;
                    for (int i = 4; i < 31; i++)
                    {
                        face.Add(new Point((int)Convert.ToDouble(words_features[i]), (int)Convert.ToDouble(words_features[i + 68])));

                        if ((int)Convert.ToDouble(words_features[i + 68]) == 0 && (int)Convert.ToDouble(words_features[i]) == 0)
                        {
                            total_num_of_empy++;
                        }
                    }

                    if (total_num_of_empy >= 4)
                    {
                        face_detection_empty = true;
                    }
                }

                bool addedtoAOIsFrame = false;
                if (manually_tracked_dict != null && manually_tracked_dict.Count > 0 && manually_tracked_dict.TryGetValue(frame_num, out letter)) //manualy tracked value override face tracking outcomes
                {
                    if (letter.Equals("NULL"))                                                                                                    //while manual tracking, when user does not decide what is the appropriate AOI to assign, s/he press 0  and it assign Null to the related frame, most probably because of the empty gaze row data
                    {
                        string newAOIs = "";
                        newAOIs = assignTheProblematicIssueLabel(frame_num, AOIs, gaze_raw_data_empty, face_detection_empty);
                        if (String.IsNullOrEmpty(newAOIs)) //sometimes if we assign null while manually track, but actually, there was no face detection issue or gaze raw data empty problem, assignTheProblematicIssueLabel do not add new line to the AOIs, for this cases it is necessary to add related frame AOI, based on detected face and raw gaze data.
                        {
                            addedtoAOIsFrame = false;
                        }
                        else
                        {
                            AOIs             = newAOIs;
                            addedtoAOIsFrame = true;
                        }
                    }

                    else
                    {
                        AOIs            += frame_num + " " + letter + "\n";
                        addedtoAOIsFrame = true;
                    }
                }
                if (!addedtoAOIsFrame && line_raw_data != null)
                {
                    if (!gaze_raw_data_empty && !face_detection_empty)
                    {
                        //face_rect
                        eye_rect.Add(new Point((int)Convert.ToDouble(words_features[4]), (int)Convert.ToDouble(words_features[4 + 68])));
                        eye_rect.Add(new Point((int)Convert.ToDouble(words_features[20]), (int)Convert.ToDouble(words_features[20 + 68])));
                        nose_rect.Add(new Point((int)Convert.ToDouble(words_features[5]), (int)Convert.ToDouble(words_features[5 + 68])));
                        nose_rect.Add(new Point((int)Convert.ToDouble(words_features[6]), (int)Convert.ToDouble(words_features[6 + 68])));
                        nose_rect.Add(new Point((int)Convert.ToDouble(words_features[19]), (int)Convert.ToDouble(words_features[19 + 68])));
                        nose_rect.Add(new Point((int)Convert.ToDouble(words_features[18]), (int)Convert.ToDouble(words_features[18 + 68])));

                        for (int i = 8; i < 19; i++)
                        {
                            mouth_rect.Add(new Point((int)Convert.ToDouble(words_features[i]), (int)Convert.ToDouble(words_features[i + 68])));
                        }

                        for (int i = 21; i < 31; i++)
                        {
                            eye_rect.Add(new Point((int)Convert.ToDouble(words_features[i]), (int)Convert.ToDouble(words_features[i + 68])));
                        }
                        for (int i = 31; i < 40; i++)
                        {
                            if (i == 31 || i == 32)
                            {
                                eye_rect.Add(new Point((int)Convert.ToDouble(words_features[i]), (int)Convert.ToDouble(words_features[i + 68])));
                            }
                            else
                            {
                                nose_rect.Add(new Point((int)Convert.ToDouble(words_features[i]), (int)Convert.ToDouble(words_features[i + 68])));
                            }
                        }
                        for (int i = 40; i < 46; i++)
                        {
                            eye_rect.Add(new Point((int)Convert.ToDouble(words_features[i]), (int)Convert.ToDouble(words_features[i + 68])));
                        }
                        for (int i = 46; i < 52; i++)
                        {
                            eye_rect.Add(new Point((int)Convert.ToDouble(words_features[i]), (int)Convert.ToDouble(words_features[i + 68])));
                        }
                        for (int i = 52; i < 72; i++)
                        {
                            mouth_rect.Add(new Point((int)Convert.ToDouble(words_features[i]), (int)Convert.ToDouble(words_features[i + 68])));
                        }



                        Dictionary <string, List <Point> > allFeaturePointLists = new Dictionary <string, List <Point> >();

                        allFeaturePointLists.Add(Constants.face, face);
                        allFeaturePointLists.Add(Constants.nose_rect, nose_rect);
                        allFeaturePointLists.Add(Constants.eye_rect, eye_rect);
                        allFeaturePointLists.Add(Constants.mouth_rect, mouth_rect);


                        string AOI = UtilityFunctions.determineAOIForFeatures(raw_x, raw_y, allFeaturePointLists, imageConversion);
                        AOIs += frame_num + " " + AOI + "\n";
                    }

                    else
                    {
                        AOIs = assignTheProblematicIssueLabel(frame_num, AOIs, gaze_raw_data_empty, face_detection_empty);
                    }
                }
            }

            return(AOIs);
        }
예제 #2
0
 private void btnDown_Click(object sender, EventArgs e)
 {
     UtilityFunctions.MoveDown(controls.lb_speechAct);
 }
        public void btn_save_resegment_determine_interval_multiple(object sender, EventArgs e)
        {
            try
            {
                bool   validationError = false;
                int    id;
                string initialSegment_pair1, initialSegment_pair2, lastSegment_pair1, lastSegment_pair2;
                validationError = validation_MultipleFiles(out id, out initialSegment_pair1, out initialSegment_pair2, out lastSegment_pair1, out lastSegment_pair2);

                validationError = validationResegmentFields(validationError);

                if (validationError)
                {
                    return;
                }

                else
                {
                    if (controls.rbOptionFirstParticipant_determine_interval_resegment.Checked)
                    {
                        Constants.base_file_path            = controls.txt_interval_determine_interval_multiple_1.Text;
                        Constants.ref_file_path             = controls.txt_interval_determine_interval_multiple_2.Text;
                        Constants.starting_segment_num_base = controls.txt_starting_number_determine_interval_multiple_1.Text;
                        Constants.starting_segment_num_ref  = controls.txt_starting_number_determine_interval_multiple_2.Text;
                        Constants.ending_segment_num_base   = controls.txt_final_number_determine_interval_multiple_1.Text;
                        Constants.ending_segment_num_ref    = controls.txt_final_number_determine_interval_multiple_2.Text;
                    }
                    else if (controls.rbOptionSecondParticipant_determine_interval_resegment.Checked)
                    {
                        Constants.base_file_path            = controls.txt_interval_determine_interval_multiple_2.Text;
                        Constants.ref_file_path             = controls.txt_interval_determine_interval_multiple_1.Text;
                        Constants.starting_segment_num_base = controls.txt_starting_number_determine_interval_multiple_2.Text;
                        Constants.starting_segment_num_ref  = controls.txt_starting_number_determine_interval_multiple_1.Text;
                        Constants.ending_segment_num_base   = controls.txt_final_number_determine_interval_multiple_2.Text;
                        Constants.ending_segment_num_ref    = controls.txt_final_number_determine_interval_multiple_1.Text;
                    }


                    Constants.output_path_resegment = controls.txt_outputFolder_resegment.Text;
                    Constants.ExpIntervalofPair expIntervals = findSegmentsWithUtilizingSynchInfo();
                    string path_resegmented = Constants.output_path_resegment + "\\segments_interval.txt"; //resegmented file path created in findSegmentsWithUtilizingSynchInfo call

                    bool   createOutputFile = false;
                    string output_path      = controls.txt_outputFile_determine_interval.Text;
                    if (!File.Exists(output_path))
                    {
                        createOutputFile = true;
                    }

                    output_expInterval(id, expIntervals, createOutputFile, output_path);


                    string fileName = controls.txt_resegment_file.Text;
                    string _javadir = UtilityFunctions.LocateJava();

                    ProcessStartInfo start = new ProcessStartInfo();
                    if (!_javadir.Equals(String.Empty))
                    {
                        start.FileName = _javadir + "java.exe";
                    }
                    else
                    {
                        start.FileName = "java.exe";
                    }

                    start.Arguments = "-cp " + Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\speech_analysis\\Sphinx4Files\\sphinx4-core-all-1.0.jar edu.cmu.sphinx.tools.endpoint.Segmenter -i " + fileName + " -o " + controls.txt_outputFolder_resegment.Text + "\\ -comb " + path_resegmented;

                    start.UseShellExecute        = false;
                    start.RedirectStandardInput  = true;
                    start.RedirectStandardOutput = true;

                    //Start the Process
                    Process java = new Process();
                    java.StartInfo = start;
                    bool isStarted = java.Start();
                    java.WaitForExit();
                    int exitCode = java.ExitCode;
                    java.Close();
                    if (exitCode == 1)
                    {
                        MessageBox.Show("Java error thrown, please be sure to pre-request wriiten in walkthrough to run java.");
                    }
                    else
                    {
                        MessageBox.Show("Succesfully done!!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please be sure the files exist!!");
            }
        }
        public void btn_save_determine_interval_single(object sender, EventArgs e)
        {
            bool validationError = false;

            if (String.IsNullOrEmpty(controls.txt_outputFile_determine_interval.Text) || String.IsNullOrWhiteSpace(controls.txt_outputFile_determine_interval.Text))
            {
                controls.errorProvider_outputFile_interval.SetError(controls.txt_outputFile_determine_interval, Constants.MESSAGE_SELECT_OUTPUT_FOLDER);
                validationError = true;
            }
            else
            {
                controls.errorProvider_outputFile_interval.Clear();
                controls.errorProvider_outputFile_interval.SetError(controls.txt_outputFile_determine_interval, "");
            }

            if (String.IsNullOrEmpty(controls.txt_interval_determine_interval_single.Text) || String.IsNullOrWhiteSpace(controls.txt_interval_determine_interval_single.Text))
            {
                controls.errorProvider_segmentsIntervalFile_single.SetError(controls.txt_interval_determine_interval_single, Constants.MESSAGE_SELECT_SEGMENTS_INTERVAL_FILE);
                validationError = true;
            }
            else
            {
                controls.errorProvider_segmentsIntervalFile_single.Clear();
                controls.errorProvider_segmentsIntervalFile_single.SetError(controls.txt_interval_determine_interval_single, "");
            }

            int id = 0;

            if (String.IsNullOrEmpty(controls.txt_id_determine_interval_single.Text) || String.IsNullOrWhiteSpace(controls.txt_id_determine_interval_single.Text) ||
                (!int.TryParse(controls.txt_id_determine_interval_single.Text, out id)))
            {
                controls.errorProvider_id_single.SetError(controls.txt_id_determine_interval_single, Constants.MESSAGE_ENTER_POSITIVE_INTEGER_VALUE);
                validationError = true;
            }
            else
            {
                controls.errorProvider_id_single.Clear();
                controls.errorProvider_id_single.SetError(controls.txt_id_determine_interval_single, "");
            }

            string initialSegment  = controls.txt_starting_number_determine_interval_single.Text;
            int    initial_segment = 0;

            if (String.IsNullOrEmpty(initialSegment) || String.IsNullOrWhiteSpace(initialSegment) ||
                (!int.TryParse(initialSegment, out initial_segment)))
            {
                controls.errorProvider_starting_segment_single.SetError(controls.txt_starting_number_determine_interval_single, Constants.MESSAGE_ENTER_POSITIVE_INTEGER_VALUE);
                validationError = true;
            }
            else
            {
                controls.errorProvider_starting_segment_single.Clear();
                controls.errorProvider_starting_segment_single.SetError(controls.txt_starting_number_determine_interval_single, "");
            }

            int    last_segment = 0;
            string lastSegment  = controls.txt_final_number_determine_interval_single.Text;

            if (String.IsNullOrEmpty(lastSegment) || String.IsNullOrWhiteSpace(lastSegment) ||
                (!int.TryParse(lastSegment, out last_segment)))
            {
                controls.errorProvider_final_segment_single.SetError(controls.txt_final_number_determine_interval_single, Constants.MESSAGE_ENTER_POSITIVE_INTEGER_VALUE);
                validationError = true;
            }
            else
            {
                controls.errorProvider_final_segment_single.Clear();
                controls.errorProvider_final_segment_single.SetError(controls.txt_final_number_determine_interval_single, "");
            }

            if (last_segment < initial_segment)
            {
                controls.errorProvider_segmentsIntervalFile_single.SetError(controls.txt_final_number_determine_interval_single, Constants.MESSAGE_ENTER_GREATER_VALUE);
                validationError = true;
            }
            if (validationError)
            {
                return;
            }

            else
            {
                string   segmented_file_path = controls.txt_interval_determine_interval_single.Text;
                string[] segmentedAudios;

                char[] delimeters = new char[] { ' ', '\t' };
                string starting_time = "", ending_time = "";
                if (File.Exists(segmented_file_path))
                {
                    segmentedAudios = File.ReadAllLines(segmented_file_path);
                    Dictionary <string, string> dict   = new Dictionary <string, string>();
                    List <String> strSegmentsInsideExp = new List <String>();

                    foreach (String line in segmentedAudios)
                    {
                        if (String.IsNullOrEmpty(line) || String.IsNullOrWhiteSpace(line) || line.Trim(new[] { ' ', '\t', '\n' }).Length <= 0)
                        {
                            continue;
                        }

                        //order of if statements should not be changed.
                        if (!String.IsNullOrEmpty(starting_time) && !String.IsNullOrWhiteSpace(starting_time))
                        {
                            strSegmentsInsideExp.Add(line);
                        }


                        if (line.Split(delimeters, StringSplitOptions.RemoveEmptyEntries)[0].Equals(initialSegment))
                        {
                            starting_time = line.Split(delimeters, StringSplitOptions.RemoveEmptyEntries)[2];
                        }
                        if (line.Split(delimeters, StringSplitOptions.RemoveEmptyEntries)[0].Equals(lastSegment))
                        {
                            ending_time = line.Split(delimeters, StringSplitOptions.RemoveEmptyEntries)[2];
                            break;
                        }
                    }

                    using (StreamWriter newTask = new StreamWriter(segmented_file_path, false))
                    {
                        foreach (string line_s in strSegmentsInsideExp)
                        {
                            int      newID     = 0;
                            string[] lineItems = line_s.Split(delimeters, StringSplitOptions.RemoveEmptyEntries);
                            if (line_s.Split(delimeters, StringSplitOptions.RemoveEmptyEntries)[0] != null)
                            {
                                newID = Convert.ToInt32(lineItems[0]) - Convert.ToInt32(initialSegment) - 1;
                            }

                            string line_changed = newID.ToString() + "		"+ lineItems[1] + " " + lineItems[2] + " " + lineItems[3];
                            newTask.WriteLine(line_changed);
                        }
                    }

                    UtilityFunctions.FixAllAudioNamesAccordingToExpInterval(Path.GetDirectoryName(segmented_file_path), Convert.ToInt32(initialSegment), Convert.ToInt32(lastSegment));



                    bool   createOutputFile = false;
                    string output_path      = controls.txt_outputFile_determine_interval.Text;
                    if (!File.Exists(output_path))
                    {
                        createOutputFile = true;
                    }
                    if (createOutputFile)
                    {
                        string[] lines = { "#id #StartingTime #EndingTime", id + " " + starting_time + " " + ending_time };

                        System.IO.File.WriteAllLines(output_path, lines);
                    }
                    else
                    {
                        string[] starting_ending_time_file           = File.ReadAllLines(output_path);
                        Dictionary <string, string> dict_output_file = new Dictionary <string, string>();
                        string writeToFile = "";
                        foreach (String line in starting_ending_time_file)
                        {
                            string line_to_write = line;
                            if (line.Contains('#')) //header
                            {
                                continue;
                            }
                            else if (String.IsNullOrEmpty(line) || String.IsNullOrWhiteSpace(line) || line.Trim(new[] { ' ', '\t', '\n' }).Length <= 0)
                            {
                                continue;
                            }
                            else if (line.Split(delimeters)[0].Equals(id))
                            {
                                line_to_write = id + " " + starting_time + " " + ending_time;
                            }

                            writeToFile += line_to_write + "\n";
                        }
                        System.IO.File.WriteAllText(output_path, writeToFile);
                    }


                    MessageBox.Show("Succesfully done!!");
                }
            }
        }
예제 #5
0
        public void btn_segment_Click(object sender, EventArgs e)
        {
            bool error = false;

            if (String.IsNullOrEmpty(controls.txt_outputFolder_segment.Text) || String.IsNullOrWhiteSpace(controls.txt_outputFolder_segment.Text))
            {
                controls.errorProvider_segment_outputFolder.SetError(controls.txt_outputFolder_segment, Constants.MESSAGE_SELECT_OUTPUT_FOLDER);
                error = true;
            }
            else
            {
                controls.errorProvider_segment_outputFolder.Clear();
                controls.errorProvider_segment_outputFolder.SetError(controls.txt_outputFolder_segment, "");
            }

            string fileName = "";

            fileName = controls.txt_wavFile_segment.Text;
            if (String.IsNullOrEmpty(fileName) || String.IsNullOrWhiteSpace(fileName))
            {
                controls.errorProvider_segment_wavFile.SetError(controls.txt_wavFile_segment, Constants.MESSAGE_SELECT_WAV_FILE);
                error = true;
            }
            else
            {
                controls.errorProvider_segment_wavFile.Clear();
                controls.errorProvider_segment_wavFile.SetError(controls.txt_wavFile_segment, "");
            }
            if (error)
            {
                return;
            }

            string           _javadir = UtilityFunctions.LocateJava();
            ProcessStartInfo start    = new ProcessStartInfo();

            if (!_javadir.Equals(String.Empty))
            {
                start.FileName = _javadir + "java.exe";
            }
            else
            {
                start.FileName = "java.exe";
            }
            start.Arguments              = "-cp " + Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\speech_analysis\\Sphinx4Files\\sphinx4-core-all-1.0.jar edu.cmu.sphinx.tools.endpoint.Segmenter -i " + fileName + " -o " + controls.txt_outputFolder_segment.Text + "\\ -a " + controls.txt_outputFolder_segment.Text + "\\";
            start.UseShellExecute        = false;
            start.RedirectStandardInput  = true;
            start.RedirectStandardOutput = true;

            //Start the Process
            Process java = new Process();

            java.StartInfo = start;
            java.Start();
            java.WaitForExit();
            int exitCode = java.ExitCode;

            java.Close();

            MessageBox.Show("Succesfully segmented!!");
        }
예제 #6
0
        private List <string> fillDictionaries(ref Dictionary <int, string> dict_speech_annotation, ref Dictionary <int, string> dict_base_AOI, ref Dictionary <int, string> dict_ref_AOI)
        {
            try
            {
                List <string> starting_endingFrames = new List <string>();
                char[]        delimiterChars        = { ' ', '\t' };
                string[]      words_speech_annotation;
                string        line_sa = "", starting_time_str = "", ending_time_str = "", extended_speech_act = "";
                int           interval_pair_1_starting = 0, interval_pair_1_ending = 0, interval_pair_2_starting = 0, interval_pair_2_ending = 0, starting_time = 0,
                              ending_time = 0, time_offset_between_participants = 0, starting_frameNo = 0, ending_frameNo = 0;



                System.IO.StreamReader file_speechAnnotation = new System.IO.StreamReader(fileName_speechAnnotation);

                System.IO.StreamReader file_base = null, file_ref = null;

                Constants.ParticipantInfo participantInfo = Constants.ParticipantInfo.First;
                UtilityFunctions.findStartingEndingFrameNo(fileName_expInterval, id, participantInfo, frequency, ref interval_pair_1_starting, ref interval_pair_1_ending);

                if (dict_ref_AOI != null)
                {
                    participantInfo = Constants.ParticipantInfo.Second;
                    UtilityFunctions.findStartingEndingFrameNo(fileName_expInterval, id, participantInfo, frequency, ref interval_pair_2_starting, ref interval_pair_2_ending);
                }



                //set starting ending frame values
                if (dict_ref_AOI != null)
                {
                    starting_endingFrames.Add(interval_pair_1_starting + " " + interval_pair_1_ending);
                    starting_endingFrames.Add(interval_pair_2_starting + " " + interval_pair_2_ending);
                }
                else//if a single participant selected
                {
                    starting_endingFrames.Add(interval_pair_1_starting + " " + interval_pair_1_ending);
                }


                bool firstLine = true;
                while ((line_sa = file_speechAnnotation.ReadLine()) != null)
                {
                    words_speech_annotation = line_sa.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
                    if (words_speech_annotation.Count() <= 3)
                    {
                        continue;
                    }

                    starting_time_str = words_speech_annotation[0];
                    starting_time     = Convert.ToInt32(starting_time_str);

                    ending_time_str = words_speech_annotation[1];
                    ending_time     = Convert.ToInt32(ending_time_str);

                    extended_speech_act = words_speech_annotation[2] + " ";
                    for (int i = 3; i < words_speech_annotation.Length; i++)
                    {
                        extended_speech_act += words_speech_annotation[i];
                    }


                    if (firstLine & dict_ref_AOI != null)
                    {
                        if (UtilityFunctions.convertMilliSecondToEyeTrackerFrameNo(frequency, starting_time) == interval_pair_1_starting)
                        {
                            file_base = new System.IO.StreamReader(fileName_AOI_file_summary_first_pair);
                            file_ref  = new System.IO.StreamReader(fileName_AOI_file_summary_second_pair);
                            time_offset_between_participants = interval_pair_1_starting - interval_pair_2_starting;
                            baseisFirst = true;
                        }
                        else
                        {
                            file_base = new System.IO.StreamReader(fileName_AOI_file_summary_second_pair);
                            file_ref  = new System.IO.StreamReader(fileName_AOI_file_summary_first_pair);
                            time_offset_between_participants = interval_pair_2_starting - interval_pair_1_starting;
                            baseisFirst = false;
                        }

                        //diff_timeOffset_frameNo = UtilityFunctions.convertMilliSecondToEyeTrackerFrameNo(frequency, time_offset_between_participants);
                        diff_timeOffset_frameNo = time_offset_between_participants;
                        dict_base_AOI           = fill_AOI_dict(file_base);
                        dict_ref_AOI            = fill_AOI_dict(file_ref);

                        firstLine = false;
                    }
                    else if (firstLine & dict_ref_AOI == null)
                    {
                        file_base     = new System.IO.StreamReader(fileName_AOI_file_summary_single);
                        dict_base_AOI = fill_AOI_dict(file_base);
                    }

                    //when calculate ending frame by converting ending millisecond value to frame number as in finding the starting frame number case, it might cause different number of frame numbers in a pair, because of conversion issues.
                    //thus ending frame number is calculated based on difference value which is absolutely same in a pair.
                    starting_frameNo = UtilityFunctions.convertnextMilliSecondToEyeTrackerFrameNo(frequency, starting_time_str);
                    ending_frameNo   = starting_frameNo + UtilityFunctions.convertMilliSecondToEyeTrackerFrameNo(frequency, ending_time - starting_time) - 1;



                    for (int i = starting_frameNo; i <= ending_frameNo; i++)
                    {
                        string val;

                        if (dict_speech_annotation.TryGetValue(i, out val))
                        {
                            // yay, value exists!
                            string[] outputLine_words = val.Split(delimiterChars);

                            string updatedLine = "";


                            string actor = outputLine_words[0];
                            //string speech_act = outputLine_words[1];
                            string speech_act = "";
                            for (int index = 1; index < outputLine_words.Length; index++)
                            {
                                speech_act += (i == 1 ? "" : " ") + outputLine_words[index];
                            }


                            string actor_newline = words_speech_annotation[2];
                            //string speech_act_newline = words_speech_annotation[3];
                            string speech_act_newline = "";
                            for (int index = 3; index < words_speech_annotation.Length; index++)
                            {
                                //speech_act_newline += (i==3?"":" ")+words_speech_annotation[index];
                                speech_act_newline += words_speech_annotation[index]; //remove spaces inside speechAct, as did we before
                            }


                            if (!actor.Contains(actor_newline))
                            {
                                updatedLine += actor + "," + actor_newline + " ";
                            }
                            else
                            {
                                updatedLine += actor_newline + " ";
                            }

                            if (!speech_act.Contains(speech_act_newline))
                            {
                                updatedLine += speech_act + "," + speech_act_newline;
                            }
                            else
                            {
                                updatedLine += speech_act_newline;
                            }

                            dict_speech_annotation[i] = updatedLine;
                        }
                        else
                        {
                            dict_speech_annotation[i] = extended_speech_act;
                        }
                    }
                }
                return(starting_endingFrames);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #7
0
        private void btn_analyse_faceAsROI_Click(object sender, EventArgs e)
        {
            bool   errror         = false;
            string outputFileName = controls.txt_outputFile_faceAsROI.Text;

            if (String.IsNullOrEmpty(outputFileName) || String.IsNullOrWhiteSpace(outputFileName))
            {
                controls.errorProvider_outputFile_faceAsROI.SetError(controls.txt_outputFile_faceAsROI, Constants.MESSAGE_SELECT_OUTPUT_FILE);
                errror = true;
            }
            else
            {
                controls.errorProvider_outputFile_faceAsROI.Clear();
                controls.errorProvider_outputFile_faceAsROI.SetError(controls.txt_outputFile_faceAsROI, "");
            }

            string rawGazeDataFileName = controls.txt_rawGazeDataFile_faceAsROI.Text;

            if (String.IsNullOrEmpty(rawGazeDataFileName) || String.IsNullOrWhiteSpace(rawGazeDataFileName) || !File.Exists(rawGazeDataFileName))
            {
                controls.errorProvider_rawGazeDataFile_faceAsROI.SetError(controls.txt_rawGazeDataFile_faceAsROI, Constants.MESSAGE_SELECT_RAW_GAZE_DATA_FILE);
                errror = true;
            }
            else
            {
                controls.errorProvider_rawGazeDataFile_faceAsROI.Clear();
                controls.errorProvider_rawGazeDataFile_faceAsROI.SetError(controls.txt_rawGazeDataFile_faceAsROI, "");
            }

            string landmarkFileName = controls.txt_2dlandmark_faceAsROI.Text;

            if (String.IsNullOrEmpty(landmarkFileName) || String.IsNullOrWhiteSpace(landmarkFileName) || !File.Exists(landmarkFileName))
            {
                controls.errorProvider_2dlandmark_faceAsROI.SetError(controls.txt_2dlandmark_faceAsROI, Constants.MESSAGE_SELECT_2dLANDMARK_FILE);
                errror = true;
            }
            else
            {
                controls.errorProvider_2dlandmark_faceAsROI.Clear();
                controls.errorProvider_2dlandmark_faceAsROI.SetError(controls.txt_2dlandmark_faceAsROI, "");
            }

            string imageSizeTrackingFrameworkFileName = controls.txt_imageSizeTrakingFramework_faceAsROI.Text;

            if (String.IsNullOrEmpty(imageSizeTrackingFrameworkFileName) || String.IsNullOrWhiteSpace(imageSizeTrackingFrameworkFileName) || !File.Exists(imageSizeTrackingFrameworkFileName))
            {
                controls.errorProvider_imageSizeTrakingFramework_faceAsROI.SetError(controls.txt_imageSizeTrakingFramework_faceAsROI, Constants.MESSAGE_SELECT_IMAGE_SIZE_TRACKING_FRAMEWORK_FILE);
                errror = true;
            }
            else
            {
                controls.errorProvider_imageSizeTrakingFramework_faceAsROI.Clear();
                controls.errorProvider_imageSizeTrakingFramework_faceAsROI.SetError(controls.txt_imageSizeTrakingFramework_faceAsROI, "");
            }

            string eyetrackerImageWidth = controls.txt_imageSizeEyeTrackerWidth_faceAsROI.Text;
            string eyetrackerImageHeight = controls.txt_imageSizeEyeTrackerHeight_faceAsROI.Text;
            int    eye_tracker_width = 0, eye_tracker_height = 0;

            if (String.IsNullOrEmpty(eyetrackerImageWidth) || String.IsNullOrWhiteSpace(eyetrackerImageWidth) || (!int.TryParse(eyetrackerImageWidth, out eye_tracker_width)) ||
                String.IsNullOrEmpty(eyetrackerImageHeight) || String.IsNullOrWhiteSpace(eyetrackerImageHeight) || (!int.TryParse(eyetrackerImageHeight, out eye_tracker_height)))
            {
                controls.errorProvider_imageSizeEyeTracker_faceAsROI.SetError(controls.txt_imageSizeEyeTrackerHeight_faceAsROI, Constants.MESSAGE_ENTER_EYE_TRACKER_IMAGE_RESOLUTION);
                errror = true;
            }
            else
            {
                controls.errorProvider_imageSizeEyeTracker_faceAsROI.Clear();
                controls.errorProvider_imageSizeEyeTracker_faceAsROI.SetError(controls.txt_imageSizeEyeTrackerHeight_faceAsROI, "");
            }

            string eyetrackerImageErrorWidth = controls.txt_errorSizeEyeTrackerWidth_faceAsROI.Text;
            string eyetrackerImageErrorHeight = controls.txt_errorSizeEyeTrackerHeight_faceAsROI.Text;
            double eye_tracker_error_width = -1, eye_tracker_error_height = -1;

            bool error_in_errorValue = false;

            if (!String.IsNullOrEmpty(eyetrackerImageErrorWidth) && !String.IsNullOrWhiteSpace(eyetrackerImageErrorWidth))
            {
                if (!double.TryParse(eyetrackerImageErrorWidth, out eye_tracker_error_width))
                {
                    controls.errorProvider_errorSizeEyeTracker_visualizeTracking.SetError(controls.txt_errorSizeEyeTrackerHeight_faceAsROI, Constants.MESSAGE_ENTER_DOUBLE_VALUE);
                    errror = true;
                    error_in_errorValue = true;
                }
            }

            if (!String.IsNullOrEmpty(eyetrackerImageErrorHeight) && !String.IsNullOrWhiteSpace(eyetrackerImageErrorHeight))
            {
                if (!double.TryParse(eyetrackerImageErrorHeight, out eye_tracker_error_height))
                {
                    controls.errorProvider_errorSizeEyeTracker_visualizeTracking.SetError(controls.txt_errorSizeEyeTrackerHeight_faceAsROI, Constants.MESSAGE_ENTER_DOUBLE_VALUE);
                    errror = true;
                    error_in_errorValue = true;
                }
            }
            if (!error_in_errorValue)
            {
                controls.errorProvider_errorSizeEyeTracker_visualizeTracking.Clear();
                controls.errorProvider_errorSizeEyeTracker_visualizeTracking.SetError(controls.txt_errorSizeEyeTrackerHeight_faceAsROI, "");
            }

            if (errror)
            {
                return;
            }


            System.IO.StreamReader file_2d_landmarks  = new System.IO.StreamReader(landmarkFileName);
            System.IO.StreamReader file_gaze_raw_data = new System.IO.StreamReader(rawGazeDataFileName);
            System.IO.StreamReader file_image_size_trackingframework = new System.IO.StreamReader(imageSizeTrackingFrameworkFileName);

            if (file_image_size_trackingframework != null)
            {
                file_image_size_trackingframework.ReadLine(); //skip header
            }
            string[] tracking_framework_image_size;
            char[]   delimiterChars = { ' ', '\t', ',' };
            tracking_framework_image_size = file_image_size_trackingframework.ReadLine().Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
            ImageConversion imageConversion = new ImageConversion(eye_tracker_width, eye_tracker_height, Convert.ToInt32(tracking_framework_image_size[0]), Convert.ToInt32(tracking_framework_image_size[1]));

            if (eye_tracker_error_width != -1 || eye_tracker_error_height != -1)
            {
                imageConversion.set_errors_of_eye_tracker(eye_tracker_error_width <= 0?0: eye_tracker_error_width, eye_tracker_error_height <= 0?0:eye_tracker_error_height);
            }

            Constants.FilesForAOIDetection filesForAOIDetection = new Constants.FilesForAOIDetection(file_2d_landmarks, file_gaze_raw_data);
            string AOIs = UtilityFunctions.getAOIsofFile_OpenFace(filesForAOIDetection, imageConversion);

            file_2d_landmarks.Close();
            file_gaze_raw_data.Close();
            file_image_size_trackingframework.Close();

            System.IO.File.WriteAllText(outputFileName, AOIs);
            MessageBox.Show("Successfully Done!!");
        }