コード例 #1
0
        /// <summary>
        /// Generate only one sample according to the selected items in ListBox
        /// </summary>
        /// <param name="skeletonDataLines">a string array; raw data including skeleton data and index number</param>
        /// <param name="listBox"></param>
        /// <param name="fileHandle"></param>
        /// <param name="url">folder:where to store the samples</param>
        /// <param name="tb"></param>
        /// <param name="cntSamples">the total number of the existing samples</param>
        /// <param name="minsteps">minimum frames in each sample,if less than minsteps, no sample will be generated</param>
        public void WriteSampleData(string[] skeletonDataLines, ListBox listBox, FileHandle fileHandle, string url,
                                    ref TextBox tb, ref int cntSamples, int minsteps = 15)
        {
            int cntValid = 0;
            // Create a sample
            string dataStr = string.Empty;
            string imgStr  = string.Empty;

            foreach (var selectedItem in listBox.SelectedItems)
            {
                // Make sure all the datas are valid
                string[] itemSplit = selectedItem.ToString().Split(' ');
                if (string.IsNullOrWhiteSpace(itemSplit[3]))
                {
                    MessageBox.Show("Empty data exists in the select data. ");
                    return;
                }
                cntValid++;
                // add data string
                string   label    = itemSplit[0];
                string   dataline = skeletonDataLines[Convert.ToInt32(itemSplit[0])].Split(':')[1];
                string[] datas    = dataline.Split(',');

                dataStr += label + "\t";
                for (int j = 0; j < datas.Length; j++)
                {
                    dataStr += string.Format("{0}\t", datas[j].Trim());
                }

                dataStr += "\n";
            }

            if (cntValid >= minsteps)
            {
                // Write
                // TXT file to write the skeleton data
                cntSamples++;
                string txtName = string.Format("{0}_{1}_{2}.txt", DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"), cntSamples.ToString("000"), cntValid);
                fileHandle.WriteMsg(Path.Combine(url, txtName), dataStr);

                // output the information
                string msg = string.Format("Done!\r\nSample No.{0}\r\nValid frames:{1}\r\n\r\n", cntSamples.ToString("000"), cntValid);
                tb.Text += msg;
            }
            else
            {
                MessageBox.Show($"You should at least choose {minsteps} frames.");
            }
        }
コード例 #2
0
        /// <summary>
        /// Disp and update the Button and NumericUpDown for all the classes
        /// </summary>
        /// <param name="labels_list">a 2-d array; 1st-d:index number; 2nd-d:label</param>
        /// <param name="fileHandle"></param>
        /// <param name="buttonCnt">button group</param>
        public void DispLabelCnt(int[,] labels_list, FileHandle fileHandle, ref Button[] buttonCnt)
        {
            for (int labelindex = 0; labelindex < buttonCnt.Length; labelindex++)
            {
                if (labels_list == null)
                {
                    return;
                }
                List <string> fileUrls = new List <string>();
                string[]      imgPaths = fileHandle.ImgaeFolder.Split(Path.DirectorySeparatorChar);
                for (int i = 0; i < labels_list.GetUpperBound(0) + 1; i++)
                {
                    if (labels_list[i, 1] == labelindex)
                    {
                        string imgPath = Path.Combine("..", "..", "..", imgPaths[imgPaths.Length - 2], imgPaths[imgPaths.Length - 1], labels_list[i, 0].ToString() + ".bmp");
                        fileUrls.Add(imgPath);
                    }
                }

                // Disp
                buttonCnt[labelindex].Text = fileUrls.Count.ToString();
            }
        }
コード例 #3
0
        /// <summary>
        /// Generate all the samples according to all the labeled data
        /// Pay attention to the paramaters
        /// </summary>
        /// <param name="skeletonDataLines">a string array; raw data including skeleton data and index number</param>
        /// <param name="labels_list">a 2-d array; 1st-d: index number; 2nd-d: label</param>
        /// <param name="fileHandle"></param>
        /// <param name="url">folder:where to store the samples</param>
        /// <param name="tb"></param>
        /// <param name="cntSamples">the total number of the existing samples</param>
        /// <param name="maxsteps">maximum frames in each sample</param>
        /// <param name="minsteps">minimum frames in each sample,if less than minsteps, no sample will be generated</param>
        /// <param name="cover">how many frames to be covered between different samples</param>
        /// <param name="gap">if the length of empty part is larger than gap, then set all the following labels to -1</param>
        public void WriteSampleData(string[] skeletonDataLines, int[,] labels_list, FileHandle fileHandle,
                                    string url, ref TextBox tb, ref int cntSamples, int maxsteps = 60, int minsteps = 15, int cover = 30, int gap = 3)
        {
            int cntValidAll = 0;

            for (int i = 0; i < labels_list.GetLength(0);)
            {
                // Make sure first data is valid
                int label = labels_list[i, 1];
                if (label < 0)
                {
                    i++;
                    continue;
                }

                //get data by maxsteps fistly
                int[,] sample = new int[maxsteps, 2];
                int step = Math.Min(labels_list.GetLength(0) - i, maxsteps);
                for (int j = 0; j < step; j++)
                {
                    sample[j, 0] = labels_list[i + j, 0];
                    sample[j, 1] = labels_list[i + j, 1];
                }

                // detect the gap and set the following data to -1
                int cntGap   = 0;
                int cntValid = 0;
                //int LstIndex = maxsteps-1;
                for (int j = 0; j < step; j++)
                {
                    if (cntGap > gap)
                    {
                        sample[j, 1] = -1;
                        continue;
                    }
                    if (sample[j, 1] == -1)
                    {
                        cntGap++;
                    }
                    else
                    {
                        cntValid++;
                        cntGap = 0;
                    }
                }

                // initial for next batch
                i = i + cover;

                //check the number of the valid data, move to next batch if not enough
                if (cntValid < minsteps)
                {
                    continue;
                }
                else
                {
                    cntSamples++;
                    cntValidAll += cntValid;
                    string baseName = string.Format("{0}_{1}_{2}", DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss"), cntSamples.ToString("000"), cntValid);
                    string txtName  = baseName + ".txt";
                    //string labelName = baseName + ".md";
                    // write the data which is not -1
                    for (int m = 0; m < step; m++)
                    {
                        string dataStr = string.Empty;
                        //string labelStr = string.Empty;
                        if (sample[m, 1] > -1)
                        {
                            string   dataline    = skeletonDataLines[sample[m, 0]].Split(':')[1];
                            string[] data_joints = dataline.Split(',');
                            // replace all the Standing with Walking
                            int label_temp = sample[m, 1] == 0 ? 2 : sample[m, 1];
                            dataStr += sample[m, 0].ToString("00000") + "\t" + label_temp.ToString() + "\t";
                            //labelStr += sample[m, 0].ToString("00000") + "\t" + sample[m, 1].ToString();
                            for (int j = 0; j < data_joints.Length; j++)
                            {
                                dataStr += string.Format("{0}\t", data_joints[j].Trim());
                            }
                            // Write
                            fileHandle.WriteMsg(Path.Combine(url, txtName), dataStr);
                        }
                    }
                }
            }

            // output the information
            string msg = string.Format("Done!\r\nUrl:{0}\r\nSample number:{1}\r\nValid frames:{2}\r\n\r\n", url, cntSamples, cntValidAll);

            tb.Text += msg;
        }
コード例 #4
0
        /// <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);
        }