Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Conceição <Tiago_caza@hotmail.com>2020-06-24 00:34:53 +0300
committerTiago Conceição <Tiago_caza@hotmail.com>2020-06-24 00:34:53 +0300
commitc65a5a184f5cee6e1d5cec366b85691684422665 (patch)
tree6986026516b72bee137d5e2491685653a931d604 /UVtools.Core/Extensions/EmguExtensions.cs
parent68078da9cc948418030263654de68705667ed089 (diff)
Scaling corrections
Diffstat (limited to 'UVtools.Core/Extensions/EmguExtensions.cs')
-rw-r--r--UVtools.Core/Extensions/EmguExtensions.cs15
1 files changed, 14 insertions, 1 deletions
diff --git a/UVtools.Core/Extensions/EmguExtensions.cs b/UVtools.Core/Extensions/EmguExtensions.cs
index 7253837..53f78e2 100644
--- a/UVtools.Core/Extensions/EmguExtensions.cs
+++ b/UVtools.Core/Extensions/EmguExtensions.cs
@@ -10,7 +10,7 @@ using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Emgu.CV;
-using Emgu.CV.Structure;
+using Emgu.CV.CvEnum;
namespace UVtools.Core.Extensions
{
@@ -28,6 +28,19 @@ namespace UVtools.Core.Extensions
return mat.GetPixelSpan<T>().Slice(offset, mat.Step);
}
+ public static void ScaleFromCenter(this Mat src, double xScale, double yScale, double xTrans = 0, double yTrans = 0, Inter interpolation = Inter.Linear)
+ {
+ //var dst = new Mat(src.Size, src.Depth, src.NumberOfChannels);
+ var translateTransform = new Matrix<double>(2, 3)
+ {
+ [0, 0] = xScale, // xScale
+ [1, 1] = yScale, // yScale
+ [0, 2] = xTrans + (src.Width - src.Width * xScale) / 2.0, //x translation + compensation of x scaling
+ [1, 2] = yTrans + (src.Height - src.Height * yScale) / 2.0 // y translation + compensation of y scaling
+ };
+ CvInvoke.WarpAffine(src, src, translateTransform, src.Size, interpolation);
+ }
+
public static void CopyToCenter(this Mat src, Mat dst)
{
if (dst.Step > src.Step && dst.Height > src.Height)