EMGU with Xamarin Forms guide [part 1]


I- Introduction, OpenCV and EMGU

Do you know OpenCV (Open Source Computer Vision Library: https://opencv.org/) ?  This open source library let's you work and play with images and videos with a lot of powerful image processing algorithms !  If you want some details, I suggest you to first navigate to the link above or search for 'OpenCV' on Google. 

Examples of OpenCV processing found on the web (filters, object detection, edges...):





EMGU is a .NET OpenCV wrapper. That means that you will be able to use OpenCV functionnalities in your .NET projects using C# for instance. EMGU is cross platform, so you will also be able to use it in your Xamarin projects ! That's great because there is no advanced image processing library in Xamarin.

In this article, we will talk about EMGU and list the steps to setup a Xamarin Forms project using EMGU. It may help you because, we must say that it's not a trivial task... 



II-What do I need to start ?

1- A licence please

The first thing you have to understand, is that you will need to purchase a commercial licence to use EMGU with mobile devices (so with Xamarin). You can refer to this page for all the details:
- http://www.emgu.com/wiki/index.php/Main_Page#Mobile_Devices



The website isn't so clear so here is the purchase link:
- http://www.emgu.com/wiki/index.php/Commercial_License_Purchase

2- iOS and Android libraries

Once you have purchased a licence, you will have access to a link where from you can download the libraries. In our case we need the iOS and Android libs.


As we will see in the next section, inside the extracted folders, you will find the source code but also:

  • - Needed Android libraries to be able to build your Xamarin Android projects
  • - Needed iOS DLL to be able to build your Xamarin iOS projects


Needed folder to build for Android:

Needed library to build for iOS:



III- Next, setup your Xamarin project to use EMGU


1- Create your project solution

First thing to do is to create a Solution for your project. In our example we will use Visual Studio to do this, but you can also try with VS for MAC. See picture below:



EMGU does not provides PCL library, that means that you will have to create a project with the "shared project" option instead of a "Portable Class Project". See picture below:



When asked, you should cancel the creation of Windows 10 projects (it's not in the scope of this article):


The base project will include:
- Shared project: you will put inside all your shared Pages for instance, or your shared services between iOS and Android
- Xamarin.Android project: you will put inside all your related Android services and classes
- Xamarin.iOS project: will contain all your iOS classes
- All EMGU Android / iOS needed libraries as we will see in the next chapter



2- Reference EMGU

When your empty Xamarin shared project is ready, you will have to make reference to EMGU component, for Android & for iOS projects.

- Notice that these process are not the same for Android & iOS !

2.a- Reference EMGU in your Android project

For Android, I think the best choice you have is to integrate the EMGU shared projects directly into your solution. Copy the Android projects that you extracted previously. Projects you need are listed below. In my example, I separate those projects in a specific solution folder called "EmguLib". 

Then you just have to reference those shared project from the Android one. Here is the organisation for Android:

Android: How to reference EMGU library

If you try to build the project now, you will surely have a compilation error:

"This package do not contain necessary binary for Xamarin Android App. Emgu CV for Android Commercial Licence is required. x86...."


Don't be afraid. We talked about it in the previous paragraph. You just have to copy / paste the "libs" folder from the android sources you downloaded to your project (at the same level as your EMGU shared projects that you reference). All will be good if you bought the licence :p



2.b- Reference EMGU in your iOS project

For iOS, it's a little bit "simpler" because you just have to copy one DLL library (specially compiled for iOS) and reference it into your iOS project. You can place it where you want into your solution hierarchy but take care the file is big ! (about 210 Mb).

File to reference in your iOS project (as seen in the previous paragraph):
--> EMGU.CV.World.iOS.dll

You should have something like that:




You are ready !


Steps below are not complicated, but there is no really helpful documentation about how to setup EMGU with XAMARIN FORMS. You can just try to inspect the sample projects. After playing around really shortly with EMGU, in a few line of code:

- I opened an asset image
- loaded it into a 'Mat' openCV object
- applied a Canny edge algorithm on it
- then displayed the image

Tada !

First step, load an image
Apply the 'Canny Edge Detector algorithm', and here is the result for Android & iOS:




It's only the begining. At this point, if you are new with OpenCV, you can try algorithms you want just to learn. On my side, new Xamarin Forms + EMGU articles will come, so  follow me ;) !





Comments

  1. Hi there, can you please tell us that how you displayed image in xamarin forms..? how did you convert image from Mat to xamarin forms image control and display it..?

    ReplyDelete
  2. Hi, could you please send me the code for this? Thank you in advance

    ReplyDelete
  3. Hi, could you please send me the code for this? thank you in advance

    ReplyDelete
  4. Hi,
    Wonderful information. Thanks.
    I have a question , how to send data in XML/JSON format from Android mobile to another webapi.
    Can you reply it?
    Thanks in advance.

    Hire Xamarin Developer

    ReplyDelete

Post a Comment

Popular posts from this blog

[Xamarin Forms] Custom bottom bordered entry (iOS & Android)

Set your browser on Fire with P5.js