Exemplo n.º 1
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("mhi");
            }
            if (segmask == null)
            {
                throw new ArgumentNullException("segmask");
            }
            mhi.ThrowIfDisposed();
            segmask.ThrowIfNotReady();

            using (var br = new VectorOfRect())
            {
                NativeMethods.video_segmentMotion(
                    mhi.CvPtr, segmask.CvPtr, br.CvPtr, timestamp, segThresh);
                boundingRects = br.ToArray();
            }
            segmask.Fix();
        }
Exemplo n.º 2
0
        /// <summary>
        /// keypoint を検出し,その SIFT ディスクリプタを計算します.
        /// </summary>
        /// <param name="img">Input 8-bit grayscale image</param>
        /// <param name="mask">Optional input mask that marks the regions where we should detect features.</param>
        /// <param name="keypoints">The input/output vector of keypoints</param>
        /// <param name="descriptors">The output matrix of descriptors. </param>
        /// <param name="useProvidedKeypoints">Boolean flag. If it is true, the keypoint detector is not run.
        /// Instead, the provided vector of keypoints is used and the algorithm just computes their descriptors.</param>
#else
        /// <summary>
        /// detects keypoints and computes the SIFT descriptors for them.
        /// </summary>
        /// <param name="img">Input 8-bit grayscale image</param>
        /// <param name="mask">Optional input mask that marks the regions where we should detect features.</param>
        /// <param name="keypoints">The input/output vector of keypoints</param>
        /// <param name="descriptors">The output matrix of descriptors. </param>
        /// <param name="useProvidedKeypoints">Boolean flag. If it is true, the keypoint detector is not run.
        /// Instead, the provided vector of keypoints is used and the algorithm just computes their descriptors.</param>
#endif
        public void Run(InputArray img, InputArray mask, out KeyPoint[] keypoints, OutputArray descriptors,
                        bool useProvidedKeypoints = false)
        {
            ThrowIfDisposed();
            if (img == null)
            {
                throw new ArgumentNullException(nameof(img));
            }
            if (descriptors == null)
            {
                throw new ArgumentNullException(nameof(descriptors));
            }
            img.ThrowIfDisposed();
            descriptors.ThrowIfNotReady();

            using (VectorOfKeyPoint keypointsVec = new VectorOfKeyPoint())
            {
                NativeMethods.nonfree_SIFT_run2_OutputArray(ptr, img.CvPtr, Cv2.ToPtr(mask), keypointsVec.CvPtr,
                                                            descriptors.CvPtr, useProvidedKeypoints ? 1 : 0);

                keypoints = keypointsVec.ToArray();
            }
            descriptors.Fix();
        }
Exemplo n.º 3
0
        /// <summary>
        /// computes the disparity for the two rectified 8-bit single-channel images.
        /// the disparity will be 16-bit signed (fixed-point) or 32-bit floating-point image of the same size as left.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <param name="disp"></param>
        /// <param name="dispType"></param>
#else
        /// <summary>
        /// computes the disparity for the two rectified 8-bit single-channel images.
        /// the disparity will be 16-bit signed (fixed-point) or 32-bit floating-point image of the same size as left.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <param name="disp"></param>
        /// <param name="dispType"></param>
#endif
        public void Compute(InputArray left, InputArray right, OutputArray disp, int dispType = MatType.CV_16S)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("StereoSGBM");
            }
            if (left == null)
            {
                throw new ArgumentNullException("left");
            }
            if (right == null)
            {
                throw new ArgumentNullException("right");
            }
            if (disp == null)
            {
                throw new ArgumentNullException("disp");
            }
            left.ThrowIfDisposed();
            right.ThrowIfDisposed();
            disp.ThrowIfNotReady();
            NativeMethods.calib3d_StereoBM_compute(ptr, left.CvPtr, right.CvPtr, disp.CvPtr, dispType);
            disp.Fix();
        }
Exemplo n.º 4
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("EM");
            }
            if (samples == null)
            {
                throw new ArgumentNullException("samples");
            }
            if (means0 == null)
            {
                throw new ArgumentNullException("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();
            }

            return(ret != 0);
        }