-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added image gradients to wrapper. #163
Open
ejoebstl
wants to merge
3
commits into
takuya-takeuchi:master
Choose a base branch
from
ejoebstl:feature/gradients
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 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
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
src/DlibDotNet.Native/dlib/image_transforms/image_gradients.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "image_gradients.h" |
133 changes: 133 additions & 0 deletions
133
src/DlibDotNet.Native/dlib/image_transforms/image_gradients.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#ifndef _CPP_IMAGE_GRADIENTS_H_ | ||
#define _CPP_IMAGE_GRADIENTS_H_ | ||
|
||
#include "../export.h" | ||
#include <dlib/image_transforms/spatial_filtering.h> | ||
#include <dlib/image_transforms/edge_detector.h> | ||
#include "../template.h" | ||
#include "../shared.h" | ||
|
||
using namespace dlib; | ||
using namespace std; | ||
|
||
#pragma region template | ||
|
||
#define image_gradients_gradient_x_template(__TYPE__, error, type, ...) \ | ||
*((dlib::rectangle*)valid_area) = gradients->gradient_x(*((array2d<__TYPE__>*)in_image), *((array2d<float>*)out_image)); | ||
|
||
#define image_gradients_gradient_y_template(__TYPE__, error, type, ...) \ | ||
*((dlib::rectangle*)valid_area) = gradients->gradient_y(*((array2d<__TYPE__>*)in_image), *((array2d<float>*)out_image)); | ||
|
||
#define image_gradients_gradient_xx_template(__TYPE__, error, type, ...) \ | ||
*((dlib::rectangle*)valid_area) = gradients->gradient_xx(*((array2d<__TYPE__>*)in_image), *((array2d<float>*)out_image)); | ||
|
||
#define image_gradients_gradient_xy_template(__TYPE__, error, type, ...) \ | ||
*((dlib::rectangle*)valid_area) = gradients->gradient_xy(*((array2d<__TYPE__>*)in_image), *((array2d<float>*)out_image)); | ||
|
||
#define image_gradients_gradient_yy_template(__TYPE__, error, type, ...) \ | ||
*((dlib::rectangle*)valid_area) = gradients->gradient_yy(*((array2d<__TYPE__>*)in_image), *((array2d<float>*)out_image)); | ||
|
||
#pragma endregion template | ||
|
||
DLLEXPORT dlib::image_gradients* get_image_gradients(long scale) | ||
{ | ||
return new dlib::image_gradients(scale); | ||
} | ||
|
||
DLLEXPORT int image_gradients_gradient_x(dlib::image_gradients* gradients, | ||
array2d_type type, | ||
void* in_image, | ||
void* out_image, | ||
void* valid_area) | ||
{ | ||
int error = ERR_OK; | ||
|
||
array2d_nonalpha_template(type, | ||
error, | ||
image_gradients_gradient_x_template, | ||
in_image, | ||
out_image, | ||
valid_area); | ||
|
||
return error; | ||
} | ||
|
||
DLLEXPORT int image_gradients_gradient_y(dlib::image_gradients* gradients, | ||
array2d_type type, | ||
void* in_image, | ||
void* out_image, | ||
void* valid_area) | ||
{ | ||
int error = ERR_OK; | ||
|
||
array2d_nonalpha_template(type, | ||
error, | ||
image_gradients_gradient_y_template, | ||
in_image, | ||
out_image, | ||
valid_area); | ||
|
||
return error; | ||
} | ||
|
||
DLLEXPORT int image_gradients_gradient_xx(dlib::image_gradients* gradients, | ||
array2d_type type, | ||
void* in_image, | ||
void* out_image, | ||
void* valid_area) | ||
{ | ||
int error = ERR_OK; | ||
|
||
array2d_nonalpha_template(type, | ||
error, | ||
image_gradients_gradient_xx_template, | ||
in_image, | ||
out_image, | ||
valid_area); | ||
|
||
return error; | ||
} | ||
|
||
DLLEXPORT int image_gradients_gradient_xy(dlib::image_gradients* gradients, | ||
array2d_type type, | ||
void* in_image, | ||
void* out_image, | ||
void* valid_area) | ||
{ | ||
int error = ERR_OK; | ||
|
||
array2d_nonalpha_template(type, | ||
error, | ||
image_gradients_gradient_xy_template, | ||
in_image, | ||
out_image, | ||
valid_area); | ||
|
||
return error; | ||
} | ||
|
||
|
||
DLLEXPORT int image_gradients_gradient_yy(dlib::image_gradients* gradients, | ||
array2d_type type, | ||
void* in_image, | ||
void* out_image, | ||
void* valid_area) | ||
{ | ||
int error = ERR_OK; | ||
|
||
array2d_nonalpha_template(type, | ||
error, | ||
image_gradients_gradient_yy_template, | ||
in_image, | ||
out_image, | ||
valid_area); | ||
|
||
return error; | ||
} | ||
|
||
DLLEXPORT void image_gradients_delete(dlib::image_gradients* obj) | ||
{ | ||
delete obj; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using DlibDotNet.Extensions; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace DlibDotNet | ||
{ | ||
|
||
public sealed class ImageGradients : DlibObject | ||
{ | ||
|
||
#region Constructors | ||
|
||
public ImageGradients(long scale = 1) | ||
{ | ||
this.NativePtr = NativeMethods.get_image_gradients(scale); | ||
} | ||
|
||
#endregion | ||
|
||
#region Methods | ||
|
||
public Rectangle GetGradientX(Array2DBase image, Array2D<float> gradient) | ||
{ | ||
return InvokeGetGradient(image, gradient, NativeMethods.image_gradients_gradient_x); | ||
} | ||
public Rectangle GetGradientY(Array2DBase image, Array2D<float> gradient) | ||
{ | ||
return InvokeGetGradient(image, gradient, NativeMethods.image_gradients_gradient_y); | ||
} | ||
|
||
public Rectangle GetGradientXY(Array2DBase image, Array2D<float> gradient) | ||
{ | ||
return InvokeGetGradient(image, gradient, NativeMethods.image_gradients_gradient_xy); | ||
} | ||
|
||
public Rectangle GetGradientXX(Array2DBase image, Array2D<float> gradient) | ||
{ | ||
return InvokeGetGradient(image, gradient, NativeMethods.image_gradients_gradient_xx); | ||
} | ||
|
||
public Rectangle GetGradientYY(Array2DBase image, Array2D<float> gradient) | ||
{ | ||
return InvokeGetGradient(image, gradient, NativeMethods.image_gradients_gradient_yy); | ||
} | ||
|
||
|
||
private Rectangle InvokeGetGradient(Array2DBase image, Array2D<float> gradient, Func<IntPtr, NativeMethods.Array2DType, IntPtr, IntPtr, IntPtr, NativeMethods.ErrorType> gradientMethod) | ||
{ | ||
this.ThrowIfDisposed(); | ||
|
||
if (image == null) | ||
throw new ArgumentNullException(nameof(image)); | ||
|
||
if (gradient == null) | ||
throw new ArgumentNullException(nameof(image)); | ||
|
||
using(var rect = new Rectangle.NativeRectangle()) | ||
{ | ||
var inType = image.ImageType.ToNativeArray2DType(); | ||
|
||
var ret = gradientMethod(this.NativePtr, inType, image.NativePtr, gradient.NativePtr, rect.NativePtr); | ||
|
||
switch (ret) | ||
{ | ||
case NativeMethods.ErrorType.Array2DTypeTypeNotSupport: | ||
throw new ArgumentException($"Input {inType} is not supported."); | ||
} | ||
|
||
return rect.ToManaged(); | ||
} | ||
} | ||
|
||
#region Overrides | ||
|
||
/// <summary> | ||
/// Releases all unmanaged resources. | ||
/// </summary> | ||
protected override void DisposeUnmanaged() | ||
{ | ||
base.DisposeUnmanaged(); | ||
|
||
if (this.NativePtr == IntPtr.Zero) | ||
return; | ||
|
||
NativeMethods.image_gradients_delete(this.NativePtr); | ||
} | ||
|
||
#endregion | ||
|
||
#endregion | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace DlibDotNet | ||
{ | ||
|
||
internal sealed partial class NativeMethods | ||
{ | ||
|
||
[DllImport(NativeLibrary, CallingConvention = CallingConvention)] | ||
public static extern IntPtr get_image_gradients(long scale); | ||
|
||
[DllImport(NativeLibrary, CallingConvention = CallingConvention)] | ||
public static extern ErrorType image_gradients_gradient_x(IntPtr gradients, | ||
Array2DType imgType, | ||
IntPtr in_img, | ||
IntPtr out_img, | ||
IntPtr valid_rectangle); | ||
|
||
[DllImport(NativeLibrary, CallingConvention = CallingConvention)] | ||
public static extern ErrorType image_gradients_gradient_y(IntPtr gradients, | ||
Array2DType imgType, | ||
IntPtr in_img, | ||
IntPtr out_img, | ||
IntPtr valid_rectangle); | ||
|
||
[DllImport(NativeLibrary, CallingConvention = CallingConvention)] | ||
public static extern ErrorType image_gradients_gradient_xx(IntPtr gradients, | ||
Array2DType imgType, | ||
IntPtr in_img, | ||
IntPtr out_img, | ||
IntPtr valid_rectangle); | ||
|
||
|
||
[DllImport(NativeLibrary, CallingConvention = CallingConvention)] | ||
public static extern ErrorType image_gradients_gradient_xy(IntPtr gradients, | ||
Array2DType imgType, | ||
IntPtr in_img, | ||
IntPtr out_img, | ||
IntPtr valid_rectangle); | ||
|
||
[DllImport(NativeLibrary, CallingConvention = CallingConvention)] | ||
public static extern ErrorType image_gradients_gradient_yy(IntPtr gradients, | ||
Array2DType imgType, | ||
IntPtr in_img, | ||
IntPtr out_img, | ||
IntPtr valid_rectangle); | ||
|
||
[DllImport(NativeLibrary, CallingConvention = CallingConvention)] | ||
public static extern void image_gradients_delete(IntPtr gradients); | ||
|
||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nameof(gradient)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And, you created feature branch but it does not derive from develop branch.
Why don't you use gitflow?
By chance, does github PR force to create branch from master?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. Done.
Regarding the branch, I don't understand?
Should I branch from development instead of master?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.