Example #1
0
        private bool ReadParam(ref ReportDB[] DB, ref string path)
        {
            if (!File.Exists(path))
                return false;

            try
            {
                StreamReader reader = new StreamReader(path);

                string tstr = reader.ReadLine();
                int m_ClientsNum = int.Parse(tstr);
                tstr = reader.ReadLine();

                //아이피 읽어들이기
                //m_Avips = new string[m_ClientsNum];

                for (int i = 0; i < m_ClientsNum; i++)
                {
                    tstr = reader.ReadLine();
                }

                //패스워드 읽기
                tstr = reader.ReadLine();

                //카메라 파라미터 읽기

                //m_AvParam = new AVParam[m_ClientsNum];

                for (int i = 0; i < m_ClientsNum; i++)
                {
                    //m_AvParam[i] = new AVParam();
                    tstr = reader.ReadLine();
                    //m_AvParam[i].left = int.Parse(tstr);
                    tstr = reader.ReadLine();
                    //m_AvParam[i].top = int.Parse(tstr);
                    tstr = reader.ReadLine();
                    //m_AvParam[i].width = int.Parse(tstr);
                    tstr = reader.ReadLine();
                    //m_AvParam[i].height = int.Parse(tstr);
                    tstr = reader.ReadLine();
                    //m_AvParam[i].fps = int.Parse(tstr);
                    tstr = reader.ReadLine();
                    //m_AvParam[i].res = (IMAGE_RESOLUTION)Enum.Parse(typeof(IMAGE_RESOLUTION), tstr);
                    tstr = reader.ReadLine();
                    //m_AvParam[i].codecType = (AVCodecType)Enum.Parse(typeof(AVCodecType), tstr);
                    tstr = reader.ReadLine();
                    //m_AvParam[i].quality = int.Parse(tstr);
                    tstr = reader.ReadLine();
                    //m_AvParam[i].intraFramePeriod = int.Parse(tstr);
                    tstr = reader.ReadLine();
                    //m_AvParam[i].bitrate = int.Parse(tstr);
                    tstr = reader.ReadLine();
                    //m_AvParam[i].stream_id = int.Parse(tstr);
                    tstr = reader.ReadLine();
                    //m_AvParam[i].dn_mode = (DN_modes)Enum.Parse(typeof(DN_modes), tstr);
                    tstr = reader.ReadLine();
                    //m_AvParam[i].light = (Light_modes)Enum.Parse(typeof(Light_modes), tstr);
                    tstr = reader.ReadLine();
                    //m_AvParam[i].CameraMode = int.Parse(tstr);
                    tstr = reader.ReadLine();
                    //m_AvParam[i].ShutterSpeed = int.Parse(tstr);
                }

                tstr = reader.ReadLine();
                TargetType m_TargetType = (TargetType)Enum.Parse(typeof(TargetType), tstr);
                tstr = reader.ReadLine();
                m_TargetWidth = double.Parse(tstr);
                tstr = reader.ReadLine();
                m_TargetHeight = double.Parse(tstr);
                tstr = reader.ReadLine();
                m_TargetLimit = double.Parse(tstr);
                tstr = reader.ReadLine();
                double m_RotateLimit = double.Parse(tstr);
                tstr = reader.ReadLine();
                double m_ScaleLimit = double.Parse(tstr);
                tstr = reader.ReadLine();

                //타깃정보 입력
                tstr = reader.ReadLine();

                if (tstr.Length > 0)
                {
                    int imgnum = int.Parse(tstr);
                    DB = new ReportDB[imgnum];

                    for (int i = 0; i < imgnum; i++)
                    {
                        DB[i] = new ReportDB();
                        tstr = reader.ReadLine();
                        tstr = reader.ReadLine();

                        if (tstr == "initialized")
                        {
                            DB[i].m_Initialized = true;
                            tstr = reader.ReadLine();
                            int tnum = int.Parse(tstr);

                            if (tnum > 0)
                            {

                                for (int x = 0; x < tnum; x++)
                                {
                                    TG tg = new TG();
                                    DB[i].TGS.Add(tg);
                                }

                                //DB[i].m_Targets = new TargetDb[tnum];

                                for (int j = 0; j < tnum; j++)
                                {
                                    TG tg = (TG)DB[i].TGS[j];
                                    //m_Images[i].m_Targets[j] = new TargetDb();
                                    tg.m_ID = reader.ReadLine();
                                    tstr = reader.ReadLine();
                                    tg.ix = double.Parse(tstr);
                                    tstr = reader.ReadLine();
                                    tg.iy = double.Parse(tstr);
                                    tstr = reader.ReadLine();
                                    tg.m_DWidth = double.Parse(tstr);
                                    tstr = reader.ReadLine();
                                    tg.m_DHeight = double.Parse(tstr);
                                    tstr = reader.ReadLine();

                                    int cnum = int.Parse(tstr);

                                    if (cnum > 0)
                                    {
                                        tg.m_Corners = new PointF[cnum];

                                        for (int x = 0; x < cnum; x++)
                                        {
                                            tg.m_Corners[x] = new PointF();
                                            tstr = reader.ReadLine();
                                            char[] splt = { ',' };
                                            string[] rst = tstr.Split(splt);
                                            tg.m_Corners[x].X = float.Parse(rst[0]);
                                            tg.m_Corners[x].Y = float.Parse(rst[1]);

                                        }
                                    }

                                }
                            }

                            //ResetTargets(false, m_Images[i].m_Targets.Length);

                        }
                        else
                        {
                            DB[i].m_Initialized = false;
                        }

                    }
                }

                reader.Close();
                return true;

            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.ToString());
                return false;
            }
        }
Example #2
0
        private void MergeDG(ref ReportDB[] mDB, ref ReportDB[] DB)
        {
            if (mDB == null)
            {
                mDB = new ReportDB[DB.Length];

            }

            for (int i = 0; i < DB.Length; i++)
            {
                if (mDB[i] == null)
                {
                    mDB[i] = new ReportDB();

                    int tnum = DB[i].TGS.Count;

                    for (int j = 0; j < tnum; j++)
                    {
                        TG tg = new TG();
                        tg.m_ID = ((TG)DB[i].TGS[j]).m_ID;
                        mDB[i].TGS.Add(tg);
                    }
                }

                int tcount = DB[i].TGS.Count;

                for (int x = 0; x < tcount; x++)
                {
                    TG ttg = (TG)mDB[i].TGS[x];

                    TG stg = null;

                    for (int k = 0; k < tcount; k++)
                    {
                        if (((TG)DB[i].TGS[x]).m_ID == ttg.m_ID)
                        {
                            stg = (TG)DB[i].TGS[x];
                            break;
                        }
                    }

                    if (stg == null)
                        continue;

                    int tgcount = stg.Arr.Count;

                    for (int y = 0; y < tgcount; y++)
                    {
                        ttg.Arr.Add(stg.Arr[y]);
                    }
                }
            }
        }
Example #3
0
        private void ReadData(ref ReportDB DB, ref string path, int day)
        {
            if (!File.Exists(path))
                return;
            try
            {
                StreamReader reader = new StreamReader(path);

                string tstr = "";

                string[] splt = { " : " };
                char[] splt2 = { '-', '(', ')', ' ' };
                char[] splt3 = { ',' };

                while (!reader.EndOfStream)
                {
                    tstr = reader.ReadLine();

                    string[] rst = tstr.Split(splt, StringSplitOptions.RemoveEmptyEntries);

                    string[] rst2 = rst[0].Split(splt2);

                    int hour = int.Parse(rst2[0]);
                    int minutes = int.Parse(rst2[1]);
                    double seconds = double.Parse(rst2[2]);

                    rst2 = rst[1].Split(splt2);

                    int tnum = int.Parse(rst2[2]);

                    for (int i = 0; i < tnum; i++)
                    {
                        TargetCoord tg = new TargetCoord();

                        tstr = reader.ReadLine();

                        rst = tstr.Split(splt, StringSplitOptions.RemoveEmptyEntries);

                        rst2 = rst[1].Split(splt2, StringSplitOptions.RemoveEmptyEntries);

                        tg.m_ID = rst[0];

                        int tgnum = -1;

                        for (int x = 0; x < DB.TGS.Count; x++)
                        {
                            TG tmptg = (TG)DB.TGS[x];

                            if (tmptg.m_ID == tg.m_ID)
                            {
                                tgnum = x;
                                break;
                            }
                        }

                        if (tgnum < 0)
                            continue;

                        TG srctg = (TG)DB.TGS[tgnum];

                        for (int x = 0; x < rst2.Length; x++)
                        {
                            rst = rst2[x].Split(splt3);
                            tg.Corners[x].X = float.Parse(rst[0]);
                            tg.Corners[x].Y = float.Parse(rst[1]);
                        }

                        double l1 = Math.Sqrt(Math.Pow(tg.Corners[0].X - tg.Corners[1].X, 2)
                            + Math.Pow(tg.Corners[0].Y - tg.Corners[1].Y, 2));

                        double l2 = Math.Sqrt(Math.Pow(tg.Corners[1].X - tg.Corners[2].X, 2)
                            + Math.Pow(tg.Corners[1].Y - tg.Corners[2].Y, 2));

                        tg.nWidth = l2;
                        tg.nHeight = l1;
                        CalcCenter(ref tg);

                        double sx = 0, sy = 0, ang = 0;

                        //CalcProjectivity(ref m_Images[i - 1].m_Targets[k].m_Corners, ref tg.Corners, ref sx, ref sy, ref ang);

                        //회전량 계산
                        CvPoint2D32f[] srcPoint = new CvPoint2D32f[3];
                        CvPoint2D32f[] dstPoint = new CvPoint2D32f[3];

                        for (int x = 0; x < 3; x++)
                        {
                            srcPoint[x] = new CvPoint2D32f(srctg.m_Corners[x].X, srctg.m_Corners[x].Y);
                            dstPoint[x] = new CvPoint2D32f(tg.Corners[x].X, tg.Corners[x].Y);
                        }

                        CvMat mapMatrix = Cv.GetAffineTransform(srcPoint, dstPoint);

                        double a11 = Cv.GetReal2D(mapMatrix, 0, 0);
                        double a12 = Cv.GetReal2D(mapMatrix, 0, 1);
                        double a21 = Cv.GetReal2D(mapMatrix, 1, 0);
                        double a22 = Cv.GetReal2D(mapMatrix, 1, 1);

                        sx = Math.Sqrt(a11 * a11 + a21 * a21);
                        sy = Math.Sqrt(a12 * a12 + a22 * a22);

                        if (sx == 0)
                            ang = 0;
                        else
                            ang = Math.Abs(Math.Asin(-a21 / sx) * 180 / Math.PI);

                        //면적변화 계산

                        sx = srcPoint[0].X * (srcPoint[1].Y - srcPoint[2].Y) + srcPoint[1].X * (srcPoint[2].Y - srcPoint[0].Y) + srcPoint[2].X * (srcPoint[0].Y - srcPoint[1].Y);
                        sy = dstPoint[0].X * (dstPoint[1].Y - dstPoint[2].Y) + dstPoint[1].X * (dstPoint[2].Y - dstPoint[0].Y) + dstPoint[2].X * (dstPoint[0].Y - dstPoint[1].Y);

                        sx = sx * Math.Pow(m_TargetWidth / srctg.GetCornerWidth(), 2);
                        sy = sy * Math.Pow(m_TargetWidth / srctg.GetCornerWidth(), 2);

                        double scale = 0;

                        scale = Math.Abs((sx - sy) / sx * 100);

                        //중심변위계산////////////////////////

                        double diffx = Math.Abs(srctg.ix - tg.x);
                        double diffy = Math.Abs(srctg.iy - tg.y);

                        if (srctg.GetCornerWidth() == 0 || srctg.GetCornerHeight() == 0)
                            continue;

                        diffx = m_TargetWidth / srctg.GetCornerWidth() * diffx;
                        diffy = m_TargetHeight / srctg.GetCornerHeight() * diffy;

                        //DB에 추가
                        COORD tdb = new COORD();
                        tdb.dx = diffx;
                        tdb.dy = diffy;
                        tdb.ang = ang;
                        tdb.scale = scale;

                        tdb.day = day;
                        tdb.hour = hour;
                        tdb.min = minutes;
                        tdb.sec = seconds;

                        srctg.Arr.Add(tdb);
                    }
                }

                reader.Close();
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.ToString());
                return;
            }
        }
Example #4
0
        private void WriteDB(ref ReportDB[] DB, int type, DateTime DT)
        {
            int num = DB.Length;

            string outpath = Application.StartupPath + "\\tmpreport.txt";

            StreamWriter writer = new StreamWriter(outpath);

            switch (obstype)
            {
                case 0:
                    writer.WriteLine("====================== 일간 영상계측 보고서 =========================");
                    writer.WriteLine("");
                    writer.WriteLine("1. 계측 담당자 		:             (인)");
                    writer.WriteLine("");
                    writer.WriteLine(string.Format("2. 관측날짜	 	: {0}년 {1}월 {2}일", DT.Year, DT.Month, DT.Day));
                    writer.WriteLine("");
                    writer.Write("3. 카메라/타깃 수량 	: ");
                    break;
                case 1:
                    int wknum = GetWeekOfMonth(DT);
                    writer.WriteLine("====================== 주간 영상계측 보고서 =========================");
                    writer.WriteLine("");
                    writer.WriteLine("1. 계측 담당자 		:             (인)");
                    writer.WriteLine("");
                    writer.WriteLine(string.Format("2. 관측날짜	 	: {0}년 {1}월 {2}째 주", DT.Year, DT.Month, wknum));
                    writer.WriteLine("");
                    writer.Write("3. 카메라/타깃 수량 	: ");
                    break;
                case 2:
                    writer.WriteLine("====================== 월간 영상계측 보고서 =========================");
                    writer.WriteLine("");
                    writer.WriteLine("1. 계측 담당자 		:             (인)");
                    writer.WriteLine("");
                    writer.WriteLine(string.Format("2. 관측날짜	 	: {0}년 {1}월", DT.Year, DT.Month));
                    writer.WriteLine("");
                    writer.Write("3. 카메라/타깃 수량 	: ");
                    break;
            }

            for (int i = 0; i < num; i++)
            {
                writer.Write("Camera{0} (타깃:{1}개)", i + 1, DB[i].TGS.Count);
                if (i < num - 1)
                    writer.Write(", ");
                else
                    writer.Write("\r\n");
            }

            writer.WriteLine("");

            writer.WriteLine("4. 계측요약\r\n");

            for (int i = 0; i < num; i++)
            {
                writer.WriteLine(string.Format("({0}) Camera {1} 계측요약\r\n", i + 1, i + 1));

                int tnum = DB[i].TGS.Count;

                for (int j = 0; j < tnum; j++)
                {
                    TG tg = (TG)DB[i].TGS[j];
                    writer.WriteLine(string.Format(" < 타깃 {0} >\r\n", tg.m_ID));

                    double maxhor = 0, maxver = 0, evenhor = 0, evenver = 0, maxang = 0, maxscale = 0;

                    CalcStatic(ref tg, ref maxhor, ref maxver, ref evenhor, ref evenver, ref maxang, ref maxscale); ;

                    writer.WriteLine(string.Format("  - 수평최대변위: {0:0.00}cm, 	수직최대변위 : {1:0.00}cm", maxhor * 100, maxver * 100));
                    writer.WriteLine(string.Format("  - 수평평균변위: {0:0.00}cm, 	수직평균변위 : {1:0.00}cm", evenhor * 100, evenver * 100));
                    writer.WriteLine(string.Format("  - 최대회전각  : {0:0.00}도, 	최대축척변화 : {1:0.00}%", maxang, maxscale));
                    writer.WriteLine("");

                }
            }

            writer.WriteLine("5. 계측자료\r\n");

            for (int i = 0; i < num; i++)
            {
                writer.WriteLine(string.Format("({0}) Camera {1}\r\n", i + 1, i + 1));

                int tnum = DB[i].TGS.Count;

                for (int j = 0; j < tnum; j++)
                {
                    TG tg = (TG)DB[i].TGS[j];

                    writer.WriteLine(string.Format(" < 타깃 {0} > (시간, 수평변위, 수직변위, 회전량, 축척변화량)\r\n", tg.m_ID));

                    int knum = tg.Arr.Count;

                    for (int k = 0; k < knum; k++)
                    {
                        COORD cg = (COORD)tg.Arr[k];
                        writer.WriteLine(string.Format("    {0:00}-{1:00}-{2:00}-{3:00.00}\t{4:0.00}cm\t{5:0.00}cm\t{6:0.00}도\t{7:0.00}%", cg.day, cg.hour, cg.min, cg.sec, cg.dx * 100, cg.dy * 100, cg.ang, cg.scale));
                    }

                    writer.WriteLine("");

                }
            }

            writer.Close();
            //리포트 출력하기

            Process.Start("notepad.exe", outpath);
        }