/// <summary>
        ///
        /// Fit an ellipse to the points collection
        /// </summary>
        /// <param name="points">The points to be fitted</param>
        /// <returns>An ellipse</returns>
        public Ellipse EllipseLeastSquareFitting(AForge.Point[] points)
        {
            IntPtr   seq    = Marshal.AllocHGlobal(StructSize.MCvSeq);
            IntPtr   block  = Marshal.AllocHGlobal(StructSize.MCvSeqBlock);
            GCHandle handle = GCHandle.Alloc(points, GCHandleType.Pinned);

            CvInvoke.cvMakeSeqHeaderForArray(
                CvInvoke.CV_MAKETYPE((int)Emgu.CV.CvEnum.MAT_DEPTH.CV_32F, 2),
                StructSize.MCvSeq,
                StructSize.PointF,
                handle.AddrOfPinnedObject(),
                points.Length,
                seq,
                block);
            Ellipse e = new Ellipse(CvInvoke.cvFitEllipse2(seq));

            handle.Free();
            Marshal.FreeHGlobal(seq);
            Marshal.FreeHGlobal(block);

            //this version of Emgu Ellipse fitting has a bug and should be modified as below
            //and even after this modification, Box is smaller in a wrong angle
            Ellipse ModifiedEllipse = new Emgu.CV.Structure.Ellipse(e.MCvBox2D.center, new SizeF(e.MCvBox2D.size.Width, e.MCvBox2D.size.Height), e.MCvBox2D.angle - 90);

            return(ModifiedEllipse);
        }
Beispiel #2
0
        /// <summary>
        /// Create a GpuMat of the specified size
        /// </summary>
        /// <param name="rows">The number of rows (height)</param>
        /// <param name="cols">The number of columns (width)</param>
        /// <param name="channels">The number of channels</param>
        /// <param name="continuous">Indicates if the data should be continuous</param>
        public GpuMat(int rows, int cols, int channels, bool continuous)
        {
            int matType = CvInvoke.CV_MAKETYPE((int)CvToolbox.GetMatrixDepth(typeof(TDepth)), channels);

            if (continuous)
            {
                _ptr = GpuInvoke.GpuMatCreateContinuous(rows, cols, matType);
            }
            else
            {
                _ptr = GpuInvoke.GpuMatCreate(rows, cols, matType);
            }
        }
        //public static PointF[] ReduceNoise(PointF[] whitePoints, Image<Gray, byte> img)
        //{
        //    for (int i = 0; i < img.Width; i++)
        //    {
        //        for (int j = 0; j < img.Height; j++)
        //        {
        //            if()
        //        }
        //    }
        //}


        /// <summary>
        /// Fit an ellipse to the points collection
        /// </summary>
        /// <param name="points">The points to be fitted</param>
        /// <returns>An ellipse</returns>
        public static Ellipse EllipseLeastSquareFitting(PointF[] points)
        {
            IntPtr   seq    = Marshal.AllocHGlobal(StructSize.MCvSeq);
            IntPtr   block  = Marshal.AllocHGlobal(StructSize.MCvSeqBlock);
            GCHandle handle = GCHandle.Alloc(points, GCHandleType.Pinned);

            CvInvoke.cvMakeSeqHeaderForArray(
                CvInvoke.CV_MAKETYPE((int)MAT_DEPTH.CV_32F, 2),
                StructSize.MCvSeq,
                StructSize.PointF,
                handle.AddrOfPinnedObject(),
                points.Length,
                seq,
                block);
            Ellipse e = new Ellipse(CvInvoke.cvFitEllipse2(seq));

            handle.Free();
            Marshal.FreeHGlobal(seq);
            Marshal.FreeHGlobal(block);
            return(e);
        }
 static Tesseract()
 {
     //dummy code that is used to involve the static constructor of CvInvoke, if it has not already been called.
     CvInvoke.CV_MAKETYPE(0, 0);
 }
Beispiel #5
0
 /// <summary>
 /// Create a GpuMat of the specified size
 /// </summary>
 /// <param name="rows">The number of rows (height)</param>
 /// <param name="cols">The number of columns (width)</param>
 /// <param name="channels">The number of channels</param>
 public GpuMat(int rows, int cols, int channels)
 {
     _ptr = GpuInvoke.GpuMatCreate(rows, cols, CvInvoke.CV_MAKETYPE((int)CvToolbox.GetMatrixDepth(typeof(TDepth)), channels));
 }