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;
            }
        }
Beispiel #2
0
        public void DrawTargetOnImages(ref Image img, ref TargetCoord[] targets)
        {
            float nPercentW, nPercentH, nPercent;

            int destX, destY;

            nPercentW = ((float)picThumb.Width / (float)img.Width);
            nPercentH = ((float)picThumb.Height / (float)img.Height);
            if (nPercentH < nPercentW)
            {
                nPercent = nPercentH;
                destX = System.Convert.ToInt16((picThumb.Width -
                              (img.Width * nPercent)) / 2);
            }
            else
            {
                nPercent = nPercentW;
                destY = System.Convert.ToInt16((picThumb.Height -
                              (img.Height * nPercent)) / 2);
            }

            int destWidth = (int)(img.Width * nPercent);
            int destHeight = (int)(img.Height * nPercent);

            //Bitmap bmp = new Bitmap(picThumb.Width, picThumb.Height, PixelFormat.Format32bppArgb);
            Bitmap bmp = new Bitmap(destWidth, destHeight, PixelFormat.Format32bppArgb);
            Graphics gbmp = Graphics.FromImage(bmp);
            gbmp.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
            //gbmp.DrawImage(img, picThumb.Bounds, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
            gbmp.DrawImage(img, new Rectangle(0, 0, destWidth, destHeight), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);

            int tnum = targets.Length;

            double cx = 0, cy = 0;

            for (int i = 0; i < tnum; i++)
            {
                double maxx = -100, maxy = -100;
                int cnum = targets[i].Corners.Length;
                PointF[] ncor = new PointF[cnum + 1];
                Pen lpen = new Pen(Color.Red, (float)1.5);

                cx = 0;
                cy = 0;

                for (int j = 0; j < cnum; j++)
                {
                    ncor[j] = new PointF(targets[i].Corners[j].X * destWidth / img.Width,
                        targets[i].Corners[j].Y * destHeight / img.Height);

                    if (maxx <= ncor[j].X)
                        maxx = ncor[j].X;
                    if (maxy <= ncor[j].Y)
                        maxy = ncor[j].Y;

                    cx += targets[i].Corners[j].X;
                    cy += targets[i].Corners[j].Y;
                }

                if (cnum == 0) continue;
                if (img.Width == 0) continue;
                if (img.Height == 0) continue;

                cx = cx / cnum;
                cy = cy / cnum;

                cx = cx * destWidth / img.Width;
                cy = cy * destHeight / img.Height;

                ncor[cnum] = new PointF(ncor[0].X, ncor[0].Y);
                gbmp.DrawLines(lpen, ncor);
                gbmp.DrawImage(m_Cursor, (float)(cx - m_Cursor.Width / 2), (float)(cy - m_Cursor.Height / 2),
                    (float)m_Cursor.Width, (float)m_Cursor.Height);

                Font tfont = new Font("굴림", 10);
                gbmp.FillRectangle(Brushes.Black, (float)(maxx + 3), (float)(maxy + 1), tfont.SizeInPoints * targets[i].m_ID.Length, tfont.Height);

                gbmp.DrawString(targets[i].m_ID, tfont, Brushes.Yellow, new PointF((float)(maxx + 3), (float)(maxy + 3)));
                tfont.Dispose();
                lpen.Dispose();

            }

            gbmp.Dispose();

            picThumb.Image = bmp;
            if (apachePath != null)
                bmp.Save(apachePath + DateTime.Now.Ticks.ToString() + ".png", ImageFormat.Png);
            picThumb.Update();
        }
        private void CalcCenter(ref TargetCoord tg)
        {
            double a1 = tg.Corners[0].X;
            double b1 = tg.Corners[0].Y;
            double x1 = tg.Corners[2].X - tg.Corners[0].X;
            double y1 = tg.Corners[2].Y - tg.Corners[0].Y;

            double a2 = tg.Corners[1].X;
            double b2 = tg.Corners[1].Y;
            double x2 = tg.Corners[3].X - tg.Corners[1].X;
            double y2 = tg.Corners[3].Y - tg.Corners[1].Y;

            double[,] A = new double[2, 2];
            A[0, 0] = 2 * (x1 * x1 + y1 * y1);
            A[0, 1] = -2 * (x1 * x2 + y1 * y2);
            A[1, 0] = -2 * (x1 * x2 + y1 * y2);
            A[1, 1] = 2 * (x2 * x2 + y2 * y2);

            double[] B = new double[2];
            B[0] = 2 * (x1 * (a2 - a1) + y1 * (b2 - b1));
            B[1] = -2 * (x2 * (a2 - a1) + y2 * (b2 - b1));

            double[,] AI = new double[2, 2];
            double td = A[0, 0] * A[1, 1] - A[1, 0] * A[0, 1];

            AI[0, 0] = A[1, 1] / td;
            AI[0, 1] = -A[0, 1] / td;
            AI[1, 0] = -A[1, 0] / td;
            AI[1, 1] = A[0, 0] / td;

            double xx0 = AI[0, 0] * B[0] + AI[0, 1] * B[1];
            double xx1 = AI[1, 0] * B[0] + AI[1, 1] * B[1];

            double l_th = 0.15;

            if (Math.Abs(xx0 - 0.5) < l_th && Math.Abs(xx1 - 0.5) < l_th)
            {
                tg.x = (float)(a1 + xx0 * x1);
                tg.y = (float)(b1 + xx0 * y1);
            }
        }
Beispiel #4
0
        public void DrawOnBoxGraph(ref int pnum, ref TargetCoord[] targets, ref double maxx, ref double maxy, ref double maxangle, ref double maxscale, ref double evenx, ref double eveny, ref double evenangle, ref double evenscale)
        {

            int i = pnum;
            MonGraph gbox = null;

            if (m_isInit)
                gbox = (MonGraph)tpnlCamArray.Controls[m_SelCamNum];
            else
                gbox = (MonGraph)tpnlCamArray.Controls[i - 1];

            if (m_isInit)
                gbox.SetInitialValue(m_SelCamNum + 1, m_TargetLimit, m_Images[i - 1].m_Targets.Length, m_Images[i - 1].m_Initialized);
            else
                gbox.SetInitialValue(i, m_TargetLimit, m_Images[i - 1].m_Targets.Length, m_Images[i - 1].m_Initialized);

            server.BroadcastCams(NET_INFO_CAMS, (m_isInit ? m_SelCamNum + 1 : m_SelCamNum), maxx, maxy, maxangle, maxscale, evenx, eveny, evenangle, evenscale);

            gbox.SetBasicValue();
            gbox.SetDiffData(evenx, eveny, maxx, maxy, ref m_CapImg[i - 1]);
            gbox.DrawControl();
        }
Beispiel #5
0
        public void DrawTargetOnImages(ref Image img, ref TargetCoord[] targets, ref Graphics gs)
        {
            gs.DrawImage(img, picThumb.Bounds, 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);

            int tnum = targets.Length;

            double cx = 0, cy = 0;

            for (int i = 0; i < tnum; i++)
            {
                int cnum = targets[i].Corners.Length;
                PointF[] ncor = new PointF[cnum + 1];
                Pen lpen = new Pen(Color.Red, (float)1.5);

                cx = 0;
                cy = 0;

                for (int j = 0; j < cnum; j++)
                {
                    ncor[j] = new PointF(targets[i].Corners[j].X * picThumb.Width / img.Width,
                        targets[i].Corners[j].Y * picThumb.Height / img.Height);

                    cx += targets[i].Corners[j].X;
                    cy += targets[i].Corners[j].Y;
                }

                cx = cx / cnum;
                cy = cy / cnum;

                cx = cx * picThumb.Width / img.Width;
                cy = cy * picThumb.Height / img.Height;

                ncor[cnum] = new PointF(ncor[0].X, ncor[0].Y);
                gs.DrawLines(lpen, ncor);

                gs.DrawImage(m_Cursor, (float)(cx - m_Cursor.Width / 2), (float)(cy - m_Cursor.Height / 2),
                    (float)m_Cursor.Width, (float)m_Cursor.Height);

                lpen.Dispose();

            }

            gs.Dispose();
        }
Beispiel #6
0
        public void DrawOnTargets(int pnum, ref TargetCoord target, double ux, double uy, double rotat, double scale)
        {
            if (m_isInit)
                return;

            TargetGraph gbox = null;

            for (int i = 0; i < tpnlTargetArray.Controls.Count; i++)
            {

                gbox = (TargetGraph)tpnlTargetArray.Controls[i];

                if (gbox.GetID() == int.Parse(target.m_ID))
                {
                    gbox.SetDiffValue(ux, uy, scale, rotat);

                    /* UDP 서버 */

                    //사고 여부 판단. 각 타깃별로 판단할 수 있는 메서드에 선언 필요
                    bool accident = (ux >= m_TargetLimit || uy >= m_TargetLimit || rotat >= m_RotateLimit);

                    if (accident)
                    {
                        //if (m_WarnForm == null)
                        //{
                        //    m_WarnForm = new SoundForm();
                        //    m_WarnForm.Owner = this;
                        //    this.AddOwnedForm(m_WarnForm);
                        //    m_WarnForm.StartPosition = FormStartPosition.CenterScreen;
                        //    m_WarnForm.Owner = this;
                        //    //사진번호,발생이상,발생시간
                        //    m_SMS.msg = "Photometer 이상변위 발생! 현장긴급조사 필요. " + "카메라:" + i.ToString() + "번.";

                        //    if (ux >= m_TargetLimit)
                        //        m_SMS.msg = m_SMS.msg + "수평변위:" + string.Format("{0:0.000}m.", ux);
                        //    if (uy >= m_TargetLimit)
                        //        m_SMS.msg = m_SMS.msg + "수직변위:" + string.Format("{0:0.000}m.", uy);
                        //    if (rotat >= m_RotateLimit)
                        //        m_SMS.msg = m_SMS.msg + "회전량:" + string.Format("{0:0.000}도.", rotat);

                        //    m_WarnForm.Show();

                        //}
                    }

                    //// UDP 전송
                    //string dest_ip = "0.0.0.0";
                    //int dest_port = 0;

                    //// 설정 파일이 없으면 생성.
                    //if (!File.Exists(configPath))
                    //{
                    //    ServerConfiguration sc = new ServerConfiguration();
                    //    sc.ShowDialog();

                    //    dest_ip = sc.destIP;
                    //    dest_port = sc.destPort;

                    //    sc.Dispose();

                    //    MessageBox.Show(sc.destIP + "\n" + sc.destPort);

                    //    StreamWriter cf = File.CreateText(configPath);
                    //    cf.WriteLine(dest_ip);
                    //    cf.WriteLine(dest_port);
                    //    cf.Close();
                    //    cf.Dispose();
                    //}
                    //else
                    //{
                    //    StreamReader cf = File.OpenText(configPath);
                    //    dest_ip = cf.ReadLine().TrimEnd();
                    //    dest_port = int.Parse(cf.ReadLine().TrimEnd());
                    //    cf.Close();
                    //    cf.Dispose();
                    //}

                    //// UDP 데이터 전송 시작
                    //IPEndPoint ip = new IPEndPoint(IPAddress.Parse(dest_ip), dest_port);

                    //// SERVER
                    //Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                    ////for (int k = 0; k < targets.Length; k++)
                    ////{
                    //XElement xe =
                    //    new XElement("TARGETINFO",
                    //        new XAttribute("targets", TargetArrayPanels.Controls.Count),
                    //        new XAttribute("number", target.m_ID),
                    //        new XAttribute("ux", ux.ToString()),
                    //        new XAttribute("uy", uy.ToString()),
                    //        new XAttribute("accident", (accident ? "true" : "false"))
                    //        );

                    //string data = xe.ToString();

                    //server.SendTo(Encoding.UTF8.GetBytes(data), ip);
                    ////}

                    server.BroadcastTargets(NET_INFO_TARGETS, int.Parse(target.m_ID), ux, uy, rotat, scale);
                    gbox.DrawControl();
                    break;
                }
            }
        }
Beispiel #7
0
        public void DrawOnBox(int pnum, ref TargetCoord[] targets)
        {
            try
            {
                // pnum : 사진번호
                // targets : 사진상에 촬영된 타겟들의 정보

                int i = pnum;

                if (m_Images[i - 1] == null)
                    return;

                if (m_Images[i - 1].m_Targets == null)
                    return;

                int tnum = m_Images[i - 1].m_Targets.Length;

                // 변위량 계산결과 저장위치 - 최대변위
                double maxx = -1000, maxy = -1000;

                // 변위량 계산결과 저장위치 - 평균변위
                double evenx = 0, eveny = 0;

                // 형태변화량 계산결과 저장위치 - 최대축척
                double maxscale = -1000, maxang = -1000;
                double evenscale = 0, evenang = 0;

                int addednum = 0;

                //--현재의 인덱스 계산
                //int currnum = 0;

                /*
                for (int k = 0; k < tnum; k++)
                {
                    //현재 각 타깃에 저장되어 있는 좌표정보의 크기 중 최대수를 선정함
                    if (m_Images[i - 1].m_Targets[k].Arr.Count - 1 > currnum)
                        currnum = m_Images[i - 1].m_Targets[k].Arr.Count - 1;
                }
                */

                //--현재의 변위 계산 % 알고리즘 개선 부분
                for (int k = 0; k < tnum; k++)
                {
                    if (m_Images[i - 1].m_Targets[k] == null)
                        continue;
                    int currnum = m_Images[i - 1].m_Targets[k].Arr.Count;
                    if (currnum - 1 < 0) continue;
                    TargetCoord tg = (TargetCoord)(m_Images[i - 1].m_Targets[k].Arr[currnum - 1]);

                    //타겟의 코너정보 표시

                    //m_Images[i - 1].m_Targets[k].m_Corners
                    //tg.Corners

                    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(m_Images[i - 1].m_Targets[k].m_Corners[x].X, m_Images[i - 1].m_Targets[k].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);

                    if (m_isInit)
                        sx = sy = 0;
                    else
                    {
                        sx = sx * Math.Pow(m_TargetWidth / m_Images[i - 1].m_Targets[k].GetCornerWidth(), 2);
                        sy = sy * Math.Pow(m_TargetWidth / m_Images[i - 1].m_Targets[k].GetCornerWidth(), 2);
                    }

                    double scale = 0;

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

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

                    double diffx = Math.Abs(m_Images[i - 1].m_Targets[k].ix - tg.x);
                    double diffy = Math.Abs(m_Images[i - 1].m_Targets[k].iy - tg.y);

                    if (m_Images[i - 1].m_Targets[k].GetCornerWidth() == 0 || m_Images[i - 1].m_Targets[k].GetCornerHeight() == 0)
                        continue;

                    diffx = m_TargetWidth / m_Images[i - 1].m_Targets[k].GetCornerWidth() * diffx;
                    diffy = m_TargetHeight / m_Images[i - 1].m_Targets[k].GetCornerHeight() * diffy;


                    //중심변위계산 종료///////////////////


                    if (diffx > maxx) maxx = diffx;
                    if (diffy > maxy) maxy = diffy;
                    if (scale > maxscale) maxscale = scale;
                    if (ang > maxang) maxang = ang;



                    evenx += diffx;
                    eveny += diffy;
                    evenscale += scale;
                    evenang += ang;

                    addednum++;

                    //타깃별 그래프 갱신
                    if (i - 1 == m_SelCamNum)
                    {
                        DrawOnTargets(i - 1, ref tg, diffx, diffy, ang, scale);
                    }
                }

                if (addednum == 0)
                    return;

                evenx = evenx / addednum;
                eveny = eveny / addednum;
                evenscale = evenscale / addednum;
                evenang = evenang / addednum;

                DrawOnBoxGraph(ref pnum, ref targets, ref maxx, ref maxy, ref maxang, ref maxscale, ref evenx, ref eveny, ref evenang, ref evenscale);
            }
            catch (Exception ee)
            {
                MessageBox.Show("전반부 : " + ee.ToString());
            }
        }
Beispiel #8
0
        public int FindDBIndex(ref ImageDb idb, ref TargetCoord tg)
        {
            if (idb.m_Targets == null)
                return -1;

            for (int i = 0; i < idb.m_Targets.Length; i++)
            {
                if (idb.m_Targets[i] != null)
                    if (idb.m_Targets[i].m_ID == tg.m_ID)
                        return i;
            }

            return -1;
        }
Beispiel #9
0
        public void InitImageDb(int num, ref TargetCoord[] targets)
        {
            // 자료구조 생성
            try
            {
                num--;

                if (targets == null)
                {
                    m_ThreadCount--;
                    return;
                }

                if (targets.Length == 0)
                {
                    m_ThreadCount--;
                    return;
                }

                //초기값을 입력함
                if (m_ThreadCount == 0)
                {
                    if (targets != null)
                    {

                        int arrsize = targets.Length;

                        if (m_Images == null)
                            m_Images = new ImageDb[m_ClientsNum];

                        if (m_Images[num] == null)
                            m_Images[num] = new ImageDb();

                        //타겟 넘버링
                        for (int j = 0; j < arrsize; j++)
                        {
                            if (m_Images[num].m_Targets == null)
                            {
                                m_Images[num].m_Targets = new TargetDb[arrsize];
                            }
                            if (m_Images[num].m_Targets[j] == null)
                                m_Images[num].m_Targets[j] = new TargetDb();

                            m_Images[num].m_Targets[j] = new TargetDb();
                            m_Images[num].m_Targets[j].m_ID = targets[j].m_ID.ToString();
                            m_Images[num].m_Targets[j].Arr.Add(targets[j]);
                            m_Images[num].m_Targets[j].ix = targets[j].x;
                            m_Images[num].m_Targets[j].iy = targets[j].y;

                            for (int k = 0; k < 4; k++)
                            {
                                m_Images[num].m_Targets[j].m_Corners[k] = targets[j].Corners[k];
                            }
                        }
                    }
                    else
                    {
                        if (m_ThreadCount != 0)
                            m_ThreadCount = -1;
                    }
                }
                else
                {
                    //타겟 좌표 넣기
                    int arrsize = targets.Length;
                    if (m_Images == null)
                        m_Images = new ImageDb[m_ClientsNum];

                    if (m_Images[num] == null)
                        m_Images[num] = new ImageDb(arrsize);

                    if (m_Images[num].m_Targets == null)
                    {
                        m_Images[num].m_Targets = new TargetDb[arrsize];
                    }


                    //자리 만들기

                    if (m_Images == null)
                        m_Images = new ImageDb[m_ClientsNum];

                    if (m_Images[num] == null)
                        m_Images[num] = new ImageDb(arrsize);

                    for (int j = 0; j < arrsize; j++)
                    {
                        if (m_Images[num].m_Targets == null)
                        {
                            m_Images[num].m_Targets = new TargetDb[arrsize];
                        }

                    }

                    // 초기값 설정하기

                    int diff = arrsize - m_Images[num].m_Targets.Length;


                    for (int x = 0; x < arrsize; x++)
                    {

                        double xx = targets[x].x;
                        double yy = targets[x].y;

                        //int ttnum = FindTarget(ref m_Images[num], xx, yy);
                        int ttnum = FindTarget2(ref m_Images[num], ref targets[x]);

                        if (ttnum == -1)
                        {
                            Array.Resize<TargetDb>(ref m_Images[num].m_Targets, m_Images[num].m_Targets.Length + 1);
                            m_Images[num].m_Targets[m_Images[num].m_Targets.Length - 1] = new TargetDb();
                            m_Images[num].m_Targets[m_Images[num].m_Targets.Length - 1].m_ID = targets[x].m_ID;
                            m_Images[num].m_Targets[m_Images[num].m_Targets.Length - 1].Arr.Add(targets[x]);
                            m_Images[num].m_Targets[m_Images[num].m_Targets.Length - 1].ix = targets[x].x;
                            m_Images[num].m_Targets[m_Images[num].m_Targets.Length - 1].iy = targets[x].y;

                        }
                        else
                        {
                            //값 더하기

                            xx = targets[x].x;
                            yy = targets[x].y;

                            ttnum = FindDBIndex(ref m_Images[num], ref targets[x]);
                            if (ttnum != -1)
                                m_Images[num].m_Targets[ttnum].Arr.Add(targets[x]);

                        }

                    }

                    if (diff < 0)
                        m_ThreadCount--;

                }
            }
            catch (Exception ee)
            {
                MessageBox.Show("후반부" + ee.ToString());
            }
        }
Beispiel #10
0
        public void DrawImageToPanel2(ref Image ms, int i)
        {

            MonGraph gbox = (MonGraph)tpnlCamArray.Controls[i - 1];

            if (gbox == null)
                return;

            //캡쳐된 이미지 저장
            m_CapImg[i - 1] = ms;


            //폴더에 저장


            //영상분석 실시

            //BlobLabling

            ArrayList ar = new ArrayList(10);

            //순서나 위치 없이 타깃 경계선들을 추출함
            //IplImage cvimg = BlobLabling((Bitmap)m_CapImg[i - 1], ref ar);

            Bitmap timg = new Bitmap((Bitmap)m_CapImg[i - 1]);
            //Bitmap timg = (Bitmap)m_CapImg[i - 1];
            m_TG.SetImage(timg);
            m_TG.MarkerRecog();
            m_TG.ReleaseImage();
            timg.Dispose();

            TargetCoord[] targets = new TargetCoord[m_TG.TargetList.Count];

            // 타깃 기본정보 생성(중심점 좌표, 코너 좌표, 폭, 높이)
            for (int x = 0; x < m_TG.TargetList.Count; x++)
            {
                targets[x] = new TargetCoord();
                sMarkerInfo tg = (sMarkerInfo)m_TG.TargetList[x];
                //targets[x] = (TargetCoord)ar[x];
                targets[x].m_ID = tg.ID.ToString();
                for (int k = 0; k < 4; k++)
                {
                    targets[x].Corners[k] = tg.GetCornerCoord(k);
                }

                targets[x].x = tg.center.X;
                targets[x].y = tg.center.Y;

                ArrangeCorner(ref targets[x].Corners);

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

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

                targets[x].nWidth = l2;
                targets[x].nHeight = l1;

            }

            //패널에 이미지 그리기


            //이미지DB 업데이트

            if (m_isInit)//초기화 모드
            {
                InitImageDb(i, ref targets);
            }
            else if (m_isJustView)//단순 이미지 표시 모드
            {
                // 아무 분석작업도 수행하지 않음
            }
            else//일반관측모드-** 타깃DB 업데이트 하는 부분
            {
                //이미지파일 저장
                DateTime dt = DateTime.Now;

                string filepre = String.Format("{0:D2}-{1:D2}-{2:D2}.{3:D3}", dt.Hour, dt.Minute, dt.Second, dt.Millisecond);

                //m_CapImg[i - 1].Save(m_SaveFolder + "\\images\\" + filepre + "_" + i.ToString() + ".jpg");


                if (targets != null && m_FileWriter != null)
                {
                    int arrsize = targets.Length;
                    m_FileWriter[i - 1].WriteLine(String.Format("{0:D2}-{1:D2}-{2:D2}.{3:D3} : 타겟 수({4:D2})", dt.Hour, dt.Minute, dt.Second, dt.Millisecond, arrsize));

                    for (int j = 0; j < arrsize; j++)
                    {
                        if (targets[j] != null)
                        {
                            //double x = targets[j].x;
                            //double y = targets[j].y;

                            int ttnum = FindDBIndex(ref m_Images[i - 1], ref targets[j]);

                            if (ttnum != -1)
                            {
                                if (m_Images[i - 1].m_Targets[ttnum].Arr.Count > 1000)
                                    m_Images[i - 1].m_Targets[ttnum].Arr.Clear();

                                m_Images[i - 1].m_Targets[ttnum].Arr.Add(targets[j]);
                                m_FileWriter[i - 1].Write(m_Images[i - 1].m_Targets[ttnum].m_ID + " : ");

                                for (int k = 0; k < targets[j].Corners.Length; k++)
                                {
                                    m_FileWriter[i - 1].Write(String.Format("{0:0.00},{1:0.00} ", targets[j].Corners[k].X, targets[j].Corners[k].Y));
                                }

                                m_FileWriter[i - 1].WriteLine("");
                            }
                        }

                    }

                }
            }

            //분석 및 패널 업데이트
            if (!m_isJustView)
                DrawOnBox(i, ref targets);


            //중앙패널에 그리기
            if (i - 1 == m_SelCamNum)
            {
                //Image timg = cvimg.ToBitmap();
                DrawTargetOnImages(ref m_CapImg[i - 1], ref targets);
                //DrawOnTargets(i, ref targets);

            }
        }