Exemple #1
0
        public void CalBackBound(ref FrameInfo backFrame)
        {
            int[] rowsum=new int[40];
            //int[] t_colsum = new int[40];
            //int[] b_colsum = new int[40];
            bool t_first = true, b_first=true;
            for (int i = 0; i < backFrame.rows; i++)
            {
                for (int j = 0; j < backFrame.cols; j++)
                {
                    rowsum[i] = rowsum[i] + backFrame.pressureValue[i, j];
                }
            }
            for (int i = 0; i < rowsum.GetLength(0) - 1; i++)
            {
                if (rowsum[i] == 0 && rowsum[i + 1] != 0)
                {
                    if (t_first)
                        backFrame.t_Top = i + 1;
                    else
                    {
                        backFrame.twoFeet = true;
                        backFrame.b_Top = i + 1;
                    }
                    t_first = !t_first;
                }
                if (rowsum[i] != 0 && rowsum[i + 1] == 0)
                {
                    if (b_first)
                        backFrame.t_Bottom = i;
                    else
                        backFrame.b_Bottom = i;
                    b_first = !b_first;
                }
            }

            int t_left = 40, t_right = 0, b_left = 40, b_right = 0;
            for (int i = backFrame.t_Top; i <= backFrame.t_Bottom; i++)
                for (int j = 0; j < 40; j++)
                {
                    if (backFrame.pressureValue[i,j] != 0)
                    {
                        t_left = j < t_left ? j : t_left;
                        t_right = j > t_right ? j : t_right;
                    }
                }
            for (int i = backFrame.b_Top; i <= backFrame.b_Bottom; i++)
                for (int j = 0; j < 40; j++)
                {
                    if (backFrame.pressureValue[i, j] != 0)
                    {
                        b_left = j < b_left ? j : b_left;
                        b_right = j > b_right ? j : b_right;
                    }
                }
            backFrame.t_Left = t_left;
            backFrame.t_Right = t_right;
            backFrame.b_Left = b_left;
            backFrame.b_Right = b_right;
        }
Exemple #2
0
        //读取压力值到内存中
        public void GetPressure()
        {
            try
            {
                using (CsvReader reader = new CsvReader(path, Encoding.Default))
                {
                    FrameInfo frameInfo = new FrameInfo();
                    int frameIndex = -1;
                    int tmpRow = 0, tmpCol = 0, tmpPressure = 0, totalPressure = 0, totalNonZero = 0, maxPressure = 0;
                    //int mPosX = 0, mPosY = 0;
                    bool isBackFrame = false;
                    while (reader.ReadNextRecord())
                    {
                        if (reader.Fields[0] == "-10")
                        {
                            if (isBackFrame)
                                backFrames.Add(frameInfo);
                            else
                                allFrames.Add(frameInfo);
                            break;
                        }
                        else if (reader.Fields[0] == "-1")
                        {
                            if (frameIndex >= 0)
                            {
                                if (isBackFrame)
                                    backFrames.Add(frameInfo);
                                else
                                    allFrames.Add(frameInfo);
                            }
                            isBackFrame = false;
                            frameInfo = new FrameInfo();
                            frameIndex = frameIndex + 1;
                            totalPressure = 0;
                            totalNonZero = 0;
                            maxPressure = 0;
                            frameInfo.frameIndex = Int32.Parse(reader.Fields[1]);
                            continue;
                        }
                        else if (reader.Fields[0] == "-2")
                        {
                            if (isBackFrame)
                                backFrames.Add(frameInfo);
                            else
                                allFrames.Add(frameInfo);
                            isBackFrame = true;
                            frameInfo = new FrameInfo();
                            tmpRow = 0;
                            totalPressure = 0;
                            totalNonZero = 0;
                            maxPressure = 0;
                            frameInfo.frameIndex = frameIndex;
                            continue;
                        }
                        else if (frameIndex >= 0 && isBackFrame == false)
                        {
                            List<string> tmpRowInfo = reader.Fields;
                            for (int i = 0; i < tmpRowInfo.Count; i++)
                            {
                                string tmp = tmpRowInfo[i];
                                if (tmp.Contains("."))
                                    tmp = tmp.Substring(0, tmp.IndexOf("."));
                                if (tmp != "-1")
                                {
                                    if (i == 0)
                                    {
                                        tmpRow = Int32.Parse(tmp);
                                    }
                                    else if (i % 2 == 1)
                                    {
                                        tmpCol = Int32.Parse(tmp);
                                        totalNonZero = totalNonZero + 1;
                                    }
                                    else
                                    {
                                        tmpPressure = Int32.Parse(tmp);
                                        totalPressure = totalPressure + tmpPressure;
                                        frameInfo.pressureValue[tmpRow, tmpCol] = tmpPressure;
                                        if (tmpPressure > maxPressure)
                                        {
                                            maxPressure = tmpPressure;
                                            //mPosX = tmpRow; mPosY = tmpCol;
                                        }
                                    }
                                }
                                else
                                    break;
                            }
                            frameInfo.Area = totalNonZero;
                            frameInfo.Pressure = totalPressure;
                            frameInfo.MaxPressure = maxPressure;
                        }
                        else if (frameIndex >= 0 && isBackFrame == true)
                        {
                            List<string> tmpRowInfo = reader.Fields;
                            for (int i = 0; i < tmpRowInfo.Count; i++)
                            {
                                string tmp = tmpRowInfo[i];
                                if (tmp.Contains("."))
                                    tmp = tmp.Substring(0, tmp.IndexOf("."));
                                //if (tmp != "-1")
                                {
                                    tmpPressure = Int32.Parse(tmp);
                                    frameInfo.pressureValue[tmpRow, i] = tmpPressure;
                                    totalPressure = totalPressure + tmpPressure;
                                    if (tmp != "0")
                                        totalNonZero = totalNonZero + 1;
                                }
                            }
                            tmpRow = tmpRow + 1;
                            //frameInfo.averagePress = totalPressure * 1.0 / totalNonZero;
                        }
                    }
                }

                //剔除孤立点
                for (int i = 0; i < backFrames.Count; i++)
                {
                    DelIsolated(ref backFrames[i].pressureValue);
                }
                for (int i = 0; i < allFrames.Count; i++)
                {
                    DelIsolated(ref allFrames[i].pressureValue);
                }

                for (int i = 0; i < allFrames.Count; i++)
                {
                    for (int j = 0; j < backFrames.Count - 1; j++)
                    {
                        if (i > backFrames[j].frameIndex && i <= backFrames[j + 1].frameIndex)
                            allFrames[i].backIndex = j + 1;
                        else if (i < backFrames[0].frameIndex)
                            allFrames[i].backIndex = 0;
                        else if (i > backFrames[backFrames.Count - 1].frameIndex)
                            allFrames[i].backIndex = backFrames.Count - 1;
                    }
                }

                //计算背景边缘
                for (int i = 0; i < backFrames.Count; i++)
                {
                    FrameInfo finfo = backFrames[i];
                    //finfo.CalBound();
                    CalBackBound(ref finfo);
                }
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message);
            }
        }