示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="idx"></param>
        /// <param name="facetList"></param>
        /// <param name="facetCenters"></param>
        public void GetVoronoiFacetList(IEnumerable <int> idx, out Point2f[][] facetList, out Point2f[] facetCenters)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("Subdiv2D", "");
            }

            IntPtr facetListPtr, facetCentersPtr;

            if (idx == null)
            {
                NativeMethods.imgproc_Subdiv2D_getVoronoiFacetList(ptr, IntPtr.Zero, 0, out facetListPtr, out facetCentersPtr);
            }
            else
            {
                int[] idxArray = EnumerableEx.ToArray(idx);
                NativeMethods.imgproc_Subdiv2D_getVoronoiFacetList(ptr, idxArray, idxArray.Length, out facetListPtr, out facetCentersPtr);
            }

            using (VectorOfVectorPoint2f facetListVec = new VectorOfVectorPoint2f(facetListPtr))
            {
                facetList = facetListVec.ToArray();
            }
            using (VectorOfPoint2f facetCentersVec = new VectorOfPoint2f(facetCentersPtr))
            {
                facetCenters = facetCentersVec.ToArray();
            }
        }
示例#2
0
        /// <summary>
        /// computes sparse optical flow using multi-scale Lucas-Kanade algorithm
        /// </summary>
        /// <param name="prevImg"></param>
        /// <param name="nextImg"></param>
        /// <param name="prevPts"></param>
        /// <param name="nextPts"></param>
        /// <param name="status"></param>
        /// <param name="err"></param>
        /// <param name="winSize"></param>
        /// <param name="maxLevel"></param>
        /// <param name="criteria"></param>
        /// <param name="flags"></param>
        /// <param name="minEigThreshold"></param>
        public static void CalcOpticalFlowPyrLK(
            InputArray prevImg, InputArray nextImg,
            Point2f[] prevPts, ref Point2f[] nextPts,
            out byte[] status, out float[] err,
            Size?winSize           = null,
            int maxLevel           = 3,
            TermCriteria?criteria  = null,
            OpticalFlowFlags flags = OpticalFlowFlags.None,
            double minEigThreshold = 1e-4)
        {
            if (prevImg == null)
            {
                throw new ArgumentNullException("prevImg");
            }
            if (nextImg == null)
            {
                throw new ArgumentNullException("nextImg");
            }
            if (prevPts == null)
            {
                throw new ArgumentNullException("prevPts");
            }
            if (nextPts == null)
            {
                throw new ArgumentNullException("nextPts");
            }
            prevImg.ThrowIfDisposed();
            nextImg.ThrowIfDisposed();

            Size         winSize0  = winSize.GetValueOrDefault(new Size(21, 21));
            TermCriteria criteria0 = criteria.GetValueOrDefault(
                TermCriteria.Both(30, 0.01));

            using (var nextPtsVec = new VectorOfPoint2f())
                using (var statusVec = new VectorOfByte())
                    using (var errVec = new VectorOfFloat())
                    {
                        NativeMethods.video_calcOpticalFlowPyrLK_vector(
                            prevImg.CvPtr, nextImg.CvPtr, prevPts, prevPts.Length,
                            nextPtsVec.CvPtr, statusVec.CvPtr, errVec.CvPtr,
                            winSize0, maxLevel, criteria0, (int)flags, minEigThreshold);
                        nextPts = nextPtsVec.ToArray();
                        status  = statusVec.ToArray();
                        err     = errVec.ToArray();
                    }
        }