Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions MergeDebevec.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;

namespace OpenCvSharp
{
/// <summary>
/// The base class algorithms that can merge exposure sequence to a single image.
/// </summary>
public class MergeDebevec : MergeExposures
{
private Ptr? ptrObj;

/// <summary>
/// Creates instance by raw pointer cv::ml::Boost*
/// </summary>
protected MergeDebevec(IntPtr p)
: base()
{
ptrObj = new Ptr(p);
ptr = ptrObj.Get();
}

/// <summary>
/// Creates the empty model.
/// </summary>
/// <returns></returns>
public static MergeDebevec Create()
{
var ptr = NativeMethods.photo_createMergeDebevec();
return new MergeDebevec(ptr);
}

/// <summary>
/// Releases managed resources
/// </summary>
protected override void DisposeManaged()
{
ptrObj?.Dispose();
ptrObj = null;
base.DisposeManaged();
}

internal class Ptr : OpenCvSharp.Ptr
{
public Ptr(IntPtr ptr) : base(ptr)
{
}

public override IntPtr Get()
{
var res = NativeMethods.photo_Ptr_MergeDebevec_get(ptr);
GC.KeepAlive(this);
return res;
}

protected override void DisposeUnmanaged()
{
NativeMethods.photo_Ptr_MergeDebevec_delete(ptr);
base.DisposeUnmanaged();
}
}
}
}
45 changes: 45 additions & 0 deletions MergeExposures.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using OpenCvSharp.Util;

namespace OpenCvSharp
{
/// <summary>
/// The base class algorithms that can merge exposure sequence to a single image.
/// </summary>
public class MergeExposures : Algorithm
{
/// <summary>
/// Merges images.
/// </summary>
/// <param name="src">vector of input images</param>
/// <param name="dst">result image</param>
/// <param name="times">vector of exposure time values for each image</param>
/// <param name="response"> 256x1 matrix with inverse camera response function for each pixel value, it should have the same number of channels as images.</param>
public virtual void Process(IEnumerable<Mat> src, OutputArray dst, IEnumerable<float> times, InputArray response)
{
if (src == null)
throw new ArgumentNullException(nameof(src));
if (dst == null)
throw new ArgumentNullException(nameof(dst));
if (times == null)
throw new ArgumentNullException(nameof(times));
if (response == null)
throw new ArgumentNullException(nameof(response));
dst.ThrowIfNotReady();

var srcArray = EnumerableEx.SelectPtrs(src);
var timesArray = EnumerableEx.ToArray(times);
if (srcArray.Length != timesArray.Length)
throw new OpenCvSharpException("src.Count() != times.Count");

NativeMethods.photo_MergeExposures_process(ptr, srcArray, srcArray.Length, dst.CvPtr, timesArray, response.CvPtr);

dst.Fix();
GC.KeepAlive(this);
GC.KeepAlive(src);
GC.KeepAlive(dst);
GC.KeepAlive(response);
}
}
}
84 changes: 84 additions & 0 deletions MergeMertens.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using OpenCvSharp.Util;

namespace OpenCvSharp
{
public class MergeMertens : MergeExposures
{
private Ptr? ptrObj;

/// <summary>
/// Creates instance by raw pointer cv::ml::Boost*
/// </summary>
protected MergeMertens(IntPtr p)
: base()
{
ptrObj = new Ptr(p);
ptr = ptrObj.Get();
}

/// <summary>
/// Creates the empty model.
/// </summary>
/// <returns></returns>
public static MergeMertens Create()
{
var ptr = NativeMethods.photo_createMergeMertens();
return new MergeMertens(ptr);
}

/// <summary>
/// Short version of process, that doesn't take extra arguments.
/// </summary>
/// <param name="src">vector of input images</param>
/// <param name="dst">result image</param>
public virtual void Process(IEnumerable<Mat> src, OutputArray dst)
{
if (src == null)
throw new ArgumentNullException(nameof(src));
if (dst == null)
throw new ArgumentNullException(nameof(dst));

dst.ThrowIfNotReady();

var srcArray = EnumerableEx.SelectPtrs(src);

NativeMethods.photo_MergeMertens_process(ptr, srcArray, srcArray.Length, dst.CvPtr);

GC.KeepAlive(this);
GC.KeepAlive(src);
dst.Fix();
}

/// <summary>
/// Releases managed resources
/// </summary>
protected override void DisposeManaged()
{
ptrObj?.Dispose();
ptrObj = null;
base.DisposeManaged();
}

internal class Ptr : OpenCvSharp.Ptr
{
public Ptr(IntPtr ptr) : base(ptr)
{
}

public override IntPtr Get()
{
var res = NativeMethods.photo_Ptr_MergeMertens_get(ptr);
GC.KeepAlive(this);
return res;
}

protected override void DisposeUnmanaged()
{
NativeMethods.photo_Ptr_MergeMertens_delete(ptr);
base.DisposeUnmanaged();
}
}
}
}
64 changes: 64 additions & 0 deletions NativeMethods_photo_HDR.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Runtime.InteropServices;

#pragma warning disable 1591
// ReSharper disable InconsistentNaming

namespace OpenCvSharp
{
static partial class NativeMethods
{
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern IntPtr photo_createCalibrateDebevec(int samples, float lambda, int random);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern IntPtr photo_createCalibrateRobertson(int maxIter, float threshold);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void photo_Ptr_CalibrateDebevec_delete(IntPtr obj);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void photo_Ptr_CalibrateRobertson_delete(IntPtr obj);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern IntPtr photo_Ptr_CalibrateDebevec_get(IntPtr obj);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern IntPtr photo_Ptr_CalibrateRobertson_get(IntPtr obj);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void photo_CalibrateCRF_process(
IntPtr obj, IntPtr[] srcImgs, int srcImgsLength, IntPtr dst, [In, MarshalAs(UnmanagedType.LPArray)] float[] times);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern IntPtr photo_createMergeDebevec();
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void photo_Ptr_MergeDebevec_delete(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern IntPtr photo_Ptr_MergeDebevec_get(IntPtr obj);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern IntPtr photo_createMergeMertens();
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void photo_Ptr_MergeMertens_delete(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern IntPtr photo_Ptr_MergeMertens_get(IntPtr obj);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void photo_MergeExposures_process(
IntPtr obj, IntPtr[] srcImgs, int srcImgsLength, IntPtr dst, [In, MarshalAs(UnmanagedType.LPArray)] float[] times, IntPtr response);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern IntPtr photo_MergeMertens_process(IntPtr obj, IntPtr[] srcImgs, int srcImgsLength, IntPtr dst);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern IntPtr photo_createTonemap(float gamma);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void photo_Ptr_Tonemap_delete(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern IntPtr photo_Ptr_Tonemap_get(IntPtr obj);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern IntPtr photo_Tonemap_process(IntPtr obj, IntPtr src, IntPtr dst);
}
}
87 changes: 87 additions & 0 deletions Tonemap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using OpenCvSharp.Util;

namespace OpenCvSharp
{
/// <summary>
/// Base class for tonemapping algorithms - tools that are used to map HDR image to 8-bit range.
/// </summary>
public class Tonemap : Algorithm
{
private Tonemap.Ptr? ptrObj;

/// <summary>
/// Creates instance by raw pointer cv::ml::Boost*
/// </summary>
protected Tonemap(IntPtr p)
: base()
{
ptrObj = new Tonemap.Ptr(p);
ptr = ptrObj.Get();
}

/// <summary>
/// Creates simple linear mapper with gamma correction
/// </summary>
/// <param name="gamma">gamma positive value for gamma correction. Gamma value of 1.0 implies no correction, gamma equal to 2.2f is suitable for most displays. Generally gamma \> 1 brightens the image and gamma \< 1 darkens it.</param>
/// <returns></returns>
public static Tonemap Create(float gamma = 2.2f)
{
var ptr = NativeMethods.photo_createTonemap(gamma);
return new Tonemap(ptr);
}

/// <summary>
/// Releases managed resources
/// </summary>
protected override void DisposeManaged()
{
ptrObj?.Dispose();
ptrObj = null;
base.DisposeManaged();
}

/// <summary>
/// Tonemaps image
/// </summary>
/// <param name="src">source image - CV_32FC3 Mat (float 32 bits 3 channels)</param>
/// <param name="dst">destination image - CV_32FC3 Mat with values in [0, 1] range</param>
public virtual void Process(InputArray src, OutputArray dst)
{
if (src == null)
throw new ArgumentNullException(nameof(src));
if (dst == null)
throw new ArgumentNullException(nameof(dst));

src.ThrowIfDisposed();
dst.ThrowIfNotReady();

NativeMethods.photo_Tonemap_process(ptr, src.CvPtr, dst.CvPtr);

GC.KeepAlive(this);
GC.KeepAlive(src);
dst.Fix();
}

internal class Ptr : OpenCvSharp.Ptr
{
public Ptr(IntPtr ptr) : base(ptr)
{
}

public override IntPtr Get()
{
var res = NativeMethods.photo_Ptr_Tonemap_get(ptr);
GC.KeepAlive(this);
return res;
}

protected override void DisposeUnmanaged()
{
NativeMethods.photo_Ptr_Tonemap_delete(ptr);
base.DisposeUnmanaged();
}
}
}
}
Loading