Esempio n. 1
0
        private void tmpDrawBoxes(ref IplImage gimg)
        {
            IplImage img8uc3 = new IplImage(gimg.Size, BitDepth.U8, 3);
            Cv.CvtColor(gimg, img8uc3, ColorConversion.GrayToBgr);

            int count = TargetList.Count;

            for (int i = 0; i < count; i++)
            {
                sMarkerInfo s = new sMarkerInfo();
                s = (sMarkerInfo)TargetList[i];

                Cv.DrawLine(img8uc3, new CvPoint((int)s.corner[0].X, (int)s.corner[0].Y), new CvPoint((int)s.corner[1].X, (int)s.corner[1].Y), Cv.RGB(255, 0, 0), 10);
                Cv.DrawLine(img8uc3, new CvPoint((int)s.corner[1].X, (int)s.corner[1].Y), new CvPoint((int)s.corner[2].X, (int)s.corner[2].Y), Cv.RGB(255, 0, 0), 10);
                Cv.DrawLine(img8uc3, new CvPoint((int)s.corner[2].X, (int)s.corner[2].Y), new CvPoint((int)s.corner[3].X, (int)s.corner[3].Y), Cv.RGB(255, 0, 0), 10);
                Cv.DrawLine(img8uc3, new CvPoint((int)s.corner[0].X, (int)s.corner[0].Y), new CvPoint((int)s.corner[3].X, (int)s.corner[3].Y), Cv.RGB(255, 0, 0), 10);

            }

            IplImage timg = new IplImage(new CvSize(800, 600), BitDepth.U8, 3);
            Cv.Resize(img8uc3, timg);
            Cv.ShowImage("contours", timg);
            img8uc3.ReleaseData();
            timg.ReleaseData();

            /*
             if (contours != null)
             {
                 Cv.DrawContours(img8uc3, contours, Cv.RGB(250, 0, 0), Cv.RGB(0, 0, 250), 1, 2, LineType.Link8);
             }
             IplImage timg = new IplImage(new CvSize(800, 600), BitDepth.U8, 3);
             Cv.Resize(img8uc3, timg);
             Cv.ShowImage("contours", timg);
             img8uc3.ReleaseData();
             timg.ReleaseData();
              * */
        }
Esempio n. 2
0
 private void tmpDrawContour(ref IplImage gimg, ref CvSeq<CvPoint> contours)
 {
     IplImage img8uc3 = new IplImage(gimg.Size, BitDepth.U8, 3);
     Cv.CvtColor(gimg, img8uc3, ColorConversion.GrayToBgr);
     if (contours != null)
     {
         Cv.DrawContours(img8uc3, contours, Cv.RGB(250, 0, 0), Cv.RGB(0, 0, 250), 1, 2, LineType.Link8);
     }
     IplImage timg = new IplImage(new CvSize(800, 600), BitDepth.U8, 3);
     Cv.Resize(img8uc3, timg);
     Cv.ShowImage("contours", timg);
     img8uc3.ReleaseData();
     timg.ReleaseData();
 }
Esempio n. 3
0
        public void MarkerRecog()
        {
            IplImage img_gray = new IplImage(imgSrc.Size, BitDepth.U8, 1);
            IplImage img_bin = new IplImage(img_gray.Size, BitDepth.U8, 1);

            Cv.CvtColor(imgSrc, img_gray, ColorConversion.BgrToGray);

            //추가부분 히스토그램 평활화
            Cv.EqualizeHist(img_gray, img_gray);

            //컬러영상을 흑백영상으로
            Cv.Copy(img_gray, img_bin);

            //트래시홀드
            Cv.AdaptiveThreshold(img_bin, img_bin, 255, AdaptiveThresholdType.MeanC, ThresholdType.BinaryInv, 11, 2);
            //Cv.AdaptiveThreshold(img_bin, img_bin, 255, AdaptiveThresholdType.MeanC, ThresholdType.BinaryInv, 71, 45);
            //Cv.AdaptiveThreshold(img_bin, img_bin, 255, AdaptiveThresholdType.MeanC, ThresholdType.BinaryInv, 301, 45);

            //개발 참고부분 - 이진영상 보기
            /*
            IplImage timg = new IplImage(new CvSize(800, 600), BitDepth.U8, 1);
            Cv.Resize(img_bin, timg);
            Cv.ShowImage("binimg", timg);
            timg.ReleaseData();
            */

            CvMemStorage storage = new CvMemStorage(0);
            CvMemStorage storage2 = new CvMemStorage(0);

            storage.Clear();
            CvSeq<CvPoint> contours;
            CvSeq<CvPoint> approxcontours;
            int ncontours = Cv.FindContours(img_bin, storage, out contours, CvContour.SizeOf, ContourRetrieval.Tree, ContourChain.ApproxSimple);

            TargetList.Clear();

            try
            {
                if (ncontours > 0)
                {
                    //검출된 contours 단순화하기
                    approxcontours = Cv.ApproxPoly(contours, CvContour.SizeOf, storage2, ApproxPolyMethod.DP, 1.0, true);

                    //개발자 참고용
                    //tmpDrawContour(ref img_gray, ref approxcontours);

                    if (approxcontours != null)
                    {
                        FindMarkerInContour(ref approxcontours, ref storage2);

                        //tmpDrawBoxes(ref img_gray);

                        GetMarkerCode(ref img_gray);

                        contours.ClearSeq();
                        approxcontours.ClearSeq();
                    }
                }
            }
            catch (Exception ee)
            {
                string msg = ee.Message;
            }

            Cv.ReleaseMemStorage(storage);
            Cv.ReleaseMemStorage(storage2);

            //storage.Dispose();
            img_gray.ReleaseData();
            img_bin.ReleaseData();
        }