Browse Source

Re-enable videostab module.

git-svn-id: https://emgucv.svn.sourceforge.net/svnroot/emgucv/trunk@1764 d7f09016-e345-0410-b530-edf29a71df78
UWP10
canming 13 years ago
parent
commit
d92a9b6411
  1. 31
      Emgu.CV.Extern/gpu/videostab_c.cpp
  2. 6
      Emgu.CV.Extern/gpu/videostab_c.h
  3. 6
      Emgu.CV.VideoStab/CaptureFrameSource.cs
  4. 5
      Emgu.CV.VideoStab/FrameSource.cs
  5. 7
      Emgu.CV.VideoStab/GaussianMotionFilter.cs
  6. 9
      Emgu.CV.VideoStab/OnePassStabilizer.cs
  7. 9
      Emgu.CV.VideoStab/TwoPassStabilizer.cs
  8. 2
      Emgu.CV.VideoStab/VideoStabInvoke.cs

31
Emgu.CV.Extern/gpu/videostab_c.cpp

@ -4,7 +4,7 @@
//
//----------------------------------------------------------------------------
/*
#include "videostab_c.h"
CaptureFrameSource* CaptureFrameSourceCreate(CvCapture* capture)
@ -34,22 +34,35 @@ bool FrameSourceGetNextFrame(cv::videostab::IFrameSource* frameSource, IplImage*
return true;
}
void StabilizerBaseSetMotionEstimator(cv::videostab::StabilizerBase* stabalizer, cv::videostab::ImageMotionEstimatorBase* motionEstimator)
void StabilizerBaseSetMotionEstimator(cv::videostab::StabilizerBase* stabalizer, cv::videostab::IGlobalMotionEstimator* motionEstimator)
{
cv::Ptr<cv::videostab::ImageMotionEstimatorBase> ptr(motionEstimator);
cv::Ptr<cv::videostab::IGlobalMotionEstimator> ptr(motionEstimator);
ptr.addref(); // add reference such that it won't release the motion estimator
stabalizer->setMotionEstimator(motionEstimator);
}
template<class cvstabilizer> cvstabilizer* StabilizerCreate(CaptureFrameSource* capture, cv::videostab::StabilizerBase** stabilizerBase, cv::videostab::IFrameSource** frameSource)
{
cvstabilizer* stabilizer = new cvstabilizer();
cv::Ptr<cv::videostab::IFrameSource> ptr(capture);
ptr.addref(); // add reference such that it won't release the CaptureFrameSource
stabilizer->setFrameSource(ptr);
*stabilizerBase = static_cast<cv::videostab::StabilizerBase*>(stabilizer);
*frameSource = static_cast<cv::videostab::IFrameSource*>(stabilizer);
return stabilizer;
}
cv::videostab::OnePassStabilizer* OnePassStabilizerCreate(CaptureFrameSource* capture, cv::videostab::StabilizerBase** stabilizerBase, cv::videostab::IFrameSource** frameSource)
{
return StabilizerCreate<cv::videostab::OnePassStabilizer>(capture, stabilizerBase, frameSource);
/*
cv::videostab::OnePassStabilizer* stabilizer = new cv::videostab::OnePassStabilizer();
cv::Ptr<cv::videostab::IFrameSource> ptr(capture);
ptr.addref(); // add reference such that it won't release the CaptureFrameSource
stabilizer->setFrameSource(ptr);
*stabilizerBase = static_cast<cv::videostab::StabilizerBase*>(stabilizer);
*frameSource = static_cast<cv::videostab::IFrameSource*>(stabilizer);
return stabilizer;
return stabilizer;*/
}
void OnePassStabilizerSetMotionFilter(cv::videostab::OnePassStabilizer* stabilizer, cv::videostab::MotionFilterBase* motionFilter)
@ -67,13 +80,15 @@ void OnePassStabilizerRelease(cv::videostab::OnePassStabilizer** stabilizer)
cv::videostab::TwoPassStabilizer* TwoPassStabilizerCreate(CaptureFrameSource* capture, cv::videostab::StabilizerBase** stabilizerBase, cv::videostab::IFrameSource** frameSource)
{
return StabilizerCreate<cv::videostab::TwoPassStabilizer>(capture, stabilizerBase, frameSource);
/*
cv::videostab::TwoPassStabilizer* stabilizer = new cv::videostab::TwoPassStabilizer();
cv::Ptr<cv::videostab::IFrameSource> ptr(capture);
ptr.addref(); // add reference such that it won't release the CaptureFrameSource
stabilizer->setFrameSource(ptr);
*stabilizerBase = static_cast<cv::videostab::StabilizerBase*>(stabilizer);
*frameSource = static_cast<cv::videostab::IFrameSource*>(stabilizer);
return stabilizer;
return stabilizer;*/
}
void TwoPassStabilizerRelease(cv::videostab::TwoPassStabilizer** stabilizer)
{
@ -81,12 +96,12 @@ void TwoPassStabilizerRelease(cv::videostab::TwoPassStabilizer** stabilizer)
*stabilizer = 0;
}
cv::videostab::GaussianMotionFilter* GaussianMotionFilterCreate(int radius, float stdev)
cv::videostab::GaussianMotionFilter* GaussianMotionFilterCreate()
{
return new cv::videostab::GaussianMotionFilter(radius, stdev);
return new cv::videostab::GaussianMotionFilter();
}
void GaussianMotionFilterRelease(cv::videostab::GaussianMotionFilter** filter)
{
delete *filter;
*filter = 0;
}*/
}

6
Emgu.CV.Extern/gpu/videostab_c.h

@ -4,7 +4,6 @@
//
//----------------------------------------------------------------------------
/*
#pragma once
#ifndef EMGU_VIDEOSTAB_C_H
#define EMGU_VIDEOSTAB_C_H
@ -35,7 +34,7 @@ CVAPI(void) CaptureFrameSourceRelease(CaptureFrameSource** captureFrameSource);
CVAPI(bool) FrameSourceGetNextFrame(cv::videostab::IFrameSource* frameSource, IplImage** nextFrame);
CVAPI(void) StabilizerBaseSetMotionEstimator(cv::videostab::StabilizerBase* stabalizer, cv::videostab::ImageMotionEstimatorBase* motionEstimator);
CVAPI(void) StabilizerBaseSetMotionEstimator(cv::videostab::StabilizerBase* stabalizer, cv::videostab::IGlobalMotionEstimator* motionEstimator);
CVAPI(cv::videostab::OnePassStabilizer*) OnePassStabilizerCreate(CaptureFrameSource* capture, cv::videostab::StabilizerBase** stabilizerBase, cv::videostab::IFrameSource** frameSource);
CVAPI(void) OnePassStabilizerSetMotionFilter(cv::videostab::OnePassStabilizer* stabilizer, cv::videostab::MotionFilterBase* motionFilter);
@ -44,8 +43,7 @@ CVAPI(void) OnePassStabilizerRelease(cv::videostab::OnePassStabilizer** stabiliz
CVAPI(cv::videostab::TwoPassStabilizer*) TwoPassStabilizerCreate(CaptureFrameSource* capture, cv::videostab::StabilizerBase** stabilizerBase, cv::videostab::IFrameSource** frameSource);
CVAPI(void) TwoPassStabilizerRelease(cv::videostab::TwoPassStabilizer** stabilizer);
CVAPI(cv::videostab::GaussianMotionFilter*) GaussianMotionFilterCreate(int radius, float stdev);
CVAPI(cv::videostab::GaussianMotionFilter*) GaussianMotionFilterCreate();
CVAPI(void) GaussianMotionFilterRelease(cv::videostab::GaussianMotionFilter** filter);
#endif
*/

6
Emgu.CV.VideoStab/CaptureFrameSource.cs

@ -17,11 +17,7 @@ namespace Emgu.CV.VideoStab
public CaptureFrameSource(Capture capture)
{
_ptr = VideoStabInvoke.CaptureFrameSourceCreate(capture);
}
protected override IntPtr GetFrameSourcePointer()
{
return _ptr;
_framSourcePtr = _ptr;
}
protected override void DisposeObject()

5
Emgu.CV.VideoStab/FrameSource.cs

@ -16,11 +16,11 @@ namespace Emgu.CV.VideoStab
{
private IntPtr _frameBuffer;
protected abstract IntPtr GetFrameSourcePointer();
protected IntPtr _framSourcePtr;
public Image<Bgr, Byte> NextFrame()
{
if (!VideoStabInvoke.FrameSourceGetNextFrame(GetFrameSourcePointer(), ref _frameBuffer) || _frameBuffer == IntPtr.Zero)
if (!VideoStabInvoke.FrameSourceGetNextFrame(_framSourcePtr, ref _frameBuffer) || _frameBuffer == IntPtr.Zero)
return null;
MIplImage iplImage = (MIplImage)Marshal.PtrToStructure(_frameBuffer, typeof(MIplImage));
@ -45,6 +45,7 @@ namespace Emgu.CV.VideoStab
{
CvInvoke.cvReleaseImage(ref _frameBuffer);
}
_framSourcePtr = IntPtr.Zero;
}
}
}

7
Emgu.CV.VideoStab/GaussianMotionFilter.cs

@ -11,14 +11,15 @@ namespace Emgu.CV.VideoStab
{
public class GaussianMotionFilter : UnmanagedObject
{
/*
public GaussianMotionFilter()
: this(15, -1.0f)
{
}
}*/
public GaussianMotionFilter(int radius, float stdev)
public GaussianMotionFilter()
{
_ptr = VideoStabInvoke.GaussianMotionFilterCreate(radius, stdev);
_ptr = VideoStabInvoke.GaussianMotionFilterCreate();
}
protected override void DisposeObject()

9
Emgu.CV.VideoStab/OnePassStabilizer.cs

@ -14,14 +14,13 @@ namespace Emgu.CV.VideoStab
public class OnePassStabilizer : FrameSource
{
private IntPtr _stabilizerBase;
private IntPtr _frameSource;
private CaptureFrameSource _captureFrameSource;
public OnePassStabilizer(Capture capture)
{
_captureFrameSource = new CaptureFrameSource(capture);
_ptr = VideoStabInvoke.OnePassStabilizerCreate(_captureFrameSource, ref _stabilizerBase, ref _frameSource);
_ptr = VideoStabInvoke.OnePassStabilizerCreate(_captureFrameSource, ref _stabilizerBase, ref _framSourcePtr);
}
public void SetMotionFilter(GaussianMotionFilter motionFilter)
@ -35,16 +34,10 @@ namespace Emgu.CV.VideoStab
VideoStabInvoke.StabilizerBaseSetMotionEstimator(_stabilizerBase, estimator);
}*/
protected override IntPtr GetFrameSourcePointer()
{
return _frameSource;
}
protected override void DisposeObject()
{
VideoStabInvoke.OnePassStabilizerRelease(ref _ptr);
_stabilizerBase = IntPtr.Zero;
_frameSource = IntPtr.Zero;
_captureFrameSource.Dispose();
base.Dispose();
}

9
Emgu.CV.VideoStab/TwoPassStabilizer.cs

@ -14,26 +14,19 @@ namespace Emgu.CV.VideoStab
public class TwoPassStabilizer : FrameSource
{
private IntPtr _stabilizerBase;
private IntPtr _frameSource;
private CaptureFrameSource _captureFrameSource;
public TwoPassStabilizer(Capture capture)
{
_captureFrameSource = new CaptureFrameSource(capture);
_ptr = VideoStabInvoke.TwoPassStabilizerCreate(_captureFrameSource, ref _stabilizerBase, ref _frameSource);
}
protected override IntPtr GetFrameSourcePointer()
{
return _frameSource;
_ptr = VideoStabInvoke.TwoPassStabilizerCreate(_captureFrameSource, ref _stabilizerBase, ref _framSourcePtr);
}
protected override void DisposeObject()
{
VideoStabInvoke.TwoPassStabilizerRelease(ref _ptr);
_stabilizerBase = IntPtr.Zero;
_frameSource = IntPtr.Zero;
_captureFrameSource.Dispose();
base.Dispose();
}

2
Emgu.CV.VideoStab/VideoStabInvoke.cs

@ -45,7 +45,7 @@ namespace Emgu.CV.VideoStab
internal static extern void TwoPassStabilizerRelease(ref IntPtr stabilizer);
[DllImport(CvInvoke.EXTERN_GPU_LIBRARY, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern IntPtr GaussianMotionFilterCreate(int radius, float stdev);
internal static extern IntPtr GaussianMotionFilterCreate();
[DllImport(CvInvoke.EXTERN_GPU_LIBRARY, CallingConvention = CvInvoke.CvCallingConvention)]
internal static extern void GaussianMotionFilterRelease(ref IntPtr filter);

Loading…
Cancel
Save