On Aug 14, 2012, at 9:15 AM, antoniolopes <[email protected]> wrote:
> We want to add http://opencv.willowgarage.com/wiki/ OpenCV features in Mono
> for Android as we use them already in our app (using a wrapper of OpenCV to
> java called https://code.google.com/p/javacv/ JavaCV - OpenCV is a c++
> library).
>
> The wrapper that we want to use for our Mono for Android project is
> https://code.google.com/p/opencvsharp/ OpenCvSharp . This wrapper is written
> in C# and compiles and run on Unix Environment just adding the precompiled
> .dll references to the MonoDevelop project.
One problem will be the license: OpenCV# appears to be LGPL, which requires
that you be able to update the LGPL library separately from your app. This
isn't possible for Mono for Android apps, as the assemblies are embedded into
the .apk and the .apk is signed to prevent modification. (As always, I'm not a
lawyer, this is not legal advice, yadda yadda yadda, but I don't see how you
can square this circle.)
Glancing through the opencvsharp sources, other potential problems include:
* Use of System.Drawing.dll: Mono for Android does not provide
System.Drawing.dll, so any types/members that require it will need to be #if'd
out, e.g. OpenCvSharp.IplImage.FromBitmap().
* Use of System.Windows.Forms.dll: Mono or Android does not provide
System.Windows.Forms.dll, so any types/members that require it will need to be
#if'd out, e.g. OpenCvSharp.Utilities.PInvokeHelper.DllImportError() (which
uses MessageBox.Show()).
* OpenCvSharp is a DllImport wrapper over numerous native libraries such as
opencv_core240 and opencv_imgproc240. You will need to recompile all of these
libraries as armeabi(-v7a?) ELF shared libraries for use in your app. This in
turn requires using the Android NDK, unless someone is already building &
distributing Android builds of these libraries...
> Being a noob in C# i would have thought that adding the reference dll in the
> Mono for Android project would do the trick but apparently it does not.
Mono for Android is a distinct "profile," with an incompatible set of
assemblies from regular .NET. Just as you can't use desktop .NET assemblies
with .NET Compact Framework or Silverlight 3.0 (and 4.0 is iffy), you cannot
use desktop .NET assemblies as-is with Mono for Android. You need to recompile
your sources against the Mono for Android profile assemblies.
An easy way to do this is to take e.g. OpenCvSharp\OpenCvSharp.csproj and
replace the line:
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
with:
<Import
Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
Then modify <TargetFrameworkVersion/> to match the Android API level you wish
to target, or delete the element entirely to target the default API level of 8.
Then, build:
cd Path\To\OpenCvSharp
msbuild
Shockingly (to me), with the above 2 changes OpenCvSharp.dll builds for me.
Unfortunately the build is wrong [0], as it contains references to
System.Windows.Forms.dll and System.Drawing.dll, neither of which are usable
within a Mono for Android app. Edit the OpenCvSharp.csproj again, and remove
the following elements:
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
Rebuild, and I get 18 errors that need to be fixed before the assembly can even
begin to be usable with Mono for Android.
Once fixed, "all" you'll need to do is reference your new OpenCvSharp.dll in
your Mono for Android application project, then add the required native
libraries (Build action: AndroidNativeLibrary) to the project and things will
(hopefully) Just Work.
- Jon
[0] $ monodis --assemblyref bin/Debug/OpenCvSharp.dll
AssemblyRef Table
1: Version=2.0.5.0
Name=mscorlib
Flags=0x00000000
Public Key:
0x00000000: 7C EC 85 D7 BE A7 79 8E
2: Version=2.0.5.0
Name=System
Flags=0x00000000
Public Key:
0x00000000: 7C EC 85 D7 BE A7 79 8E
3: Version=4.0.0.0
Name=System.Windows.Forms
Flags=0x00000000
Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89
4: Version=4.0.0.0
Name=System.Drawing
Flags=0x00000000
Public Key:
0x00000000: B0 3F 5F 7F 11 D5 0A 3A
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid