AForge.Net Filters alternatives for Monotouch

2019-07-16 08:52发布

问题:

Is there any options? I can't get it worked for Monotouch. Seems like some functions missing from AForge*.dll's. Now, I'm looking at OpenCV, but it's just too complicated for such a simple problem. But still very interesting :)

Well, there is no problem with System.Drawing.Bitmap, I've built it from github.com/mono/ and it worked. But there is errors related to AForge framework. When I try to apply filter through Bitmap Apply (Bitmap image) from AForge.Imaging.Filters.BaseFilter I'm getting the error:

Error CS0584: Internal compiler error: Method not found: 'AForge.Imaging.UnmanagedImage.CollectActivePixels'. (CS0584) (projectName)

Also, when I'm trying to use AForge.Imaging.Filters.Sepia or Invert, compiler couldn't find them:

Error CS0584: Internal compiler error: Could not import type AForge.Imaging.Filters.Sepia' fromAForge.Imaging, Version=2.2.4.0, Culture=neutral, PublicKeyToken=ba8ddea9676ca48b' (CS0584) (projectName)

The interesting thing is that AForge.Imaging.Filters.Grayscale found.

Here is the code that produces these errors:

This one produces "Could not import type" errors:

partial void showFilters (MonoTouch.Foundation.NSObject sender)
    {
        UIActionSheet sheet = new UIActionSheet ("Filters");
        // @TODO: I'll hardcode filters for now, but in future it should be refactored out.
        sheet.AddButton ("Grayscale");
        sheet.AddButton ("Sepia");
        sheet.AddButton ("Invert");
        sheet.Clicked += 
            (sndr, e) => {
            var ev = (UIButtonEventArgs)e;
            switch (ev.ButtonIndex) {
            case 0:
                imageView.Image = ImageProcessor.process (imageView.Image, new Grayscale(0.2125, 0.7154, 0.0721));
                break;
            case 1:
                imageView.Image = ImageProcessor.process (imageView.Image, new Sepia());
                break;
            case 2:
                imageView.Image = ImageProcessor.process (imageView.Image, new Invert());
                break;
            }
            imageView.Image.SaveToPhotosAlbum((image, error) => {
                var o = image as UIImage;
                Console.WriteLine("error:" + error);
            });
        };
        sheet.ShowInView (this.View);
    }

First 3 functions produces "Method not found: 'AForge.Imaging.UnmanagedImage.CollectActivePixels'.:

    #region methods
    static public Bitmap process (String fileName, IFilter filter)
    {
        if (File.Exists (fileName)) {
            Bitmap bitmap = Bitmap.FromFile (fileName);
            Bitmap image = (Bitmap) filter.Apply (bitmap);
            return image;
        } else {
            throw (new FileNotFoundException());
        }
    }

    static public Bitmap process (String fileName, FiltersSequence seq)
    {
        if (File.Exists (fileName)) {
            Bitmap image = Bitmap.FromFile (fileName);
            image = seq.Apply (image);
            return image;
        } else {
            throw (new FileNotFoundException());
        }
    }
    #region iOS
    static public UIImage process (UIImage capturedImage, IFilter filter)
    {
        Bitmap bitmap = getBitmapFromUIImage (capturedImage);
        Bitmap image = (Bitmap) filter.Apply (bitmap);
        UIImage result = getUIImageFromBitmap (image);
        return result;
    }

    static public Bitmap getBitmapFromUIImage (UIImage capturedImage)
    {
        NSData imageData = capturedImage.AsPNG();
        Byte[] byteArray = new Byte[imageData.Length];
        System.Runtime.InteropServices.Marshal.Copy (imageData.Bytes,
                                                     byteArray,
                                                     0,
                                                     Convert.ToInt32 (imageData.Length));
        MemoryStream stream = new MemoryStream (byteArray);
        Bitmap bitmap = new Bitmap (stream, false);
        return bitmap;
    }

    static public UIImage getUIImageFromBitmap (Bitmap bitmap)
    {
        Byte[] byteArray;
        MemoryStream stream = new MemoryStream();
        bitmap.Save(stream);
        stream.Close();
        byteArray = stream.ToArray();
        NSData imageData = NSData.FromArray(byteArray);
        return UIImage.LoadFromData(imageData);
    }
    #endregion iOS
    #endregion methods

}

And the complete list of errors:

Error CS0584: Internal compiler error: Could not import type `AForge.Imaging.Filters.Sepia' from `AForge.Imaging, Version=2.2.4.0, Culture=neutral, PublicKeyToken=ba8ddea9676ca48b' (CS0584) (tryingImageProcessing)
Error CS0584: Internal compiler error: Could not import type `AForge.Imaging.Filters.Invert' from `AForge.Imaging, Version=2.2.4.0, Culture=neutral, PublicKeyToken=ba8ddea9676ca48b' (CS0584) (tryingImageProcessing)
Error CS0584: Internal compiler error: Method not found: 'AForge.Imaging.UnmanagedImage.CollectActivePixels'. (CS0584) (tryingImageProcessing)
Error CS0266: Cannot implicitly convert type `object' to `System.Drawing.Bitmap'. An explicit conversion exists (are you missing a cast?) (CS0266) (tryingImageProcessing)

I didn't say anything about the last error because it's easy to repair, but I can't understand why it's showing up. It cries about:

Bitmap image = ((BaseFilter) filter).Apply (bitmap);

And every line where I use Apply.

This is the project itself (Monodevelop, zipped).

Answer: Monodevelop. Method that visible from Assembly Browser not found. (CS0584)