问题
I'm using portable.aforge.imaging for image comparison on a UWP project. The method ProcessImage requires Bitmap type as arguments. I'm using System.Drawing to access Bitmap class, but i'm getting errors when i try to instantiate: "Bitmap does not contains a constructor that takes 1 argument"
Does regular Bitmap class is available on UWP? if yes, what am i doing wrong? if not, what alternatives do i have to use the aforge's ProcessImage for comparison?
private void TestAForge()
{
ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0);
Bitmap image, template;
//fetch Bitmaps
image = new Bitmap("MyDir/myImage.jpg");
template = new Bitmap("MyDir/myImage.jpg");
// compare two images
TemplateMatch[] matchings = tm.ProcessImage(image, template);
// check similarity level
TextBlock.Text = "" + matchings[0].Similarity;
if (matchings[0].Similarity > 0.95)
{
// do something with quite similar images
}
}
回答1:
Yes, System.Drawing.Bitmap
is available via the Shim.Drawing assembly for AForge on the Universal Windows Platform.
As Clemens suggests, you need to cast from a WriteableBitmap
to a System.Drawing.Bitmap
, apply the AForge imaging operations on the Bitmap
and finally cast back to WriteableBitmap
(or BitmapSource
or ImageSource
).
An example of where this workflow is implemented can be found in the Corner.SURF.Windows sample in the accord-samples repository, in the file MainPage.xaml.cs.
来源:https://stackoverflow.com/questions/36041653/aforge-image-comparison-with-uwp