Ejemplo n.º 1
0
        /// <summary>
        /// Decodes QR code in image once it's found by the detect() method.
        /// Returns UTF8-encoded output string or empty string if the code cannot be decoded.
        /// </summary>
        /// <param name="img">grayscale or color (BGR) image containing QR code.</param>
        /// <param name="points">Quadrangle vertices found by detect() method (or some other algorithm).</param>
        /// <param name="straightQrCode">The optional output image containing rectified and binarized QR code</param>
        /// <returns></returns>
        public string Decode(InputArray img, IEnumerable <Point2f> points, OutputArray?straightQrCode = null)
        {
            if (img == null)
            {
                throw new ArgumentNullException(nameof(img));
            }
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points));
            }
            img.ThrowIfDisposed();
            straightQrCode?.ThrowIfNotReady();

            using var pointsVec    = new VectorOfPoint2f(points);
            using var resultString = new StdString();
            NativeMethods.HandleException(
                NativeMethods.objdetect_QRCodeDetector_decode(
                    ptr, img.CvPtr, pointsVec.CvPtr, Cv2.ToPtr(straightQrCode), resultString.CvPtr));

            GC.KeepAlive(img);
            GC.KeepAlive(points);
            GC.KeepAlive(straightQrCode);
            GC.KeepAlive(this);

            return(resultString.ToString());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Estimates Gaussian mixture parameters from the sample set
        /// </summary>
        /// <param name="samples"></param>
        /// <param name="logLikelihoods"></param>
        /// <param name="labels"></param>
        /// <param name="probs"></param>
        /// <returns></returns>
        public virtual bool TrainEM(
            InputArray samples,
            OutputArray logLikelihoods = null,
            OutputArray labels         = null,
            OutputArray probs          = null)
        {
            ThrowIfDisposed();
            if (samples == null)
            {
                throw new ArgumentNullException(nameof(samples));
            }
            samples.ThrowIfDisposed();

            logLikelihoods?.ThrowIfNotReady();
            labels?.ThrowIfNotReady();
            probs?.ThrowIfNotReady();

            int ret = NativeMethods.ml_EM_trainEM(
                ptr,
                samples.CvPtr,
                Cv2.ToPtr(logLikelihoods),
                Cv2.ToPtr(labels),
                Cv2.ToPtr(probs));

            logLikelihoods?.Fix();
            labels?.Fix();
            probs?.Fix();
            GC.KeepAlive(this);
            GC.KeepAlive(samples);
            GC.KeepAlive(logLikelihoods);
            GC.KeepAlive(labels);
            GC.KeepAlive(probs);
            return(ret != 0);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// find template on image
        /// </summary>
        /// <param name="image"></param>
        /// <param name="positions"></param>
        /// <param name="votes"></param>
        public virtual void Detect(
            InputArray image, OutputArray positions, OutputArray?votes = null)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            if (positions == null)
            {
                throw new ArgumentNullException(nameof(positions));
            }
            image.ThrowIfDisposed();
            positions.ThrowIfNotReady();
            votes?.ThrowIfNotReady();

            NativeMethods.HandleException(
                NativeMethods.imgproc_GeneralizedHough_detect1(
                    ptr, image.CvPtr, positions.CvPtr, Cv2.ToPtr(votes)));

            GC.KeepAlive(this);
            GC.KeepAlive(image);
            GC.KeepAlive(positions);
            GC.KeepAlive(votes);
            positions.Fix();
            votes?.Fix();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Both detects and decodes QR code
        /// </summary>
        /// <param name="img">grayscale or color (BGR) image containing QR code.</param>
        /// <param name="points">opiotnal output array of vertices of the found QR code quadrangle. Will be empty if not found.</param>
        /// <param name="straightQrcode">The optional output image containing rectified and binarized QR code</param>
        /// <returns></returns>
        public string DetectAndDecode(InputArray img, out Point2f[] points, OutputArray straightQrcode = null)
        {
            if (img == null)
            {
                throw new ArgumentNullException(nameof(img));
            }
            img.ThrowIfDisposed();
            straightQrcode?.ThrowIfNotReady();

            string result;

            using (var pointsVec = new VectorOfPoint2f())
                using (var resultString = new StdString())
                {
                    NativeMethods.objdetect_QRCodeDetector_detectAndDecode(
                        ptr, img.CvPtr, pointsVec.CvPtr, Cv2.ToPtr(straightQrcode), resultString.CvPtr);
                    points = pointsVec.ToArray();
                    result = resultString.ToString();
                }

            GC.KeepAlive(img);
            GC.KeepAlive(straightQrcode);
            GC.KeepAlive(this);

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Finds lines in the input image.
        /// This is the output of the default parameters of the algorithm on the above shown image.
        /// </summary>
        /// <param name="image">A grayscale (CV_8UC1) input image. </param>
        /// <param name="lines">A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line.
        /// Where Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly oriented depending on the gradient.</param>
        /// <param name="width">Vector of widths of the regions, where the lines are found. E.g. Width of line.</param>
        /// <param name="prec">Vector of precisions with which the lines are found.</param>
        /// <param name="nfa">Vector containing number of false alarms in the line region,
        /// with precision of 10%. The bigger the value, logarithmically better the detection.</param>
        public virtual void Detect(InputArray image, OutputArray lines,
                                   OutputArray width = null, OutputArray prec = null, OutputArray nfa = null)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            if (lines == null)
            {
                throw new ArgumentNullException(nameof(lines));
            }
            image.ThrowIfDisposed();
            lines.ThrowIfNotReady();
            width?.ThrowIfNotReady();
            prec?.ThrowIfNotReady();
            nfa?.ThrowIfNotReady();

            NativeMethods.imgproc_LineSegmentDetector_detect_OutputArray(ptr, image.CvPtr, lines.CvPtr,
                                                                         Cv2.ToPtr(width), Cv2.ToPtr(prec), Cv2.ToPtr(nfa));

            GC.KeepAlive(image);
            lines.Fix();
            width?.Fix();
            prec?.Fix();
            nfa?.Fix();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="frame0"></param>
        /// <param name="frame1"></param>
        /// <param name="flow1"></param>
        /// <param name="flow2"></param>
        public virtual void Calc(InputArray frame0, InputArray frame1, OutputArray flow1, OutputArray flow2 = null)
        {
            if (frame0 == null)
            {
                throw new ArgumentNullException(nameof(frame0));
            }
            if (frame1 == null)
            {
                throw new ArgumentNullException(nameof(frame1));
            }
            if (flow1 == null)
            {
                throw new ArgumentNullException(nameof(flow1));
            }
            frame0.ThrowIfDisposed();
            frame1.ThrowIfDisposed();
            flow1.ThrowIfNotReady();
            flow2?.ThrowIfNotReady();

            NativeMethods.superres_DenseOpticalFlowExt_calc(
                ptr, frame0.CvPtr, frame1.CvPtr, flow1.CvPtr, Cv2.ToPtr(flow2));
            GC.KeepAlive(this);
            GC.KeepAlive(frame0);
            GC.KeepAlive(frame1);
            GC.KeepAlive(flow1);
            GC.KeepAlive(flow2);
            flow1.Fix();
            flow2?.Fix();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Estimate the Gaussian mixture parameters from a samples set.
        /// </summary>
        /// <param name="samples">Samples from which the Gaussian mixture model will be estimated. It should be a
        /// one-channel matrix, each row of which is a sample. If the matrix does not have CV_64F type
        /// it will be converted to the inner matrix of such type for the further computing.</param>
        /// <param name="means0">Initial means \f$a_k\f$ of mixture components. It is a one-channel matrix of
        /// \f$nclusters \times dims\f$ size. If the matrix does not have CV_64F type it will be
        /// converted to the inner matrix of such type for the further computing.</param>
        /// <param name="covs0">The vector of initial covariance matrices \f$S_k\f$ of mixture components. Each of
        /// covariance matrices is a one-channel matrix of \f$dims \times dims\f$ size. If the matrices
        /// do not have CV_64F type they will be converted to the inner matrices of such type for the further computing.</param>
        /// <param name="weights0">Initial weights \f$\pi_k\f$ of mixture components. It should be a one-channel
        /// floating-point matrix with \f$1 \times nclusters\f$ or \f$nclusters \times 1\f$ size.</param>
        /// <param name="logLikelihoods">The optional output matrix that contains a likelihood logarithm value for
        /// each sample. It has \f$nsamples \times 1\f$ size and CV_64FC1 type.</param>
        /// <param name="labels">The optional output "class label" for each sample:
        /// \f$\texttt{labels}_i=\texttt{arg max}_k(p_{i,k}), i=1..N\f$ (indices of the most probable
        /// mixture component for each sample). It has \f$nsamples \times 1\f$ size and CV_32SC1 type.</param>
        /// <param name="probs">The optional output matrix that contains posterior probabilities of each Gaussian
        /// mixture component given the each sample. It has \f$nsamples \times nclusters\f$ size and CV_64FC1 type.</param>
        public virtual bool TrainE(
            InputArray samples,
            InputArray means0,
            InputArray?covs0           = null,
            InputArray?weights0        = null,
            OutputArray?logLikelihoods = null,
            OutputArray?labels         = null,
            OutputArray?probs          = null)
        {
            ThrowIfDisposed();
            if (samples == null)
            {
                throw new ArgumentNullException(nameof(samples));
            }
            if (means0 == null)
            {
                throw new ArgumentNullException(nameof(means0));
            }
            samples.ThrowIfDisposed();
            means0.ThrowIfDisposed();

            logLikelihoods?.ThrowIfNotReady();
            covs0?.ThrowIfDisposed();
            weights0?.ThrowIfDisposed();
            labels?.ThrowIfNotReady();
            probs?.ThrowIfNotReady();

            NativeMethods.HandleException(
                NativeMethods.ml_EM_trainE(
                    ptr,
                    samples.CvPtr,
                    means0.CvPtr,
                    Cv2.ToPtr(covs0),
                    Cv2.ToPtr(weights0),
                    Cv2.ToPtr(logLikelihoods),
                    Cv2.ToPtr(labels),
                    Cv2.ToPtr(probs),
                    out var ret));

            logLikelihoods?.Fix();
            labels?.Fix();
            probs?.Fix();
            GC.KeepAlive(this);
            GC.KeepAlive(samples);
            GC.KeepAlive(means0);
            GC.KeepAlive(covs0);
            GC.KeepAlive(weights0);
            GC.KeepAlive(logLikelihoods);
            GC.KeepAlive(labels);
            GC.KeepAlive(probs);
            return(ret != 0);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// サンプルに対する応答を予測する
        /// </summary>
        /// <param name="sample"></param>
        /// <param name="probs"></param>
#else
        /// <summary>
        /// Predicts the response for sample
        /// </summary>
        /// <param name="sample"></param>
        /// <param name="probs"></param>
#endif
        public virtual Vec2d Predict2(InputArray sample, OutputArray probs = null)
        {
            ThrowIfDisposed();
            if (sample == null)
            {
                throw new ArgumentNullException(nameof(sample));
            }
            sample.ThrowIfDisposed();
            probs?.ThrowIfNotReady();

            Vec2d ret = NativeMethods.ml_EM_predict2(ptr, sample.CvPtr, Cv2.ToPtr(probs));

            probs?.Fix();
            GC.KeepAlive(sample);
            return(ret);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// find template on image
        /// </summary>
        /// <param name="edges"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="positions"></param>
        /// <param name="votes"></param>
        public virtual void Detect(
            InputArray edges, InputArray dx, InputArray dy, OutputArray positions, OutputArray?votes = null)
        {
            if (edges == null)
            {
                throw new ArgumentNullException(nameof(edges));
            }
            if (dx == null)
            {
                throw new ArgumentNullException(nameof(dx));
            }
            if (dy == null)
            {
                throw new ArgumentNullException(nameof(dy));
            }
            if (positions == null)
            {
                throw new ArgumentNullException(nameof(positions));
            }
            edges.ThrowIfDisposed();
            dx.ThrowIfDisposed();
            dy.ThrowIfDisposed();
            positions.ThrowIfNotReady();
            votes?.ThrowIfNotReady();

            NativeMethods.HandleException(
                NativeMethods.imgproc_GeneralizedHough_detect2(
                    ptr, edges.CvPtr, dx.CvPtr, dy.CvPtr, positions.CvPtr, Cv2.ToPtr(votes)));

            GC.KeepAlive(this);
            GC.KeepAlive(edges);
            GC.KeepAlive(dx);
            GC.KeepAlive(dy);
            GC.KeepAlive(positions);
            GC.KeepAlive(votes);
            positions.Fix();
            votes?.Fix();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Given an original color image, two differently colored versions of this
        /// image can be mixed seamlessly. Multiplication factor is between 0.5 to 2.5.
        /// </summary>
        /// <param name="src">Input 8-bit 3-channel image.</param>
        /// <param name="mask">Input 8-bit 1 or 3-channel image.</param>
        /// <param name="dst">Output image with the same size and type as src.</param>
        /// <param name="redMul">R-channel multiply factor.</param>
        /// <param name="greenMul">G-channel multiply factor.</param>
        /// <param name="blueMul">B-channel multiply factor.</param>
        public static void ColorChange(
            InputArray src, InputArray mask, OutputArray dst,
            float redMul = 1.0f, float greenMul = 1.0f, float blueMul = 1.0f)
        {
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfNotReady();
            mask?.ThrowIfDisposed();

            NativeMethods.photo_colorChange(
                src.CvPtr, ToPtr(mask), dst.CvPtr, redMul, greenMul, blueMul);

            GC.KeepAlive(src);
            GC.KeepAlive(mask);
            dst.Fix();
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Transforms a color image to a grayscale image. It is a basic tool in digital
 /// printing, stylized black-and-white photograph rendering, and in many single
 /// channel image processing applications @cite CL12 .
 /// </summary>
 /// <param name="src">Input 8-bit 3-channel image.</param>
 /// <param name="grayscale">Output 8-bit 1-channel image.</param>
 /// <param name="colorBoost">Output 8-bit 3-channel image.</param>
 public static void Decolor(
     InputArray src, OutputArray grayscale, OutputArray colorBoost)
 {
     if (src == null)
     {
         throw new ArgumentNullException(nameof(src));
     }
     if (grayscale == null)
     {
         throw new ArgumentNullException(nameof(grayscale));
     }
     if (colorBoost == null)
     {
         throw new ArgumentNullException(nameof(colorBoost));
     }
     src.ThrowIfDisposed();
     grayscale.ThrowIfNotReady();
     colorBoost.ThrowIfNotReady();
     NativeMethods.photo_decolor(src.CvPtr, grayscale.CvPtr, colorBoost.CvPtr);
     GC.KeepAlive(src);
     grayscale.Fix();
     colorBoost.Fix();
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Filtering is the fundamental operation in image and video processing.
        /// Edge-preserving smoothing filters are used in many different applications @cite EM11 .
        /// </summary>
        /// <param name="src">Input 8-bit 3-channel image.</param>
        /// <param name="dst">Output 8-bit 3-channel image.</param>
        /// <param name="flags">Edge preserving filters</param>
        /// <param name="sigmaS">Range between 0 to 200.</param>
        /// <param name="sigmaR">Range between 0 to 1.</param>
        public static void EdgePreservingFilter(
            InputArray src, OutputArray dst,
            EdgePreservingMethods flags = EdgePreservingMethods.RecursFilter,
            float sigmaS = 60, float sigmaR = 0.4f)
        {
            if (src == null)
            {
                throw new ArgumentNullException("nameof(src)");
            }
            if (dst == null)
            {
                throw new ArgumentNullException("nameof(dst)");
            }

            src.ThrowIfDisposed();
            dst.ThrowIfNotReady();

            NativeMethods.photo_edgePreservingFilter(
                src.CvPtr, dst.CvPtr, (int)flags, sigmaS, sigmaR);

            GC.KeepAlive(src);
            dst.Fix();
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Try to stitch the given images.
        /// </summary>
        /// <param name="images">Input images.</param>
        /// <param name="pano">Final pano.</param>
        /// <returns>Status code.</returns>
        public Status Stitch(InputArray images, OutputArray pano)
        {
            if (images == null)
            {
                throw new ArgumentNullException(nameof(images));
            }
            if (pano == null)
            {
                throw new ArgumentNullException(nameof(pano));
            }
            images.ThrowIfDisposed();
            pano.ThrowIfNotReady();

            Status status = (Status)NativeMethods.stitching_Stitcher_stitch1_InputArray(
                ptr, images.CvPtr, pano.CvPtr);

            GC.KeepAlive(this);
            GC.KeepAlive(images);
            GC.KeepAlive(pano);
            pano.Fix();

            return(status);
        }
        /// <summary>
        /// Get the images that correspond to each shape.
        /// This images are used in the calculation of the Image Appearance cost.
        /// </summary>
        /// <param name="image1">Image corresponding to the shape defined by contours1.</param>
        /// <param name="image2">Image corresponding to the shape defined by contours2.</param>
        public void GetImages(OutputArray image1, OutputArray image2)
        {
            ThrowIfDisposed();
            if (image1 == null)
            {
                throw new ArgumentNullException(nameof(image1));
            }
            if (image2 == null)
            {
                throw new ArgumentNullException(nameof(image2));
            }
            image1.ThrowIfNotReady();
            image2.ThrowIfNotReady();

            NativeMethods.HandleException(
                NativeMethods.shape_ShapeContextDistanceExtractor_getImages(ptr, image1.CvPtr, image2.CvPtr));

            image1.Fix();
            image2.Fix();
            GC.KeepAlive(this);
            GC.KeepAlive(image1);
            GC.KeepAlive(image2);
        }
Ejemplo n.º 15
0
        public Status ComposePanorama(InputArray images, OutputArray pano)
        {
            if (images == null)
            {
                throw new ArgumentNullException(nameof(images));
            }
            if (pano == null)
            {
                throw new ArgumentNullException(nameof(pano));
            }
            images.ThrowIfDisposed();
            pano.ThrowIfNotReady();

            NativeMethods.HandleException(
                NativeMethods.stitching_Stitcher_composePanorama2_InputArray(
                    ptr, images.CvPtr, pano.CvPtr, out var ret));

            pano.Fix();
            GC.KeepAlive(this);
            GC.KeepAlive(images);
            GC.KeepAlive(pano);
            return((Status)ret);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Computes disparity map for the specified stereo pair
 /// </summary>
 /// <param name="left">Left 8-bit single-channel image.</param>
 /// <param name="right">Right image of the same size and the same type as the left one.</param>
 /// <param name="disparity">Output disparity map. It has the same size as the input images. Some algorithms,
 /// like StereoBM or StereoSGBM compute 16-bit fixed-point disparity map(where each disparity value has 4 fractional bits),
 /// whereas other algorithms output 32 - bit floating - point disparity map.</param>
 public virtual void Compute(InputArray left, InputArray right, OutputArray disparity)
 {
     if (left == null)
     {
         throw new ArgumentNullException(nameof(left));
     }
     if (right == null)
     {
         throw new ArgumentNullException(nameof(right));
     }
     if (disparity == null)
     {
         throw new ArgumentNullException(nameof(disparity));
     }
     left.ThrowIfDisposed();
     right.ThrowIfDisposed();
     disparity.ThrowIfNotReady();
     NativeMethods.calib3d_StereoMatcher_compute(ptr, left.CvPtr, right.CvPtr, disparity.CvPtr);
     GC.KeepAlive(this);
     GC.KeepAlive(left);
     GC.KeepAlive(right);
     disparity.Fix();
 }
Ejemplo n.º 17
0
 /// <summary>
 /// restores the damaged image areas using one of the available intpainting algorithms
 /// </summary>
 /// <param name="src"></param>
 /// <param name="inpaintMask"></param>
 /// <param name="dst"></param>
 /// <param name="inpaintRadius"></param>
 /// <param name="flags"></param>
 public static void Inpaint(InputArray src, InputArray inpaintMask,
                            OutputArray dst, double inpaintRadius, InpaintMethod flags)
 {
     if (src == null)
     {
         throw new ArgumentNullException(nameof(src));
     }
     if (inpaintMask == null)
     {
         throw new ArgumentNullException(nameof(inpaintMask));
     }
     if (dst == null)
     {
         throw new ArgumentNullException(nameof(dst));
     }
     src.ThrowIfDisposed();
     inpaintMask.ThrowIfDisposed();
     dst.ThrowIfNotReady();
     NativeMethods.photo_inpaint(src.CvPtr, inpaintMask.CvPtr, dst.CvPtr, inpaintRadius, (int)flags);
     dst.Fix();
     GC.KeepAlive(src);
     GC.KeepAlive(inpaintMask);
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Stylization aims to produce digital imagery with a wide variety of effects
        /// not focused on photorealism. Edge-aware filters are ideal for stylization,
        /// as they can abstract regions of low contrast while preserving, or enhancing,
        /// high-contrast features.
        /// </summary>
        /// <param name="src">Input 8-bit 3-channel image.</param>
        /// <param name="dst">Output image with the same size and type as src.</param>
        /// <param name="sigmaS">Range between 0 to 200.</param>
        /// <param name="sigmaR">Range between 0 to 1.</param>
        public static void Stylization(
            InputArray src, OutputArray dst,
            float sigmaS = 60, float sigmaR = 0.45f)
        {
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }

            src.ThrowIfDisposed();
            dst.ThrowIfNotReady();

            NativeMethods.HandleException(
                NativeMethods.photo_stylization(
                    src.CvPtr, dst.CvPtr, sigmaS, sigmaR));

            GC.KeepAlive(src);
            dst.Fix();
        }
Ejemplo n.º 19
0
 /// <summary>
 /// performs back substitution
 /// </summary>
 /// <param name="w"></param>
 /// <param name="u"></param>
 /// <param name="vt"></param>
 /// <param name="rhs"></param>
 /// <param name="dst"></param>
 public static void BackSubst(InputArray w, InputArray u,
                              InputArray vt, InputArray rhs, OutputArray dst)
 {
     if (w == null)
     {
         throw new ArgumentNullException(nameof(w));
     }
     if (u == null)
     {
         throw new ArgumentNullException(nameof(u));
     }
     if (vt == null)
     {
         throw new ArgumentNullException(nameof(vt));
     }
     if (rhs == null)
     {
         throw new ArgumentNullException(nameof(rhs));
     }
     if (dst == null)
     {
         throw new ArgumentNullException(nameof(dst));
     }
     w.ThrowIfDisposed();
     u.ThrowIfDisposed();
     vt.ThrowIfDisposed();
     rhs.ThrowIfDisposed();
     dst.ThrowIfNotReady();
     NativeMethods.HandleException(
         NativeMethods.core_SVD_static_backSubst(w.CvPtr, u.CvPtr, vt.CvPtr, rhs.CvPtr, dst.CvPtr));
     dst.Fix();
     GC.KeepAlive(w);
     GC.KeepAlive(u);
     GC.KeepAlive(vt);
     GC.KeepAlive(rhs);
     GC.KeepAlive(dst);
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Splits a motion history image into a few parts corresponding to separate independent motions
        /// (for example, left hand, right hand).
        /// </summary>
        /// <param name="mhi">Motion history image.</param>
        /// <param name="segmask">Image where the found mask should be stored, single-channel, 32-bit floating-point.</param>
        /// <param name="boundingRects">Vector containing ROIs of motion connected components.</param>
        /// <param name="timestamp">Current time in milliseconds or other units.</param>
        /// <param name="segThresh">Segmentation threshold that is recommended to be equal to the interval between motion history “steps” or greater.</param>
        public static void SegmentMotion(
            InputArray mhi, OutputArray segmask,
            out Rect[] boundingRects,
            double timestamp, double segThresh)
        {
            if (mhi == null)
            {
                throw new ArgumentNullException("nameof(mhi)");
            }
            if (segmask == null)
            {
                throw new ArgumentNullException("nameof(segmask)");
            }
            mhi.ThrowIfDisposed();
            segmask.ThrowIfNotReady();

            using (var br = new VectorOfRect())
            {
                NativeMethods.optflow_motempl_segmentMotion(
                    mhi.CvPtr, segmask.CvPtr, br.CvPtr, timestamp, segThresh);
                boundingRects = br.ToArray();
            }
            segmask.Fix();
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Calculates 2D Fast Hough transform of an image.
        /// </summary>
        /// <param name="src">The source (input) image.</param>
        /// <param name="dst">The destination image, result of transformation.</param>
        /// <param name="dstMatDepth">The depth of destination image</param>
        /// <param name="angleRange">The part of Hough space to calculate, see cv::AngleRangeOption</param>
        /// <param name="op">The operation to be applied, see cv::HoughOp</param>
        /// <param name="makeSkew">Specifies to do or not to do image skewing, see cv::HoughDeskewOption</param>
        public static void FastHoughTransform(
            InputArray src,
            OutputArray dst,
            MatType dstMatDepth,
            AngleRangeOption angleRange = AngleRangeOption.ARO_315_135,
            HoughOP op = HoughOP.FHT_ADD,
            HoughDeskewOption makeSkew = HoughDeskewOption.DESKEW)
        {
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            src.ThrowIfDisposed();
            dst.ThrowIfNotReady();

            NativeMethods.ximgproc_FastHoughTransform(src.CvPtr, dst.CvPtr, dstMatDepth, (int)angleRange, (int)op, (int)makeSkew);

            GC.KeepAlive(src);
            dst.Fix();
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Modification of fastNlMeansDenoisingMulti function for colored images sequences
        /// </summary>
        /// <param name="srcImgs">Input 8-bit 3-channel images sequence. All images should have the same type and size.</param>
        /// <param name="dst">Output image with the same size and type as srcImgs images.</param>
        /// <param name="imgToDenoiseIndex">Target image to denoise index in srcImgs sequence</param>
        /// <param name="temporalWindowSize">Number of surrounding images to use for target image denoising. Should be odd.
        /// Images from imgToDenoiseIndex - temporalWindowSize / 2 to imgToDenoiseIndex - temporalWindowSize / 2 from srcImgs
        /// will be used to denoise srcImgs[imgToDenoiseIndex] image.</param>
        /// <param name="h">Parameter regulating filter strength for luminance component. Bigger h value perfectly removes noise
        /// but also removes image details, smaller h value preserves details but also preserves some noise.</param>
        /// <param name="hColor"> The same as h but for color components.</param>
        /// <param name="templateWindowSize">Size in pixels of the template patch that is used to compute weights. Should be odd. Recommended value 7 pixels</param>
        /// <param name="searchWindowSize">Size in pixels of the window that is used to compute weighted average for given pixel.
        /// Should be odd. Affect performance linearly: greater searchWindowsSize - greater denoising time. Recommended value 21 pixels</param>
        public static void FastNlMeansDenoisingColoredMulti(
            IEnumerable <InputArray> srcImgs, OutputArray dst,
            int imgToDenoiseIndex, int temporalWindowSize, float h = 3, float hColor = 3,
            int templateWindowSize = 7, int searchWindowSize = 21)
        {
            if (srcImgs == null)
            {
                throw new ArgumentNullException(nameof(srcImgs));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            dst.ThrowIfNotReady();
            var srcImgPtrs = srcImgs.Select(x => x.CvPtr).ToArray();

            NativeMethods.HandleException(
                NativeMethods.photo_fastNlMeansDenoisingColoredMulti(
                    srcImgPtrs, srcImgPtrs.Length, dst.CvPtr, imgToDenoiseIndex,
                    temporalWindowSize, h, hColor, templateWindowSize, searchWindowSize));

            dst.Fix();
            GC.KeepAlive(srcImgs);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Applying an appropriate non-linear transformation to the gradient field inside
        /// the selection and then integrating back with a Poisson solver, modifies locally
        /// the apparent illumination of an image.
        /// </summary>
        /// <param name="src">Input 8-bit 3-channel image.</param>
        /// <param name="mask">Input 8-bit 1 or 3-channel image.</param>
        /// <param name="dst">Output image with the same size and type as src.</param>
        /// <param name="alpha">Value ranges between 0-2.</param>
        /// <param name="beta">Value ranges between 0-2.</param>
        /// <remarks>
        /// This is useful to highlight under-exposed foreground objects or to reduce specular reflections.
        /// </remarks>
        public static void IlluminationChange(
            InputArray src, InputArray mask, OutputArray dst,
            float alpha = 0.2f, float beta = 0.4f)
        {
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }

            src.ThrowIfDisposed();
            dst.ThrowIfNotReady();
            mask?.ThrowIfDisposed();

            NativeMethods.photo_illuminationChange(
                src.CvPtr, ToPtr(mask), dst.CvPtr, alpha, beta);

            GC.KeepAlive(src);
            GC.KeepAlive(mask);
            dst.Fix();
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Try to stitch the given images.
        /// </summary>
        /// <param name="images">Input images.</param>
        /// <param name="pano">Final pano.</param>
        /// <returns>Status code.</returns>
        public Status Stitch(IEnumerable <Mat> images, OutputArray pano)
        {
            if (images == null)
            {
                throw new ArgumentNullException(nameof(images));
            }
            if (pano == null)
            {
                throw new ArgumentNullException(nameof(pano));
            }
            pano.ThrowIfNotReady();

            IntPtr[] imagesPtrs = EnumerableEx.SelectPtrs(images);

            Status status = (Status)NativeMethods.stitching_Stitcher_stitch1_MatArray(
                ptr, imagesPtrs, imagesPtrs.Length, pano.CvPtr);

            GC.KeepAlive(this);
            GC.KeepAlive(images);
            GC.KeepAlive(pano);
            pano.Fix();

            return(status);
        }
Ejemplo n.º 25
0
        public Status ComposePanorama(IEnumerable <Mat> images, OutputArray pano)
        {
            if (images == null)
            {
                throw new ArgumentNullException(nameof(images));
            }
            if (pano == null)
            {
                throw new ArgumentNullException(nameof(pano));
            }
            pano.ThrowIfNotReady();

            var imagesPtrs = images.Select(x => x.CvPtr).ToArray();

            NativeMethods.HandleException(
                NativeMethods.stitching_Stitcher_composePanorama2_MatArray(
                    ptr, imagesPtrs, imagesPtrs.Length, pano.CvPtr, out var ret));

            pano.Fix();
            GC.KeepAlive(this);
            GC.KeepAlive(images);
            GC.KeepAlive(pano);
            return((Status)ret);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Merges images.
        /// </summary>
        /// <param name="src">vector of input images</param>
        /// <param name="dst">result image</param>
        /// <param name="times">vector of exposure time values for each image</param>
        /// <param name="response"> 256x1 matrix with inverse camera response function for each pixel value, it should have the same number of channels as images.</param>
        public virtual void Process(IEnumerable <Mat> src, OutputArray dst, IEnumerable <float> times, InputArray response)
        {
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (dst == null)
            {
                throw new ArgumentNullException(nameof(dst));
            }
            if (times == null)
            {
                throw new ArgumentNullException(nameof(times));
            }
            if (response == null)
            {
                throw new ArgumentNullException(nameof(response));
            }
            dst.ThrowIfNotReady();

            var srcArray   = EnumerableEx.SelectPtrs(src);
            var timesArray = EnumerableEx.ToArray(times);

            if (srcArray.Length != timesArray.Length)
            {
                throw new OpenCvSharpException("src.Count() != times.Count");
            }

            NativeMethods.photo_MergeExposures_process(ptr, srcArray, srcArray.Length, dst.CvPtr, timesArray, response.CvPtr);

            dst.Fix();
            GC.KeepAlive(this);
            GC.KeepAlive(src);
            GC.KeepAlive(dst);
            GC.KeepAlive(response);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// サンプル集合からガウス混合パラメータを推定する
        /// </summary>
        /// <param name="samples"></param>
        /// <param name="means0"></param>
        /// <param name="covs0"></param>
        /// <param name="weights0"></param>
        /// <param name="logLikelihoods"></param>
        /// <param name="labels"></param>
        /// <param name="probs"></param>
#else
        /// <summary>
        /// Estimates Gaussian mixture parameters from the sample set
        /// </summary>
        /// <param name="samples"></param>
        /// <param name="means0"></param>
        /// <param name="covs0"></param>
        /// <param name="weights0"></param>
        /// <param name="logLikelihoods"></param>
        /// <param name="labels"></param>
        /// <param name="probs"></param>
#endif
        public virtual bool TrainE(
            InputArray samples,
            InputArray means0,
            InputArray covs0           = null,
            InputArray weights0        = null,
            OutputArray logLikelihoods = null,
            OutputArray labels         = null,
            OutputArray probs          = null)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
            if (samples == null)
            {
                throw new ArgumentNullException(nameof(samples));
            }
            if (means0 == null)
            {
                throw new ArgumentNullException(nameof(means0));
            }
            samples.ThrowIfDisposed();
            means0.ThrowIfDisposed();

            if (logLikelihoods != null)
            {
                logLikelihoods.ThrowIfNotReady();
            }
            if (covs0 != null)
            {
                covs0.ThrowIfDisposed();
            }
            if (weights0 != null)
            {
                weights0.ThrowIfDisposed();
            }
            if (labels != null)
            {
                labels.ThrowIfNotReady();
            }
            if (probs != null)
            {
                probs.ThrowIfNotReady();
            }

            int ret = NativeMethods.ml_EM_trainE(
                ptr,
                samples.CvPtr,
                means0.CvPtr,
                Cv2.ToPtr(covs0),
                Cv2.ToPtr(weights0),
                Cv2.ToPtr(logLikelihoods),
                Cv2.ToPtr(labels),
                Cv2.ToPtr(probs));

            if (logLikelihoods != null)
            {
                logLikelihoods.Fix();
            }
            if (labels != null)
            {
                labels.Fix();
            }
            if (probs != null)
            {
                probs.Fix();
            }
            GC.KeepAlive(samples);
            GC.KeepAlive(means0);
            GC.KeepAlive(covs0);
            GC.KeepAlive(weights0);

            return(ret != 0);
        }