Browse Source

Added DenseRLOFOpticalFlow

pull/262/head
Canming Huang 6 years ago
parent
commit
ed4dcebcae
  1. 84
      Emgu.CV.Contrib/Stereo/QuasiDenseStereo.cs
  2. 19
      Emgu.CV.Extern/CMakeLists.txt
  3. 40
      Emgu.CV.Extern/optflow/optflow_c.cpp
  4. 16
      Emgu.CV.Extern/optflow/optflow_c.h
  5. 144
      Emgu.CV/Optflow/DenseRLOFOpticalFlow.cs
  6. 12
      Emgu.CV/Optflow/RLOFOpticalFlowParameter.cs

84
Emgu.CV.Contrib/Stereo/QuasiDenseStereo.cs

@ -54,118 +54,104 @@ namespace Emgu.CV.Stereo
/// <summary>
/// similarity window
/// </summary>
int CorrWinSizeX;
public int CorrWinSizeX;
/// <summary>
/// similarity window
/// </summary>
int CorrWinSizeY;
public int CorrWinSizeY;
/// <summary>
/// border to ignore
/// </summary>
int BorderX;
public int BorderX;
/// <summary>
/// border to ignore
/// </summary>
int BorderY;
public int BorderY;
/// <summary>
/// correlation threshold
/// </summary>
float CorrelationThreshold;
public float CorrelationThreshold;
/// <summary>
/// texture threshold
/// </summary>
float TextrureThreshold;
public float TextrureThreshold;
/// <summary>
/// neighborhood size
/// </summary>
int NeighborhoodSize;
public int NeighborhoodSize;
/// <summary>
/// disparity gradient threshold
/// </summary>
int DisparityGradient;
public int DisparityGradient;
/// <summary>
/// Parameters for LK flow algorithm
/// </summary>
int LkTemplateSize;
public int LkTemplateSize;
/// <summary>
/// Parameters for LK flow algorithm
/// </summary>
int LkPyrLvl;
public int LkPyrLvl;
/// <summary>
/// Parameters for LK flow algorithm
/// </summary>
int LkTermParam1;
public int LkTermParam1;
/// <summary>
/// Parameters for LK flow algorithm
/// </summary>
float LkTermParam2;
public float LkTermParam2;
/// <summary>
/// Parameters for GFT algorithm.
/// </summary>
float GftQualityThres;
public float GftQualityThres;
/// <summary>
/// Parameters for GFT algorithm.
/// </summary>
int GftMinSeperationDist;
public int GftMinSeperationDist;
/// <summary>
/// Parameters for GFT algorithm.
/// </summary>
int GftMaxNumFeatures;
public int GftMaxNumFeatures;
}
}
public enum SupportRegionType
/// <summary>
/// Class that contains entry points for the Stereo module.
/// </summary>
public static partial class StereoInvoke
{
static StereoInvoke()
{
/// <summary>
/// Apply a constant support region
/// </summary>
Fixed = 0,
/// <summary>
/// Apply a adaptive support region obtained by cross-based segmentation
/// </summary>
Cross = 1
CvInvoke.CheckLibraryLoaded();
}
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal extern static IntPtr cveQuasiDenseStereoCreate(
ref Size monoImgSize,
IntPtr paramFilepath,
ref IntPtr sharedPtr);
/// <summary>
/// Class that contains entry points for the Stereo module.
/// </summary>
public static partial class StereoInvoke
{
static StereoInvoke()
{
CvInvoke.CheckLibraryLoaded();
}
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal extern static void cveQuasiDenseStereoRelease(ref IntPtr sharedPtr);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal extern static IntPtr cveQuasiDenseStereoCreate(
ref Size monoImgSize,
IntPtr paramFilepath,
ref IntPtr sharedPtr);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal extern static void cveQuasiDenseStereoProcess(IntPtr stereo, IntPtr imgLeft, IntPtr imgRight);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal extern static void cveQuasiDenseStereoRelease(ref IntPtr sharedPtr);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal extern static void cveQuasiDenseStereoProcess(IntPtr stereo, IntPtr imgLeft, IntPtr imgRight);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal extern static void cveQuasiDenseStereoGetDisparity(IntPtr stereo, byte disparityLvls,
IntPtr disparity);
}
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal extern static void cveQuasiDenseStereoGetDisparity(IntPtr stereo, byte disparityLvls,
IntPtr disparity);
}
}

19
Emgu.CV.Extern/CMakeLists.txt

@ -1315,18 +1315,25 @@ CREATE_OCV_CLASS_PROPERTY(
"${CMAKE_CURRENT_SOURCE_DIR}/../Emgu.CV/Optflow/RLOFOpticalFlowParameter.g.cs"
"cv::optflow::RLOFOpticalFlowParameter"
"RLOFOpticalFlowParameter"
"NormSigma0;NormSigma1;SolverType;SupportRegionType;SmallWinSize;LargeWinSize;CrossSegmentationThreshold"
"float;float;cv::optflow::SolverType;cv::optflow::SupportRegionType;int;int;int"
"prop;prop;prop;prop;prop;prop;prop"
"NormSigma0;NormSigma1;SolverType;SupportRegionType;SmallWinSize;LargeWinSize;CrossSegmentationThreshold"
"float;float;Emgu.CV.SolverType;Emgu.CV.SupportRegionType;int;int;int"
"NormSigma0;NormSigma1;SolverType;SupportRegionType;SmallWinSize;LargeWinSize;CrossSegmentationThreshold;MaxLevel;UseInitialFlow;UseIlluminationModel;UseGlobalMotionPrior;MaxIteration;MinEigenValue;GlobalMotionRansacThreshold"
"float;float;cv::optflow::SolverType;cv::optflow::SupportRegionType;int;int;int;int;bool;bool;bool;int;float;float"
"prop;prop;prop;prop;prop;prop;prop;prop;prop;prop;prop;prop;prop;prop"
"NormSigma0;NormSigma1;SolverType;SupportRegionType;SmallWinSize;LargeWinSize;CrossSegmentationThreshold;MaxLevel;UseInitialFlow;UseIlluminationModel;UseGlobalMotionPrior;MaxIteration;MinEigenValue;GlobalMotionRansacThreshold"
"float;float;Emgu.CV.DenseRLOFOpticalFlow.SolverType;Emgu.CV.DenseRLOFOpticalFlow.SupportRegionType;int;int;int;int;bool;bool;bool;int;float;float"
"parameter of the shrinked Hampel norm;
parameter of the shrinked Hampel norm;
Variable specifies the iterative refinement strategy;
Variable specifies the support region shape extraction or shrinking strategy;
Minimal window size of the support region. This parameter is only used if supportRegionType is Cross;
Maximal window size of the support region. If supportRegionType is Fixed this gives the exact support region size. The speed of the RLOF is related to the applied win sizes. The smaller the window size the lower is the runtime, but the more sensitive to noise is the method.;
Color similarity threshold used by cross-based segmentation. Only used if supportRegionType is Cross. With the cross-bassed segmentation motion boundaries can be computed more accurately"
Color similarity threshold used by cross-based segmentation. Only used if supportRegionType is Cross. With the cross-bassed segmentation motion boundaries can be computed more accurately;
Maximal number of pyramid level used. The large this value is the more likely it is to obtain accurate solutions for long-range motions. The runtime is linear related to this parameter;
Use next point list as initial values. A good initialization can improve the algorithm accuracy and reduce the runtime by a faster convergence of the iteration refinement;
Use the Gennert and Negahdaripour illumination model instead of the intensity brightness constraint.;
Use global motion prior initialisation. It allows to be more accurate for long-range motion. The computational complexity is slightly increased by enabling the global motion prior initialisation.;
Number of maximal iterations used for the iterative refinement. Lower values can reduce the runtime but also the accuracy.;
Threshold for the minimal eigenvalue of the gradient matrix defines when to abort the iterative refinement.;
To apply the global motion prior motion vectors will be computed on a regulary sampled which are the basis for Homography estimation using RANSAC. The reprojection threshold is based on n-th percentil (given by this value [0 ... 100]) of the motion vectors magnitude. "
"Emgu.CV"
"CvInvoke"
"RLOFOpticalFlowParameter"

40
Emgu.CV.Extern/optflow/optflow_c.cpp

@ -65,4 +65,44 @@ void cveRLOFOpticalFlowParameterRelease(cv::optflow::RLOFOpticalFlowParameter**
{
delete *p;
*p = 0;
}
cv::optflow::DenseRLOFOpticalFlow* cveDenseRLOFOpticalFlowCreate(
cv::optflow::RLOFOpticalFlowParameter* rlofParameter,
float forwardBackwardThreshold,
CvSize* gridStep,
int interpType,
int epicK,
float epicSigma,
float epicLambda,
bool usePostProc,
float fgsLambda,
float fgsSigma,
cv::DenseOpticalFlow** denseOpticalFlow,
cv::Algorithm** algorithm,
cv::Ptr<cv::optflow::DenseRLOFOpticalFlow>** sharedPtr)
{
cv::Ptr<cv::optflow::RLOFOpticalFlowParameter> pPtr(rlofParameter, [](cv::optflow::RLOFOpticalFlowParameter* p) {});
cv::Ptr<cv::optflow::DenseRLOFOpticalFlow> rlof = cv::optflow::DenseRLOFOpticalFlow::create(
pPtr,
forwardBackwardThreshold,
*gridStep,
static_cast<cv::optflow::InterpolationType>(interpType),
epicK,
epicSigma,
epicLambda,
usePostProc,
fgsLambda,
fgsSigma);
*sharedPtr = new cv::Ptr<cv::optflow::DenseRLOFOpticalFlow>(rlof);
cv::optflow::DenseRLOFOpticalFlow* ptr = (*sharedPtr)->get();
*denseOpticalFlow = dynamic_cast<cv::optflow::DenseRLOFOpticalFlow*>(ptr);
*algorithm = dynamic_cast<cv::Algorithm*>(ptr);
return ptr;
}
void cveDenseRLOFOpticalFlowRelease(cv::Ptr<cv::optflow::DenseRLOFOpticalFlow>** sharedPtr)
{
delete *sharedPtr;
*sharedPtr = 0;
}

16
Emgu.CV.Extern/optflow/optflow_c.h

@ -25,4 +25,20 @@ CVAPI(void) cveDualTVL1OpticalFlowRelease(cv::Ptr<cv::optflow::DualTVL1OpticalFl
CVAPI(cv::optflow::RLOFOpticalFlowParameter*) cveRLOFOpticalFlowParameterCreate();
CVAPI(void) cveRLOFOpticalFlowParameterRelease(cv::optflow::RLOFOpticalFlowParameter** p);
CVAPI(cv::optflow::DenseRLOFOpticalFlow*) cveDenseRLOFOpticalFlowCreate(
cv::optflow::RLOFOpticalFlowParameter* rlofParameter,
float forwardBackwardThreshold,
CvSize* gridStep,
int interpType,
int epicK,
float epicSigma,
float epicLambda,
bool usePostProc,
float fgsLambda,
float fgsSigma,
cv::DenseOpticalFlow** denseOpticalFlow,
cv::Algorithm** algorithm,
cv::Ptr<cv::optflow::DenseRLOFOpticalFlow>** sharedPtr);
CVAPI(void) cveDenseRLOFOpticalFlowRelease(cv::Ptr<cv::optflow::DenseRLOFOpticalFlow>** sharedPtr);
#endif

144
Emgu.CV/Optflow/DenseRLOFOpticalFlow.cs

@ -0,0 +1,144 @@
//----------------------------------------------------------------------------
// Copyright (C) 2004-2019 by EMGU Corporation. All rights reserved.
//----------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using Emgu.CV.Structure;
using Emgu.CV.Util;
using Emgu.Util;
namespace Emgu.CV
{
public partial class DenseRLOFOpticalFlow : SharedPtrObject, IDenseOpticalFlow
{
public enum SolverType
{
/// <summary>
/// Apply standard iterative refinement
/// </summary>
Standard = 0,
/// <summary>
/// Apply optimized iterative refinement based bilinear equation solutions
/// </summary>
Bilinear = 1
}
public enum SupportRegionType
{
/// <summary>
/// Apply a constant support region
/// </summary>
Fixed = 0,
/// <summary>
/// Apply a adaptive support region obtained by cross-based segmentation
/// </summary>
Cross = 1
}
public enum InterpolationType
{
/// <summary>
/// Fast geodesic interpolation
/// </summary>
Geo = 0,
/// <summary>
/// Edge-preserving interpolation
/// </summary>
Epic = 1,
};
private IntPtr _algorithm;
private IntPtr _denseOpticalFlow;
public DenseRLOFOpticalFlow(
RLOFOpticalFlowParameter parameter,
float forwardBackwardThreshold,
Size gridStep,
InterpolationType interpType,
int epicK,
float epicSigma,
float epicLambda,
bool usePostProc,
float fgsLambda,
float fgsSigma
)
{
_ptr = CvInvoke.cveDenseRLOFOpticalFlowCreate(
parameter,
forwardBackwardThreshold,
ref gridStep,
interpType,
epicK,
epicSigma,
epicLambda,
usePostProc,
fgsLambda,
fgsSigma,
ref _denseOpticalFlow,
ref _algorithm,
ref _sharedPtr);
}
/// <summary>
/// Release the unmanaged resources
/// </summary>
protected override void DisposeObject()
{
if (_sharedPtr != IntPtr.Zero)
{
CvInvoke.cveDenseRLOFOpticalFlowRelease(ref _sharedPtr);
_ptr = IntPtr.Zero;
_algorithm = IntPtr.Zero;
_denseOpticalFlow = IntPtr.Zero;
}
}
/// <summary>
/// Gets the dense optical flow pointer.
/// </summary>
/// <value>
/// The pointer to the dense optical flow object.
/// </value>
public IntPtr DenseOpticalFlowPtr
{
get { return _denseOpticalFlow; }
}
/// <summary>
/// Return the pointer to the algorithm object
/// </summary>
public IntPtr AlgorithmPtr
{
get { return _algorithm; }
}
}
public static partial class CvInvoke
{
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern void cveDenseRLOFOpticalFlowRelease(ref IntPtr sharedPtr);
[DllImport(CvInvoke.ExternLibrary, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern IntPtr cveDenseRLOFOpticalFlowCreate(
IntPtr rlofParameter,
float forwardBackwardThreshold,
ref Size gridStep,
Emgu.CV.DenseRLOFOpticalFlow.InterpolationType interpType,
int epicK,
float epicSigma,
float epicLambda,
[MarshalAs(CvInvoke.BoolMarshalType)]
bool usePostProc,
float fgsLambda,
float fgsSigma,
ref IntPtr denseOpticalFlow,
ref IntPtr algorithm,
ref IntPtr sharedPtr);
}
}

12
Emgu.CV/Optflow/RLOFOpticalFlowParameter.cs

@ -11,18 +11,6 @@ using System.Runtime.InteropServices;
namespace Emgu.CV
{
public enum SolverType
{
/// <summary>
/// Apply standard iterative refinement
/// </summary>
Standard = 0,
/// <summary>
/// Apply optimized iterative refinement based bilinear equation solutions
/// </summary>
Bilinear = 1
}
public partial class RLOFOpticalFlowParameter : UnmanagedObject
{

Loading…
Cancel
Save