/// <summary> /// Read all the labels from a .MD file, if the file does not exist, then create one /// </summary> /// <param name="url">the url of the .MD file</param> /// <param name="data_length">the number of all frames</param> /// <returns></returns> public int[,] GetLabels(string url, int data_length) { int[,] LabelsList = new int[data_length, 2]; // If Label List does not exist, create one if (!File.Exists(url)) { // Create a list with the same length for (int i = 0; i < data_length; i++) { //string itemStr = string.Format("{0}:{1}", i.ToString("00000"), "-1"); LabelsList[i, 0] = i + 1; LabelsList[i, 1] = -1; } m_fileHandle.WriteLabelsMD(url, LabelsList); } else { // If Label List exists, read it string[] labels_string = File.ReadAllLines(url); for (int i = 0; i < labels_string.Length; i++) { string[] line = labels_string[i].Split(':'); int index = Convert.ToInt32(line[0]); int label = Convert.ToInt32(line[1]); LabelsList[i, 0] = index; LabelsList[i, 1] = label; //string itemStr = string.Format("{0}:{1}", index, "-1"); } } return(LabelsList); }
/// <summary> /// After label, this function help to update Listbox and global label list /// And save the label list to a .md file /// </summary> /// <param name="labels_list">global label list</param> /// <param name="url">url of the .md file to save the labels</param> /// <param name="listBox"></param> /// <param name="labelindex">[-1,0,1,2,3,4] -1 means ignored</param> /// <param name="fileHandle"></param> public void UpdateLabel(ref int[,] labels_list, string url, ref ListBox listBox, int labelindex, FileHandle fileHandle) { // add image string: ..\..\..\DataFloder\ImagesFolder\ImageName string[] imgPaths = fileHandle.ImgaeFolder.Split(Path.DirectorySeparatorChar); foreach (int selectedIndex in listBox.SelectedIndices) { // Modify the listBox string line = listBox.Items[selectedIndex].ToString(); string[] line_arr = line.Split(' '); if (string.IsNullOrWhiteSpace(line_arr[3])) { continue; } string line_new = line.Substring(0, line.Length - 1) + (labelindex == -1 ? " " : labelindex.ToString()); listBox.Items[selectedIndex] = line_new; listBox.SetSelected(selectedIndex, true); // Modify the labels list labels_list[selectedIndex, 1] = labelindex; } // Write fileHandle.WriteLabelsMD(url, labels_list); }