Beispiel #1
0
        static public openposeImageFrame[] loadFromTextFile_coco(string file)
        {
            List <openposeImageFrame> rtn = new List <openposeImageFrame>();
            string line      = "";
            string recordStr = "";
            bool   inSection = false;


            System.IO.StreamReader fr = new System.IO.StreamReader(@file);
            try
            {
                while ((line = fr.ReadLine()) != null)
                {
                    if (line.Trim().Length < 1)
                    {
                        continue;
                    }

                    if (inSection)
                    {
                        if (line[0] == '>')
                        {
                            openposeImageFrame oif = openposeImageFrame.fromTextLine_coco(recordStr);
                            if (oif != null)
                            {
                                rtn.Add(oif);
                            }

                            recordStr = line.Substring(1);
                        }
                        else
                        {
                            recordStr += Environment.NewLine + line;
                        }
                    }
                    else if (line[0] == '>')
                    {
                        inSection = true;
                        recordStr = line.Substring(1);
                    }
                }
            }
            catch (Exception ex)
            {
                fr.Close();
                throw ex;
            }

            return(rtn.ToArray());
        }
Beispiel #2
0
        static public openposeImageFrame fromTextLine_coco(string line)
        {
            openposeImageFrame rtn = new openposeImageFrame();

            rtn.keyType = keyPointModelType.coco;

            string[] lines = line.Split('\n');
            rtn.fileName = lines[0].Trim();

            for (int i = 1; i < lines.Length; ++i)
            {
                string body = lines[i].Trim();
                if (body.Length > 0)
                {
                    rtn.bodys.Add(bodyFromLine_coco(body));
                }
            }

            return(rtn);
        }
Beispiel #3
0
        static public openposeImageFrame fromTextLine(string line)
        {
            openposeImageFrame rtn = new openposeImageFrame();

            line = line.Replace('[', '<').Replace(']', '>');
            line = Regex.Replace(line, "<<<", "|<<");
            line = Regex.Replace(line, ">>>", ">>|");

            string[] parts = line.Split('|');
            if (parts.Length < 3)
            {
                string[] rFile = Regex.Split(line, ".jpg");
                rtn.fileName = rFile[0] + ".jpg";
                return(rtn);
            }
            rtn.fileName = parts[0].Trim();



            string bodysStr = Regex.Replace(Regex.Replace(Regex.Replace(parts[1], "<<", "_<"), ">>", ">_"), "_\\s+_", "_");

            if (!Regex.IsMatch(bodysStr, "^_") || !Regex.IsMatch(bodysStr, "_$"))
            {
                throw new Exception("Invalid bodys keypoints format");
            }
            bodysStr = Regex.Replace(bodysStr, "^_|_$", "");
            string[] bodys = bodysStr.Split('_');

            foreach (string body in bodys)
            {
                if (!Regex.IsMatch(body, "\\.\\.\\."))
                {
                    rtn.bodys.Add(bodyFromLine(body));
                }
            }

            return(rtn);
        }