scale before stitch
This commit is contained in:
parent
8d4b2bc943
commit
d26bcf545c
4 changed files with 47 additions and 4 deletions
|
|
@ -66,7 +66,47 @@ public class ImageGenerator
|
|||
double newWidth = temp.Width * scale;
|
||||
double newHeight = temp.Height * scale;
|
||||
|
||||
temp.Resize(new Size(newWidth, newHeight));
|
||||
var resized = temp.Resize(new Size(newWidth, newHeight));
|
||||
var result = resized.ImEncode();
|
||||
var end = DateTime.Now;
|
||||
var elapsed = end - start;
|
||||
Console.WriteLine($"Elapsed: {elapsed.TotalMilliseconds} ms");
|
||||
return result;
|
||||
}
|
||||
|
||||
public byte[] GenerateImage3(RequestBody requestBody)
|
||||
{
|
||||
var start = DateTime.Now;
|
||||
string[] inputs = requestBody.CanvasRect.Split(":");
|
||||
double scale = requestBody.OutputScale;
|
||||
Coordinate a1 = new Coordinate("A1");
|
||||
Mat a1Mat = new Mat(a1.Path);
|
||||
int width = a1Mat.Width;
|
||||
int height = a1Mat.Height;
|
||||
if (scale < 1)
|
||||
{
|
||||
width = (int)(width * scale);
|
||||
height = (int)(height * scale);
|
||||
a1Mat = a1Mat.Resize(new Size(width, height));
|
||||
}
|
||||
|
||||
Coordinate coord0 = new Coordinate(inputs[0]);
|
||||
Coordinate coord1 = new Coordinate(inputs[1]);
|
||||
|
||||
(var matrix, int rowCount, int colCount) = GenerateMatrix(coord0, coord1);
|
||||
Mat temp = GenerateTempMat(a1Mat, rowCount, colCount);
|
||||
|
||||
Parallel.ForEach(matrix, item =>
|
||||
{
|
||||
Mat mat = new Mat(item.Path);
|
||||
if (scale < 1)
|
||||
{
|
||||
mat = mat.Resize(new Size(width, height));
|
||||
}
|
||||
Rect rect = new Rect((item.Col - 1) * a1Mat.Cols, (item.Row - 1) * a1Mat.Rows, a1Mat.Cols, a1Mat.Rows);
|
||||
mat.CopyTo(temp[rect]);
|
||||
});
|
||||
|
||||
var result = temp.ImEncode();
|
||||
var end = DateTime.Now;
|
||||
var elapsed = end - start;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue