gpt4 book ai didi

c# - Microsoft Image Composite Editor StitchEngine.dll 的最小工作示例

转载 作者:太空宇宙 更新时间:2023-11-03 12:06:17 25 4
gpt4 key购买 nike

我们要使用 StitchEngine.dll来 self 们的一个 C# 项目中的 Microsoft Image Composite Editor (ICE)。很少有证据表明人们已经完成了这项任务,例如理查德在这个 SO 问题中 Getting an "InvalidCastException" when passing a Rectangle ValueType in c# .所以,我们的问题是,是否有人可以提供一个最小的工作示例,即加载两个图像、拼接它们并导出生成的图像。

目前,我们已经卡在了加载(或初始化)部分。我们调查了 StitchEngineWrapperStitchProjectInfo类,但无法弄清楚如何加载图像。 StitchEngineWrapper.AddImageCacheLocations(IReadOnlyList<string> imageCacheLocations)方法对我们不起作用!? List<ImageInfo> StitchProjectInfo.SourceImages属性不可访问!?使用 ILSpy也没有帮助我们。

非常感谢每一个正确方向的提示!希望 Richard 会看到这个问题。

最佳答案

ICE 是一个在后台运行的状态机,因此您必须等待每个步骤完成才能进行下一步。如果您至少添加了两个有效图像(首先使用 UI 进行测试),下面是一个应该可以运行的示例控制台 C# 应用程序:

class Program
{
static void Main(string[] args)
{
using (var stitch = new StitchEngineWrapper()) // using Microsoft.Research.ICE.Stitching;
{
var taskCompleted = new AutoResetEvent(false);
stitch.ProgressChanged += (s, e) => Console.Write(".");
stitch.TaskCompleted += (s, e) =>
{
Console.WriteLine();
taskCompleted.Set();
};

var pi = new StitchProjectInfo();
pi.SourceImages.Add(new ImageInfo(@"c:\myPath\lenna1.jpg", null));
pi.SourceImages.Add(new ImageInfo(@"c:\myPath\lenna2.jpg", null));
if (!stitch.InitializeFromProjectInfo(pi) || stitch.HasLastError)
{
Console.WriteLine("Initialization failed.");
if (stitch.HasLastError)
{
Console.WriteLine("Error 0x" + stitch.LastError.ToString("x8") + ": " + stitch.LastErrorMessage);
}
return;
}
Console.WriteLine("Initialization ok.");

stitch.StartAligning();
taskCompleted.WaitOne(Timeout.Infinite);
if (stitch.AlignedCount < 2 || stitch.HasLastError)
{
Console.WriteLine("Alignement failed. Wrong input.");
Console.WriteLine("Error 0x" + stitch.LastError.ToString("x8") + ": " + stitch.LastErrorMessage);
return;
}
Console.WriteLine("Alignement ok.");

stitch.StartCompositing();
taskCompleted.WaitOne(Timeout.Infinite);
if (stitch.HasLastError)
{
Console.WriteLine("Composition failed.");
Console.WriteLine("Error 0x" + stitch.LastError.ToString("x8") + ": " + stitch.LastErrorMessage);
return;
}
Console.WriteLine("Composition ok.");

stitch.StartProjecting();
taskCompleted.WaitOne(Timeout.Infinite);
if (stitch.HasLastError)
{
Console.WriteLine("Projection failed.");
Console.WriteLine("Error 0x" + stitch.LastError.ToString("x8") + ": " + stitch.LastErrorMessage);
return;
}
Console.WriteLine("Projection ok.");

var options = new OutputOptions(ExportFormat.JPEG, 75, true, false, false);
stitch.StartExporting(@"c:\myPath\stitched.jpg", stitch.ResetCropRect, 1, options, false);
taskCompleted.WaitOne(Timeout.Infinite);
Console.WriteLine("Export ok.");
}
}
}

这是一个示例 Lenna stiched(注意图像 Y 偏移和重叠):

左:

enter image description here

右:

enter image description here

缝合:

enter image description here

请注意右侧由于缝合而产生的黑色伪像和有趣的头发

关于c# - Microsoft Image Composite Editor StitchEngine.dll 的最小工作示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54800001/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com