Example #1
0
        /// <summary>
        /// Computes dense optical flow using Gunnar Farneback's algorithm
        /// </summary>
        /// <param name="prev0">The first 8-bit single-channel input image</param>
        /// <param name="next0">The second input image of the same size and the same type as prevImg</param>
        /// <param name="flowX">The computed flow image for x-velocity; will have the same size as prevImg</param>
        /// <param name="flowY">The computed flow image for y-velocity; will have the same size as prevImg</param>
        /// <param name="pyrScale">Specifies the image scale (!1) to build the pyramids for each image. pyrScale=0.5 means the classical pyramid, where each next layer is twice smaller than the previous</param>
        /// <param name="levels">The number of pyramid layers, including the initial image. levels=1 means that no extra layers are created and only the original images are used</param>
        /// <param name="winSize">The averaging window size; The larger values increase the algorithm robustness to image noise and give more chances for fast motion detection, but yield more blurred motion field</param>
        /// <param name="iterations">The number of iterations the algorithm does at each pyramid level</param>
        /// <param name="polyN">Size of the pixel neighborhood used to find polynomial expansion in each pixel. The larger values mean that the image will be approximated with smoother surfaces, yielding more robust algorithm and more blurred motion field. Typically, poly n=5 or 7</param>
        /// <param name="polySigma">Standard deviation of the Gaussian that is used to smooth derivatives that are used as a basis for the polynomial expansion. For poly n=5 you can set poly sigma=1.1, for poly n=7 a good value would be poly sigma=1.5</param>
        /// <param name="flags">The operation flags</param>
        public static void CalcOpticalFlowFarneback(
            Image <Gray, Byte> prev0,
            Image <Gray, Byte> next0,
            Image <Gray, Single> flowX,
            Image <Gray, Single> flowY,
            double pyrScale,
            int levels,
            int winSize,
            int iterations,
            int polyN,
            double polySigma,
            CvEnum.OpticalflowFarnebackFlag flags)
        {
            using (Mat flow0 = new Mat(prev0.Height, prev0.Width, CvEnum.DepthType.Cv32F, 2))
                using (Util.VectorOfMat vm = new Util.VectorOfMat(new Mat[] { flowX.Mat, flowY.Mat }))
                {
                    if ((int)(flags & Emgu.CV.CvEnum.OpticalflowFarnebackFlag.UseInitialFlow) != 0)
                    { //use initial flow
                        CvInvoke.Merge(vm, flow0);
                    }

                    CvInvoke.CalcOpticalFlowFarneback(prev0, next0, flow0, pyrScale, levels, winSize, iterations, polyN, polySigma, flags);
                    CvInvoke.Split(flow0, vm);
                }
        }
Example #2
0
 private extern static void cveCalcOpticalFlowFarneback(
     IntPtr prev0,
     IntPtr next0,
     IntPtr flow0,
     double pyrScale,
     int levels,
     int winSize,
     int iterations,
     int polyN,
     double polySigma,
     CvEnum.OpticalflowFarnebackFlag flags);
Example #3
0
 internal static extern IntPtr cveFarnebackOpticalFlowCreate(
     int numLevels,
     double pyrScale,
     [MarshalAs(CvInvoke.BoolMarshalType)]
     bool fastPyramids,
     int winSize,
     int numIters,
     int polyN,
     double polySigma,
     CvEnum.OpticalflowFarnebackFlag flags,
     ref IntPtr denseOpticalFlow,
     ref IntPtr algorithm);
Example #4
0
 /// <summary>
 /// Create a FarnebackOpticalFlow object
 /// </summary>
 /// <param name="pyrScale">Specifies the image scale (!1) to build the pyramids for each image. pyrScale=0.5 means the classical pyramid, where each next layer is twice smaller than the previous</param>
 /// <param name="numLevels">The number of pyramid layers, including the initial image. levels=1 means that no extra layers are created and only the original images are used</param>
 /// <param name="winSize">The averaging window size; The larger values increase the algorithm robustness to image noise and give more chances for fast motion detection, but yield more blurred motion field</param>
 /// <param name="numIters">The number of iterations the algorithm does at each pyramid level</param>
 /// <param name="polyN">Size of the pixel neighborhood used to find polynomial expansion in each pixel. The larger values mean that the image will be approximated with smoother surfaces, yielding more robust algorithm and more blurred motion field. Typically, poly n=5 or 7</param>
 /// <param name="polySigma">Standard deviation of the Gaussian that is used to smooth derivatives that are used as a basis for the polynomial expansion. For poly n=5 you can set poly sigma=1.1, for poly n=7 a good value would be poly sigma=1.5</param>
 /// <param name="flags">The operation flags</param>
 /// <param name="fastPyramids">Fast Pyramids</param>
 public FarnebackOpticalFlow(
     int numLevels     = 5,
     double pyrScale   = 0.5,
     bool fastPyramids = false,
     int winSize       = 13,
     int numIters      = 10,
     int polyN         = 5,
     double polySigma  = 1.1,
     CvEnum.OpticalflowFarnebackFlag flags = CvEnum.OpticalflowFarnebackFlag.Default)
 {
     _ptr = CvInvoke.cveFarnebackOpticalFlowCreate(
         numLevels,
         pyrScale, fastPyramids, winSize, numIters, polyN, polySigma,
         flags,
         ref _denseOpticalFlow, ref _algorithm);
 }
Example #5
0
 public FarnebackOpticalFlow(
     int numLevels,
     double pyrScale,
     bool fastPyramids,
     int winSize,
     int numIters,
     int polyN,
     double polySigma,
     CvEnum.OpticalflowFarnebackFlag flags)
 {
     _ptr = CvInvoke.cveFarnebackOpticalFlowCreate(
         numLevels,
         pyrScale, fastPyramids, winSize, numIters, polyN, polySigma,
         flags,
         ref _denseOpticalFlow, ref _algorithm);
 }
Example #6
0
 /// <summary>
 /// Computes dense optical flow using Gunnar Farneback's algorithm
 /// </summary>
 /// <param name="prev0">The first 8-bit single-channel input image</param>
 /// <param name="next0">The second input image of the same size and the same type as prevImg</param>
 /// <param name="flow">The computed flow image; will have the same size as prevImg and type CV 32FC2</param>
 /// <param name="pyrScale">Specifies the image scale (!1) to build the pyramids for each image. pyrScale=0.5 means the classical pyramid, where each next layer is twice smaller than the previous</param>
 /// <param name="levels">The number of pyramid layers, including the initial image. levels=1 means that no extra layers are created and only the original images are used</param>
 /// <param name="winSize">The averaging window size; The larger values increase the algorithm robustness to image noise and give more chances for fast motion detection, but yield more blurred motion field</param>
 /// <param name="iterations">The number of iterations the algorithm does at each pyramid level</param>
 /// <param name="polyN">Size of the pixel neighborhood used to find polynomial expansion in each pixel. The larger values mean that the image will be approximated with smoother surfaces, yielding more robust algorithm and more blurred motion field. Typically, poly n=5 or 7</param>
 /// <param name="polySigma">Standard deviation of the Gaussian that is used to smooth derivatives that are used as a basis for the polynomial expansion. For poly n=5 you can set poly sigma=1.1, for poly n=7 a good value would be poly sigma=1.5</param>
 /// <param name="flags">The operation flags</param>
 public static void CalcOpticalFlowFarneback(
     IInputArray prev0,
     IInputArray next0,
     IInputOutputArray flow,
     double pyrScale,
     int levels,
     int winSize,
     int iterations,
     int polyN,
     double polySigma,
     CvEnum.OpticalflowFarnebackFlag flags)
 {
     using (InputArray iaPrev0 = prev0.GetInputArray())
         using (InputArray iaNext0 = next0.GetInputArray())
             using (InputOutputArray ioaFlow = flow.GetInputOutputArray())
                 cveCalcOpticalFlowFarneback(iaPrev0, iaNext0, ioaFlow, pyrScale, levels, winSize, iterations, polyN, polySigma, flags);
 }
Example #7
0
 /// <summary>
 /// Create a CudaFarnebackOpticalFlow object
 /// </summary>
 /// <param name="pyrScale">Specifies the image scale (!1) to build the pyramids for each image. pyrScale=0.5 means the classical pyramid, where each next layer is twice smaller than the previous</param>
 /// <param name="numLevels">The number of pyramid layers, including the initial image. levels=1 means that no extra layers are created and only the original images are used</param>
 /// <param name="winSize">The averaging window size; The larger values increase the algorithm robustness to image noise and give more chances for fast motion detection, but yield more blurred motion field</param>
 /// <param name="numIters">The number of iterations the algorithm does at each pyramid level</param>
 /// <param name="polyN">Size of the pixel neighborhood used to find polynomial expansion in each pixel. The larger values mean that the image will be approximated with smoother surfaces, yielding more robust algorithm and more blurred motion field. Typically, poly n=5 or 7</param>
 /// <param name="polySigma">Standard deviation of the Gaussian that is used to smooth derivatives that are used as a basis for the polynomial expansion. For poly n=5 you can set poly sigma=1.1, for poly n=7 a good value would be poly sigma=1.5</param>
 /// <param name="flags">The operation flags</param>
 /// <param name="fastPyramids">Fast Pyramids</param>
 public CudaFarnebackOpticalFlow(
     int numLevels     = 5,
     double pyrScale   = 0.5,
     bool fastPyramids = false,
     int winSize       = 13,
     int numIters      = 10,
     int polyN         = 5,
     double polySigma  = 1.1,
     CvEnum.OpticalflowFarnebackFlag flags = 0)
 {
     _ptr = CudaInvoke.cudaFarnebackOpticalFlowCreate(
         numLevels,
         pyrScale,
         fastPyramids,
         winSize,
         numIters,
         polyN,
         polySigma,
         flags,
         ref _denseFlow,
         ref _algorithm,
         ref _sharedPtr);
 }