Пример #1
0
        public Text()
        {
            // cvInitFont, cvPutText
            // フォントを初期化して,テキストを描画する

            List <FontFace> font_face = new List <FontFace>(
                (FontFace[])Enum.GetValues(typeof(FontFace))
                );

            font_face.Remove(FontFace.Italic);

            // (1)画像を確保し初期化する
            using (IplImage img = Cv.CreateImage(new CvSize(450, 600), BitDepth.U8, 3))
            {
                Cv.Zero(img);
                // (2)フォント構造体を初期化する
                CvFont[] font = new CvFont[font_face.Count * 2];
                for (int i = 0; i < font.Length; i += 2)
                {
                    font[i]     = new CvFont(font_face[i / 2], 1.0, 1.0);
                    font[i + 1] = new CvFont(font_face[i / 2] | FontFace.Italic, 1.0, 1.0);
                }
                // (3)フォントを指定して,テキストを描画する
                for (int i = 0; i < font.Length; i++)
                {
                    CvColor rcolor = CvColor.Random();
                    Cv.PutText(img, "OpenCV sample code", new CvPoint(15, (i + 1) * 30), font[i], rcolor);
                }
                // (4)画像の表示,キーが押されたときに終了
                using (CvWindow w = new CvWindow(img))
                {
                    CvWindow.WaitKey(0);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Extracts MSER by C++-style code (cv::MSER)
        /// </summary>
        /// <param name="gray"></param>
        /// <param name="dst"></param>
        private void CppStyleMSER(Mat gray, Mat dst)
        {
            MSER mser = new MSER();

            Point[][] contours = mser.Run(gray, null);     // operator()
            foreach (Point[] pts in contours)
            {
                CvColor color = CvColor.Random();
                foreach (Point p in pts)
                {
                    dst.Circle(p, 1, color);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Extracts MSER by C-style code (cvExtractMSER)
        /// </summary>
        /// <param name="imgGray"></param>
        /// <param name="imgDst"></param>
        private void CStyleMSER(IplImage imgGray, IplImage imgDst)
        {
            using (CvMemStorage storage = new CvMemStorage())
            {
                CvContour[]  contours;
                CvMSERParams param = new CvMSERParams();
                Cv.ExtractMSER(imgGray, null, out contours, storage, param);

                foreach (CvContour c in contours)
                {
                    CvColor color = CvColor.Random();
                    for (int i = 0; i < c.Total; i++)
                    {
                        imgDst.Circle(c[i].Value, 1, color);
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="img"></param>
        /// <param name="edge"></param>
        private void DrawSubdivFacet(IplImage img, CvSubdiv2DEdge edge)
        {
            CvSubdiv2DEdge t     = edge;
            int            count = 0;

            // count number of edges in facet
            do
            {
                count++;
                t = t.GetEdge(CvNextEdgeType.NextAroundLeft);
            } while (t != edge);

            CvPoint[] buf = new CvPoint[count];

            // gather points
            t = edge;
            int i;

            for (i = 0; i < count; i++)
            {
                CvSubdiv2DPoint pt = t.Org();
                if (pt == null)
                {
                    break;
                }
                buf[i] = pt.Pt;
                t      = t.GetEdge(CvNextEdgeType.NextAroundLeft);
            }

            if (i == count)
            {
                Random          rand = new Random();
                CvSubdiv2DPoint pt   = edge.RotateEdge(RotateEdgeFlag.Rotate).Dst();
                img.FillConvexPoly(buf, CvColor.Random(), LineType.AntiAlias, 0);
                img.PolyLine(new CvPoint[][] { buf }, true, CvColor.Black, 1, LineType.AntiAlias, 0);
                DrawSubdivPoint(img, pt.Pt, CvColor.Black);
            }
        }