コード例 #1
0
        public static IEnumerable <Rectangle> FindCandidateObjectLocations(
            Array2DBase image,
            MatrixRangeExp <double> kvals,
            uint minSize = 20,
            uint maxMergingIterations = 50)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            if (kvals == null)
            {
                throw new ArgumentNullException(nameof(kvals));
            }

            var array2DType = image.ImageType.ToNativeArray2DType();

            using (var dets = new VectorOfRectangle())
            {
                var ret = Native.find_candidate_object_locations(array2DType, image.NativePtr, dets.NativePtr, IntPtr.Zero, minSize, maxMergingIterations);
                if (ret == Native.ErrorType.ArrayTypeNotSupport)
                {
                    throw new ArgumentException($"{image.ImageType} is not supported.");
                }
                return(dets.ToArray());
            }
        }
コード例 #2
0
        public void CreateWithCollection()
        {
            const int size   = 10;
            var       source = Enumerable.Range(0, size).Select(i => new Rectangle(i, i, i, i));
            var       vector = new VectorOfRectangle(source);

            Assert.AreEqual(vector.Size, size);
            var ret = vector.ToArray();

            for (var i = 0; i < size; i++)
            {
                Assert.AreEqual(ret[i].Left, i);
                Assert.AreEqual(ret[i].Top, i);
                Assert.AreEqual(ret[i].Right, i);
                Assert.AreEqual(ret[i].Bottom, i);
            }
            this.DisposeAndCheckDisposedState(vector);
        }
コード例 #3
0
        public Rectangle[] Detect(Array2DBase image, double threshold = 0d)
        {
            this.ThrowIfDisposed();

            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            image.ThrowIfDisposed();

            using (var dets = new VectorOfRectangle())
            {
                var inType = image.ImageType.ToNativeArray2DType();
                var ret    = Native.frontal_face_detector_operator(this.NativePtr, inType, image.NativePtr, threshold, dets.NativePtr);
                switch (ret)
                {
                case Dlib.Native.ErrorType.InputArrayTypeNotSupport:
                    throw new ArgumentException($"Input {inType} is not supported.");
                }

                return(dets.ToArray());
            }
        }