@@ -18,29 +18,10 @@ namespace Aardvark.OpenCV
18
18
public void Dispose ( ) => Handle . Free ( ) ;
19
19
}
20
20
21
- internal static class PinningExtensions
21
+ internal static class Extensions
22
22
{
23
23
public static GCHandleDiposable Pin ( this object obj )
24
24
=> new ( GCHandle . Alloc ( obj , GCHandleType . Pinned ) ) ;
25
- }
26
-
27
- public static class ImageProcessing
28
- {
29
- [ OnAardvarkInit ]
30
- public static void Init ( )
31
- {
32
- PixImage < byte > . SetScaledFun ( ScaledOpenCV ) ;
33
- PixImage < sbyte > . SetScaledFun ( ScaledOpenCV ) ;
34
- PixImage < ushort > . SetScaledFun ( ScaledOpenCV ) ;
35
- PixImage < short > . SetScaledFun ( ScaledOpenCV ) ;
36
- PixImage < uint > . SetScaledFun ( ScaledOpenCV ) ;
37
- PixImage < int > . SetScaledFun ( ScaledOpenCV ) ;
38
- PixImage < ulong > . SetScaledFun ( ScaledOpenCV ) ;
39
- PixImage < long > . SetScaledFun ( ScaledOpenCV ) ;
40
- PixImage < Half > . SetScaledFun ( ScaledOpenCV ) ;
41
- PixImage < float > . SetScaledFun ( ScaledOpenCV ) ;
42
- PixImage < double > . SetScaledFun ( ScaledOpenCV ) ;
43
- }
44
25
45
26
private static readonly Dictionary < Type , Func < int , MatType > > matTypes = new ( )
46
27
{
@@ -53,7 +34,7 @@ public static void Init()
53
34
{ typeof ( double ) , MatType . CV_64FC } ,
54
35
} ;
55
36
56
- private static MatType ToMatType ( this Type type , int channels )
37
+ public static MatType ToMatType ( this Type type , int channels )
57
38
{
58
39
if ( matTypes . TryGetValue ( type , out var toMatType ) ) return toMatType ( channels ) ;
59
40
else throw new NotSupportedException ( $ "Channel type { type } is not supported.") ;
@@ -67,14 +48,29 @@ private static MatType ToMatType(this Type type, int channels)
67
48
{ ImageInterpolation . Lanczos , InterpolationFlags . Lanczos4 } ,
68
49
} ;
69
50
70
- private static InterpolationFlags ToInterpolationFlags ( this ImageInterpolation interpolation )
51
+ public static InterpolationFlags ToInterpolationFlags ( this ImageInterpolation interpolation )
71
52
{
72
53
if ( interpolationFlags . TryGetValue ( interpolation , out InterpolationFlags flags ) ) return flags ;
73
54
else throw new NotSupportedException ( $ "Filter { interpolation } is not supported.") ;
74
55
}
56
+ }
57
+
58
+ public sealed class PixProcessor : IPixProcessor
59
+ {
60
+ public string Name => "OpenCV" ;
61
+
62
+ public PixProcessorCaps Capabilities => PixProcessorCaps . Scale ;
75
63
76
- public static Volume < T > ScaledOpenCV < T > ( this Volume < T > src , V2d scaleFactor , ImageInterpolation interpolation )
64
+ [ OnAardvarkInit ]
65
+ public static void Init ( )
66
+ {
67
+ PixImage . AddProcessor ( Instance ) ;
68
+ }
69
+
70
+ public PixImage < T > Scale < T > ( PixImage < T > image , V2d scaleFactor , ImageInterpolation interpolation )
77
71
{
72
+ var src = image . Volume ;
73
+
78
74
if ( ! src . HasImageWindowLayout ( ) )
79
75
{
80
76
throw new ArgumentException ( $ "Volume must be in image layout (Delta = { src . Delta } ).") ;
@@ -104,10 +100,23 @@ public static Volume<T> ScaledOpenCV<T>(this Volume<T> src, V2d scaleFactor, Ima
104
100
var dstMat = CvMat . FromPixelData ( dstSize . Y , dstSize . X , matType , dstPtr ) ;
105
101
Cv2 . Resize ( srcMat , dstMat , new Size ( dstSize . X , dstSize . Y ) , interpolation : interpolation . ToInterpolationFlags ( ) ) ;
106
102
107
- return dst ;
103
+ return new ( image . Format , dst ) ;
108
104
}
109
105
110
- public static PixImage < T > ScaledOpenCV < T > ( this PixImage < T > src , V2d scaleFactor , ImageInterpolation interpolation )
111
- => new ( src . Format , src . Volume . ScaledOpenCV ( scaleFactor , interpolation ) ) ;
106
+ public PixImage < T > Rotate < T > ( PixImage < T > image , double angleInRadians , bool resize , ImageInterpolation interpolation ,
107
+ ImageBorderType borderType = ImageBorderType . Const ,
108
+ T border = default )
109
+ => null ;
110
+
111
+ public PixImage < T > Remap < T > ( PixImage < T > image , Matrix < float > mapX , Matrix < float > mapY , ImageInterpolation interpolation ,
112
+ ImageBorderType borderType = ImageBorderType . Const ,
113
+ T border = default )
114
+ => null ;
115
+
116
+ private PixProcessor ( ) { }
117
+
118
+ private static readonly Lazy < PixProcessor > _instance = new ( ( ) => new PixProcessor ( ) ) ;
119
+
120
+ public static PixProcessor Instance => _instance . Value ;
112
121
}
113
122
}
0 commit comments