Ejemplo n.º 1
0
        /// <summary>
        /// Given a rectangle area of the motion, output the angle of the motion and the number of pixels that are considered to be motion pixel
        /// </summary>
        /// <param name="motionRectangle">The rectangle area of the motion</param>
        /// <param name="angle">The orientation of the motion</param>
        /// <param name="motionPixelCount">Number of motion pixels within silhouette ROI</param>
        /// <param name="forgroundMask">The foreground mask used to calculate the motion info.</param>
        public void MotionInfo(Mat forgroundMask, System.Drawing.Rectangle motionRectangle, out double angle, out double motionPixelCount)
        {
            TimeSpan ts = _lastTime.Subtract(_initTime);

            // select component ROI
            using (Mat forgroundMaskRect = new Mat(forgroundMask, motionRectangle))
                using (Mat mhiRect = new Mat(_mhi, motionRectangle))
                    using (Mat orientationRect = new Mat(_orientation, motionRectangle))
                        using (Mat maskRect = new Mat(_mask, motionRectangle))
                        {
                            // calculate orientation
                            angle = CvInvoke.CalcGlobalOrientation(orientationRect, maskRect, mhiRect, ts.TotalSeconds, _mhiDuration);
                            angle = 360.0 - angle; // adjust for images with top-left origin

                            // calculate number of points within silhouette ROI
                            motionPixelCount = CvInvoke.Norm(forgroundMaskRect, null, CvEnum.NormType.L1);
                        }
        }