Browse Source

Fixed Emgu.CV.World.iOS compilation

pull/299/head
Canming Huang 6 years ago
parent
commit
4536ca3c6c
  1. 1
      .gitmodules
  2. 14
      Emgu.CV.Example/XamarinForms/iOS/Emgu.CV.XamarinForms.iOS.csproj
  3. 6
      Emgu.CV.NativeImage/CGImageExtension.cs
  4. 93
      Emgu.CV.NativeImage/UIImageExtension.cs
  5. 0
      Emgu.CV.World/iOS/ApiDefinition.cs
  6. 38
      Emgu.CV.World/iOS/Emgu.CV.World.IOS.csproj
  7. 16
      Emgu.CV.World/iOS/Properties/AssemblyInfo.cs
  8. 0
      Emgu.CV.World/iOS/libcvextern.linkwith.cs
  9. 4
      Emgu.CV/Core/Image.cs
  10. 4
      Emgu.CV/Core/Mat.cs
  11. 150
      Emgu.CV/Emgu.CV.projitems
  12. 109
      Emgu.CV/PInvoke/iOS/ImageiOS.cs
  13. 170
      Emgu.CV/PInvoke/iOS/MatiOS.cs
  14. 143
      Emgu.CV/PInvoke/iOS/UMatiOS.cs
  15. 2
      Solution/iOS/Emgu.CV.iOS.Example.sln

1
.gitmodules

@ -21,6 +21,7 @@
[submodule "Emgu.CV.Extern/tesseract/libtesseract/leptonica/leptonica.git"]
path = Emgu.CV.Extern/tesseract/libtesseract/leptonica/leptonica.git
url = https://github.com/emgucv/leptonica.git
ignore = dirty
[submodule "freetype2"]
path = freetype2
url = git://git.sv.nongnu.org/freetype/freetype2.git

14
Emgu.CV.Example/XamarinForms/iOS/Emgu.CV.XamarinForms.iOS.csproj

@ -126,12 +126,6 @@
<Reference Include="System.Xml.Serialization" />
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Emgu.CV.World\Emgu.CV.World.IOS.csproj">
<Project>{0EE2B36C-F7CD-49FA-A270-D7D988CFF6E5}</Project>
<Name>Emgu.CV.World.IOS</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="..\..\..\opencv\data\haarcascades\haarcascade_eye.xml">
<Link>haarcascade_eye.xml</Link>
@ -163,9 +157,15 @@
<Version>4.0.1.5</Version>
</PackageReference>
<PackageReference Include="Xamarin.Forms">
<Version>4.3.0.947036</Version>
<Version>4.3.0.991211</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Emgu.CV.World\iOS\Emgu.CV.World.IOS.csproj">
<Project>{0EE2B36C-F7CD-49FA-A270-D7D988CFF6E5}</Project>
<Name>Emgu.CV.World.IOS</Name>
</ProjectReference>
</ItemGroup>
<Import Project="..\Core\Emgu.CV.XamarinForms.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
</Project>

6
Emgu.CV.NativeImage/CGImageExtension.cs

@ -31,8 +31,8 @@ namespace Emgu.CV
/// <summary>
/// Copy the data from the CGImage to the current Image object
/// </summary>
private static void ImageFromCGImage<TColor, TDepth>(Image<TColor, TDepth> image, CGImage cgImage)
where TColor : struct, IColor
internal static void ImageFromCGImage<TColor, TDepth>(Image<TColor, TDepth> image, CGImage cgImage)
where TColor : struct, IColor
where TDepth : new()
{
//Don't do this, Xamarin.iOS won't be able to resolve: if (this is Image<Rgba, Byte>)
@ -89,7 +89,7 @@ namespace Emgu.CV
}
}
private static void ConvertCGImageToArray(CGImage cgImage, IOutputArray mat, ImreadModes modes = ImreadModes.AnyColor)
internal static void ConvertCGImageToArray(CGImage cgImage, IOutputArray mat, ImreadModes modes = ImreadModes.AnyColor)
{
Size sz = new Size((int)cgImage.Width, (int)cgImage.Height);
using (Mat m = new Mat(sz, DepthType.Cv8U, 4))

93
Emgu.CV.NativeImage/UIImageExtension.cs

@ -0,0 +1,93 @@
//----------------------------------------------------------------------------
// Copyright (C) 2004-2019 by EMGU Corporation. All rights reserved.
//----------------------------------------------------------------------------
#if __IOS__
using System;
using System.Drawing;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using CoreGraphics;
using UIKit;
namespace Emgu.CV
{
public static class UIImageExtension
{
/// <summary>
/// Creating an Image from the UIImage
/// </summary>
public static Image<TColor, TDepth> ToImage<TColor, TDepth> (this UIImage uiImage)
where TColor : struct, IColor
where TDepth : new()
//: this( (int) uiImage.Size.Width, (int) uiImage.Size.Height)
{
using (CGImage cgImage = uiImage.CGImage) {
return cgImage.ToImage<TColor, TDepth> ();
}
}
/// <summary>
/// Convert this Image object to UIImage
/// </summary>
public static UIImage ToUIImage<TColor, TDepth> (this Image<TColor, TDepth> image)
where TColor : struct, IColor
where TDepth : new()
{
using (CGImage cgImage = image.ToCGImage ()) {
return UIImage.FromImage (cgImage);
}
}
/// <summary>
/// Initializes a new instance of the <see cref="Emgu.CV.UMat"/> class from UIImage
/// </summary>
/// <param name="mode">The color conversion mode. By default, it convert the UIImage to BGRA color type to preserve all the image channels.</param>
/// <param name="uiImage">The UIImage.</param>
public static UMat ToUMat(this UIImage uiImage, ImreadModes mode = ImreadModes.AnyColor)
{
//UMat umat = new UMat ();
using (CGImage cgImage = uiImage.CGImage) {
//ConvertCGImageToArray (cgImage, this, mode);
return cgImage.ToUMat (mode);
}
}
/// <summary>
/// Converts to UIImage.
/// </summary>
/// <returns>The UIImage.</returns>
public static UIImage ToUIImage (this UMat umat)
{
using (CGImage tmp = umat.ToCGImage ()) {
return UIImage.FromImage (tmp);
}
}
/// <summary>
/// Initializes a new instance of the <see cref="Emgu.CV.Mat"/> class from UIImage
/// </summary>
/// <param name="mode">The color conversion mode. By default, it convert the UIImage to BGRA color type to preserve all the image channels.</param>
/// <param name="uiImage">The UIImage.</param>
public static Mat ToMat(this UIImage uiImage, ImreadModes mode = ImreadModes.AnyColor)
{
using (CGImage cgImage = uiImage.CGImage) {
return cgImage.ToMat (mode);
}
}
/// <summary>
/// Converts to UIImage.
/// </summary>
/// <returns>The UIImage.</returns>
public static UIImage ToUIImage (this Mat mat)
{
using (CGImage tmp = mat.ToCGImage ()) {
return UIImage.FromImage (tmp);
}
}
}
}
#endif

0
Emgu.CV.World/ApiDefinition.cs → Emgu.CV.World/iOS/ApiDefinition.cs

38
Emgu.CV.World/Emgu.CV.World.IOS.csproj → Emgu.CV.World/iOS/Emgu.CV.World.IOS.csproj

@ -6,10 +6,13 @@
<ProjectTypeGuids>{8FFB629D-F513-41CE-95D2-7ECE97B6EEEC};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<ProjectGuid>{0EE2B36C-F7CD-49FA-A270-D7D988CFF6E5}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Emgu.CV.World.IOS</RootNamespace>
<RootNamespace>Emgu.CV</RootNamespace>
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
<AssemblyName>Emgu.CV.World.IOS</AssemblyName>
</PropertyGroup>
<PropertyGroup>
<OpenCVBinaryDir>$(MSBuildThisFileDirectory)..\..\libs</OpenCVBinaryDir>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
@ -32,7 +35,6 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="OpenTK-1.0" />
<Reference Include="System" />
@ -48,19 +50,41 @@
<HintPath Condition="Exists('$(TargetFrameworkRootPath)\Xamarin.iOS\v1.0\Facades\System.Drawing.Common.dll')">$(TargetFrameworkRootPath)\Xamarin.iOS\v1.0\Facades\System.Drawing.Common.dll</HintPath>
</Reference>
</ItemGroup>
<PropertyGroup>
<EmguCVLinkTarget>Xamarin iOS Native Binding Library</EmguCVLinkTarget>
<EmguCVNativeFile>$(OpenCVBinaryDir)\iOS\libcvextern.a</EmguCVNativeFile>
<EmguCVErrorMessage Condition="!Exists('$(EmguCVNativeFile)')"> This package do not contain necessary binary for $(EmguCVLinkTarget). Emgu CV for iOS Commercial License is required. Missing $(EmguCVNativeFile) </EmguCVErrorMessage>
<EmguCVDeployMessage Condition="Exists('$(EmguCVNativeFile)')">$(EmguCVDeployMessage)ios </EmguCVDeployMessage>
<EmguCVLinkWithFile>$(MSBuildThisFileDirectory)\libcvextern.linkwith.cs</EmguCVLinkWithFile>
<EmguCVErrorMessage Condition="!Exists('$(EmguCVLinkWithFile)')"> This package do not contain necessary file for $(EmguCVLinkTarget). Emgu CV for iOS Commercial License is required. Missing $(EmguCVLinkWithFile) </EmguCVErrorMessage>
</PropertyGroup>
<ItemGroup>
<ObjcBindingNativeLibrary Include="$(EmguCVNativeFile)" Condition="Exists('$(EmguCVNativeFile)')" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(EmguCVLinkWithFile)" Condition="Exists('$(EmguCVLinkWithFile)')">
<DependentUpon>libcvextern.a</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\..\Emgu.CV.NativeImage\CGImageExtension.cs">
<Link>CGImageExtension.cs</Link>
</Compile>
<Compile Include="..\..\Emgu.CV.NativeImage\UIImageExtension.cs">
<Link>UIImageExtension.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<ObjcBindingApiDefinition Include="ApiDefinition.cs" />
</ItemGroup>
<Import Project="..\Emgu.CV\Emgu.CV.projitems" Label="Shared" />
<Import Project="..\Emgu.CV.Contrib\Emgu.CV.Contrib.projitems" Label="Shared" />
<Import Project="..\Emgu.CV.OCR\Emgu.CV.OCR.projitems" Label="Shared" />
<Import Project="..\Emgu.Util\Emgu.Util.projitems" Label="Shared" />
<Import Project="..\..\Emgu.CV\Emgu.CV.projitems" Label="Shared" />
<Import Project="..\..\Emgu.CV.Contrib\Emgu.CV.Contrib.projitems" Label="Shared" />
<Import Project="..\..\Emgu.CV.OCR\Emgu.CV.OCR.projitems" Label="Shared" />
<Import Project="..\..\Emgu.Util\Emgu.Util.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.ObjCBinding.CSharp.targets" />
<Target Name="BeforeBuild">
<Message Text="MSBuildExtensionsPath: $(MSBuildExtensionsPath)" Importance="high" />
@ -71,4 +95,4 @@
<Copy SourceFiles="$(OutputPath)$(AssemblyName).dll" DestinationFolder="..\libs" ContinueOnError="true" />
<Copy SourceFiles="$(OutputPath)$(AssemblyName).xml" DestinationFolder="..\libs" ContinueOnError="true" />
</Target>
</Project>
</Project>

16
Emgu.CV.World/iOS/Properties/AssemblyInfo.cs

@ -0,0 +1,16 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("Emgu.CV.World")]
[assembly: AssemblyDescription("")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

0
Emgu.CV/PInvoke/iOS/libcvextern.linkwith.cs → Emgu.CV.World/iOS/libcvextern.linkwith.cs

4
Emgu.CV/Core/Image.cs

@ -148,7 +148,7 @@ namespace Emgu.CV
using (CGImage tmp = CGImage.FromPNG(provider, null, false, CGColorRenderingIntent.Default))
{
AllocateData((int)tmp.Height, (int)tmp.Width, NumberOfChannels);
ConvertFromCGImage(tmp);
CGImageExtension.ImageFromCGImage<TColor, TDepth> (this, tmp);
}
return;
}
@ -219,7 +219,7 @@ namespace Emgu.CV
using (UIImage tmp = UIImage.FromFile(fileName))
{
AllocateData((int)tmp.Size.Height, (int)tmp.Size.Width, NumberOfChannels);
ConvertFromCGImage(tmp.CGImage);
CGImageExtension.ImageFromCGImage<TColor, TDepth>(this, tmp.CGImage);
}
#elif __UNIFIED__
#else

4
Emgu.CV/Core/Mat.cs

@ -250,7 +250,7 @@ namespace Emgu.CV
using (CGDataProvider provider = new CGDataProvider(fileName))
using (CGImage tmp = CGImage.FromPNG(provider, null, false, CGColorRenderingIntent.Default))
{
CvInvoke.ConvertCGImageToArray(tmp, this, loadType);
CGImageExtension.ConvertCGImageToArray(tmp, this, loadType);
}
return;
}
@ -276,7 +276,7 @@ namespace Emgu.CV
//try again to load with UIImage
using (UIImage tmp = UIImage.FromFile(fileName))
{
CvInvoke.ConvertCGImageToArray(tmp.CGImage, this);
CGImageExtension.ConvertCGImageToArray(tmp.CGImage, this);
}
#else
throw new ArgumentException(String.Format("Unable to decode file: {0}", fileName));

150
Emgu.CV/Emgu.CV.projitems

@ -40,155 +40,5 @@
<Compile Include="$(MSBuildThisFileDirectory)PInvoke\Windows.Store\*.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PInvoke\System.Drawing\*.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PInvoke\CvEnum\*.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PInvoke\iOS\ImageiOS.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PInvoke\iOS\MatiOS.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PInvoke\iOS\UMatiOS.cs" />
</ItemGroup>
<PropertyGroup>
<OpenCVBinaryDir>$(MSBuildThisFileDirectory)..\libs</OpenCVBinaryDir>
<EmguCVDir>$(MSBuildThisFileDirectory)</EmguCVDir>
</PropertyGroup>
<Choose>
<!-- IOS -->
<!-- IOS library project -->
<When Condition="(('$(TargetFrameworkIdentifier)'=='Xamarin.iOS' OR '$(ProjectTypeGuids)'=='{8FFB629D-F513-41CE-95D2-7ECE97B6EEEC};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}' OR '$(Platform)'=='iPhone' OR '$(Platform)'=='iPhoneSimulator') AND '$(OutputType)' != 'Exe')">
<PropertyGroup>
<EmguCVLinkTarget>Xamarin iOS Native Binding Library</EmguCVLinkTarget>
<EmguCVNativeFile>$(OpenCVBinaryDir)\iOS\libcvextern.a</EmguCVNativeFile>
<EmguCVErrorMessage Condition="!Exists('$(EmguCVNativeFile)')"> This package do not contain necessary binary for $(EmguCVLinkTarget). Emgu CV for iOS Commercial License is required. Missing $(EmguCVNativeFile) </EmguCVErrorMessage>
<EmguCVDeployMessage Condition="Exists('$(EmguCVNativeFile)')">$(EmguCVDeployMessage)ios </EmguCVDeployMessage>
<EmguCVLinkWithFile>$(EmguCVDir)PInvoke\iOS\libcvextern.linkwith.cs</EmguCVLinkWithFile>
<EmguCVErrorMessage Condition="!Exists('$(EmguCVLinkWithFile)')"> This package do not contain necessary file for $(EmguCVLinkTarget). Emgu CV for iOS Commercial License is required. Missing $(EmguCVLinkWithFile) </EmguCVErrorMessage>
</PropertyGroup>
<ItemGroup>
<ObjcBindingNativeLibrary Include="$(EmguCVNativeFile)" Condition="Exists('$(EmguCVNativeFile)')" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(EmguCVLinkWithFile)" Condition="Exists('$(EmguCVLinkWithFile)')">
<DependentUpon>libcvextern.a</DependentUpon>
</Compile>
</ItemGroup>
</When>
<!-- Xamarin.Mac application -->
<When Condition="'$(TargetFrameworkIdentifier)'=='Xamarin.Mac' OR '$(ProjectTypeGuids)'=='{810C163F-4746-4721-8B8E-88A3673A62EA};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}'">
<PropertyGroup>
<EmguCVLinkTarget>Xamarin.Mac</EmguCVLinkTarget>
<EmguCVNativeFile>$(OpenCVBinaryDir)\osx\libcvextern.dylib</EmguCVNativeFile>
<EmguCVErrorMessage Condition="!Exists('$(EmguCVNativeFile)')"> This package do not contain necessary binary for $(EmguCVLinkTarget). Emgu CV for Mac Commercial License is required. Missing $(EmguCVNativeFile) </EmguCVErrorMessage>
<EmguCVDeployMessage Condition="Exists('$(EmguCVNativeFile)')">$(EmguCVDeployMessage)mac </EmguCVDeployMessage>
</PropertyGroup>
<ItemGroup>
<NativeReference Include="$(EmguCVNativeFile)">
<Kind>Dynamic</Kind>
<SmartLink>False</SmartLink>
</NativeReference>
</ItemGroup>
</When>
<!-- IOS application (Note: do not work for Xamarin iOS for Visual Studio) -->
<When Condition="(('$(TargetFrameworkIdentifier)'=='Xamarin.iOS' OR '$(ProjectTypeGuids)'=='{8FFB629D-F513-41CE-95D2-7ECE97B6EEEC};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}' OR '$(ProjectTypeGuids)'=='{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}' OR '$(Platform)'=='iPhone' OR '$(Platform)'=='iPhoneSimulator') AND '$(OutputType)' == 'Exe')">
<PropertyGroup>
<EmguCVErrorMessage Condition="'$(OS)' == 'Windows_NT'"> Direct reference of Emgu CV for Xamarin iOS is only available with Xamarin Studio on Mac. When using Emgu CV in Visual Studio with Xamarin iOS plug in, please add the Emgu.CV.iOS.World reference instead.</EmguCVErrorMessage>
<EmguCVLinkTarget>Xamarin iOS App</EmguCVLinkTarget>
<EmguCVNativeFile>$(OpenCVBinaryDir)\iOS\libcvextern.a</EmguCVNativeFile>
<EmguCVErrorMessage Condition="!Exists('$(EmguCVNativeFile)')"> This package do not contain necessary binary for $(EmguCVLinkTarget). Emgu CV for iOS Commercial License is required. Missing $(EmguCVNativeFile) </EmguCVErrorMessage>
<MtouchExtraArgs>$(MtouchExtraArgs) -cxx -gcc_flags "-L$(OpenCVBinaryDir)\iOS\ -lcvextern -force_load $(OpenCVBinaryDir)\iOS\libcvextern.a -framework Foundation -framework Accelerate -framework CoreFoundation -framework CoreGraphics -framework AssetsLibrary -framework AVFoundation -framework CoreImage -framework CoreMedia -framework CoreVideo -framework QuartzCore -framework ImageIO -framework UIKit"</MtouchExtraArgs>
<EmguCVDeployMessage Condition="Exists('$(EmguCVNativeFile)')">$(EmguCVDeployMessage)ios </EmguCVDeployMessage>
</PropertyGroup>
</When>
<!-- Android -->
<When Condition="('$(AndroidSupportedAbis)'!='') OR '$(ProjectTypeGuids)'=='{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}'">
<PropertyGroup>
<EmguCVLinkTarget Condition="('$(AndroidApplication)'=='True' OR '$(AndroidApplication)'=='true')">Xamarin Android App</EmguCVLinkTarget>
<EmguCVLinkTarget Condition="!('$(AndroidApplication)'=='True' OR '$(AndroidApplication)'=='true')">Xamarin Android Library</EmguCVLinkTarget>
<!--
<EmguCVNativeArmeabi>$(OpenCVBinaryDir)\android\armeabi\libcvextern.so</EmguCVNativeArmeabi>
<EmguCVBuildAndroidArmeabi Condition="$(AndroidSupportedAbis.Contains('armeabi%3')) OR $(AndroidSupportedAbis.Contains('armeabi,')) OR $(AndroidSupportedAbis.Contains('armeabi;')) OR $(AndroidSupportedAbis.EndsWith('armeabi')) OR ('$(AndroidSupportedAbis)'=='' AND '$(Platform)'=='AnyCPU') OR ('$(Platform)'=='armeabi')">True</EmguCVBuildAndroidArmeabi>
<EmguCVErrorMessage Condition="'$(EmguCVBuildAndroidArmeabi)'=='True' AND !Exists('$(EmguCVNativeArmeabi)')">This package do not contain necessary binary for $(EmguCVLinkTarget). Emgu CV for Android Commercial License is required. Armeabi is targeted, but file $(EmguCVNativeArmeabi) is missing.</EmguCVErrorMessage>
<EmguCVDeployMessage Condition="'$(EmguCVBuildAndroidArmeabi)'=='True' AND Exists('$(EmguCVNativeArmeabi)')">$(EmguCVDeployMessage)armeabi </EmguCVDeployMessage>
-->
<EmguCVNativeArmeabiv7a>$(OpenCVBinaryDir)\android\armeabi-v7a\libcvextern.so</EmguCVNativeArmeabiv7a>
<EmguCVBuildAndroidArmeabiv7a Condition="$(AndroidSupportedAbis.Contains('armeabi-v7a%3')) OR $(AndroidSupportedAbis.Contains('armeabi-v7a,')) OR $(AndroidSupportedAbis.Contains('armeabi-v7a;')) OR $(AndroidSupportedAbis.EndsWith('armeabi-v7a')) OR ('$(AndroidSupportedAbis)'=='' AND '$(Platform)'=='AnyCPU') OR ('$(Platform)'=='armeabi-v7a')">True</EmguCVBuildAndroidArmeabiv7a>
<EmguCVErrorMessage Condition="'$(EmguCVBuildAndroidArmeabiv7a)'=='True' AND !Exists('$(EmguCVNativeArmeabiv7a)')">This package do not contain necessary binary for $(EmguCVLinkTarget). Emgu CV for Android Commercial License is required. Armeabi-v7a is targeted, but file $(EmguCVNativeArmeabiv7a) is missing.</EmguCVErrorMessage>
<EmguCVDeployMessage Condition="'$(EmguCVBuildAndroidArmeabiv7a)'=='True' AND Exists('$(EmguCVNativeArmeabiv7a)')">$(EmguCVDeployMessage)armeabi-v7a </EmguCVDeployMessage>
<EmguCVNativeArm64v8a>$(OpenCVBinaryDir)\android\arm64-v8a\libcvextern.so</EmguCVNativeArm64v8a>
<EmguCVBuildAndroidArm64v8a Condition="$(AndroidSupportedAbis.Contains('arm64-v8a%3')) OR $(AndroidSupportedAbis.Contains('arm64-v8a,')) OR $(AndroidSupportedAbis.EndsWith('arm64-v8a;')) OR $(AndroidSupportedAbis.EndsWith('arm64-v8a')) OR ('$(AndroidSupportedAbis)'=='' AND '$(Platform)'=='AnyCPU') OR ('$(Platform)'=='arm64-v8a')">True</EmguCVBuildAndroidArm64v8a>
<EmguCVErrorMessage Condition="'$(EmguCVBuildAndroidArm64v8a)'=='True' AND !Exists('$(EmguCVNativeArm64v8a)')">This package do not contain necessary binary for $(EmguCVLinkTarget). Emgu CV for Android Commercial License is required. Arm64-v8a is targeted, but file $(EmguCVNativeArm64v8a) is missing.</EmguCVErrorMessage>
<EmguCVDeployMessage Condition="'$(EmguCVBuildAndroidArm64v8a)'=='True' AND Exists('$(EmguCVNativeArm64v8a)')">$(EmguCVDeployMessage)arm64-v8a </EmguCVDeployMessage>
<EmguCVNativex86>$(OpenCVBinaryDir)\android\x86\libcvextern.so</EmguCVNativex86>
<EmguCVBuildAndroidx86 Condition="$(AndroidSupportedAbis.Contains('x86%3')) OR $(AndroidSupportedAbis.Contains('x86,')) OR $(AndroidSupportedAbis.Contains('x86;')) OR $(AndroidSupportedAbis.EndsWith('x86')) OR ('$(AndroidSupportedAbis)'=='' AND '$(Platform)'=='AnyCPU') OR ('$(Platform)'=='x86')">True</EmguCVBuildAndroidx86>
<EmguCVErrorMessage Condition="'$(EmguCVBuildAndroidx86)'=='True' AND !Exists('$(EmguCVNativex86)')">This package do not contain necessary binary for $(EmguCVLinkTarget). Emgu CV for Android Commercial License is required. x86 is targeted, but file $(EmguCVNativex86) is missing.</EmguCVErrorMessage>
<EmguCVDeployMessage Condition="'$(EmguCVBuildAndroidx86)'=='True' AND Exists('$(EmguCVNativex86)')">$(EmguCVDeployMessage)x86 </EmguCVDeployMessage>
<EmguCVNativex8664>$(OpenCVBinaryDir)\android\x86_64\libcvextern.so</EmguCVNativex8664>
<EmguCVBuildAndroidx8664 Condition="$(AndroidSupportedAbis.Contains('x86_64%3')) OR $(AndroidSupportedAbis.Contains('x86_64,')) OR $(AndroidSupportedAbis.Contains('x86_64;')) OR $(AndroidSupportedAbis.EndsWith('x86_64')) OR ('$(AndroidSupportedAbis)'=='' AND '$(Platform)'=='AnyCPU') OR ('$(Platform)'=='x86_64')">True</EmguCVBuildAndroidx8664>
<EmguCVErrorMessage Condition="'$(EmguCVBuildAndroidx8664)'=='True' AND !Exists('$(EmguCVNativex8664)')">This package do not contain necessary binary for $(EmguCVLinkTarget). Emgu CV for Android Commercial License is required. x86_64 is targeted, but file $(EmguCVNativex8664) is missing.</EmguCVErrorMessage>
<EmguCVDeployMessage Condition="'$(EmguCVBuildAndroidx8664)'=='True' AND Exists('$(EmguCVNativex8664)')">$(EmguCVDeployMessage)x86_64 </EmguCVDeployMessage>
</PropertyGroup>
<!-- armeabi -->
<!--
<ItemGroup Condition="'$(EmguCVBuildAndroidArmeabi)'=='True' AND Exists('$(EmguCVNativeArmeabi)')">
<EmbeddedNativeLibrary Condition="'$(EmguCVLinkTarget)'=='Xamarin Android Library'" Include="$(EmguCVNativeArmeabi)">
<Link>lib\armeabi\libcvextern.so</Link>
</EmbeddedNativeLibrary>
<AndroidNativeLibrary Condition="'$(EmguCVLinkTarget)'=='Xamarin Android App'" Include="$(EmguCVNativeArmeabi)">
<Link>lib\armeabi\libcvextern.so</Link>
</AndroidNativeLibrary>
</ItemGroup>
-->
<!-- armeabi-v7a -->
<ItemGroup Condition="'$(EmguCVBuildAndroidArmeabiv7a)'=='True' AND Exists('$(EmguCVNativeArmeabiv7a)')">
<EmbeddedNativeLibrary Condition="'$(EmguCVLinkTarget)'=='Xamarin Android Library'" Include="$(EmguCVNativeArmeabiv7a)">
<Link>lib\armeabi-v7a\libcvextern.so</Link>
</EmbeddedNativeLibrary>
<AndroidNativeLibrary Condition="'$(EmguCVLinkTarget)'=='Xamarin Android App'" Include="$(EmguCVNativeArmeabiv7a)">
<Link>lib\armeabi-v7a\libcvextern.so</Link>
</AndroidNativeLibrary>
</ItemGroup>
<!-- arm64-v8a -->
<ItemGroup Condition="'$(EmguCVBuildAndroidArm64v8a)'=='True' AND Exists('$(EmguCVNativeArm64v8a)')">
<EmbeddedNativeLibrary Condition="'$(EmguCVLinkTarget)'=='Xamarin Android Library'" Include="$(EmguCVNativeArm64v8a)">
<Link>lib\arm64-v8a\libcvextern.so</Link>
</EmbeddedNativeLibrary>
<AndroidNativeLibrary Condition="'$(EmguCVLinkTarget)'=='Xamarin Android App'" Include="$(EmguCVNativeArm64v8a)">
<Link>lib\arm64-v8a\libcvextern.so</Link>
</AndroidNativeLibrary>
</ItemGroup>
<!-- x86 -->
<ItemGroup Condition="'$(EmguCVBuildAndroidx86)'=='True' AND Exists('$(EmguCVNativex86)')">
<EmbeddedNativeLibrary Condition="'$(EmguCVLinkTarget)'=='Xamarin Android Library'" Include="$(EmguCVNativex86)">
<Link>lib\x86\libcvextern.so</Link>
</EmbeddedNativeLibrary>
<AndroidNativeLibrary Condition="'$(EmguCVLinkTarget)'=='Xamarin Android App'" Include="$(EmguCVNativex86)">
<Link>lib\x86\libcvextern.so</Link>
</AndroidNativeLibrary>
</ItemGroup>
<!-- x86_64 -->
<ItemGroup Condition="'$(EmguCVBuildAndroidx8664)'=='True' AND Exists('$(EmguCVNativex8664)')">
<EmbeddedNativeLibrary Condition="'$(EmguCVLinkTarget)'=='Xamarin Android Library'" Include="$(EmguCVNativex8664)">
<Link>lib\x86_64\libcvextern.so</Link>
</EmbeddedNativeLibrary>
<AndroidNativeLibrary Condition="'$(EmguCVLinkTarget)'=='Xamarin Android App'" Include="$(EmguCVNativex8664)">
<Link>lib\x86_64\libcvextern.so</Link>
</AndroidNativeLibrary>
</ItemGroup>
</When>
<!-- DotNetCore Application -->
<When Condition="'$(EmguCVLinkTarget)'=='' AND ('$(TargetFramework)'=='netcoreapp1.1')">
<PropertyGroup>
<EmguCVLinkTarget>DotNetCore</EmguCVLinkTarget>
</PropertyGroup>
</When>
<!-- NetStandard -->
<When Condition="'$(EmguCVLinkTarget)'=='' AND ('$(TargetFramework)'=='netstandard1.4')">
<PropertyGroup>
<EmguCVLinkTarget>NetStandard</EmguCVLinkTarget>
</PropertyGroup>
</When>
</Choose>
<Target Name="EmguCVPackageBuildImports" BeforeTargets="PrepareForBuild">
<Message Condition="'$(EmguCVLinkTarget)'!=''" Text="Emgu CV shared project compiling against $(EmguCVLinkTarget)" Importance="High" />
<Error Text="'$(EmguCVErrorMessage)'" Condition="'$(EmguCVErrorMessage)'!=''" />
<Warning Text="'$(EmguCVWarningMessage)'" Condition="'$(EmguCVWarningMessage)'!=''" />
<Message Text="Compiling with $(EmguCVDeployMessage)binary" Condition="'$(EmguCVDeployMessage)'!=''" Importance="High" />
<Message Text="WARNING: No native binary is being deployed by the Emgu.CV shared project. Please remember to copy the native binary to the folder of your final executable, or there will be a PInvoke runtime exception during application execution." Condition="'$(EmguCVDeployMessage)'==''" Importance="High" />
</Target>
</Project>

109
Emgu.CV/PInvoke/iOS/ImageiOS.cs

@ -1,109 +0,0 @@
//----------------------------------------------------------------------------
// Copyright (C) 2004-2019 by EMGU Corporation. All rights reserved.
//----------------------------------------------------------------------------
#if __IOS__
using System;
using System.Drawing;
using Emgu.CV;
using Emgu.CV.Structure;
using CoreGraphics;
using UIKit;
namespace Emgu.CV
{
public partial class Image<TColor, TDepth>
: CvArray<TDepth>, IEquatable<Image<TColor, TDepth>>
where TColor : struct, IColor
where TDepth : new()
{
/// <summary>
/// Creating an Image from the CGImage
/// </summary>
public Image(CGImage cgImage)
: this( (int) cgImage.Width, (int) cgImage.Height)
{
ConvertFromCGImage(cgImage);
}
/// <summary>
/// Copy the data from the CGImage to the current Image object
/// </summary>
private void ConvertFromCGImage(CGImage cgImage)
{
//Don't do this, Xamarin.iOS won't be able to resolve: if (this is Image<Rgba, Byte>)
if (typeof(TColor) == typeof(Rgba) && typeof(TDepth) == typeof(byte))
{
RectangleF rect = new RectangleF(PointF.Empty, new SizeF(cgImage.Width, cgImage.Height));
using (CGColorSpace cspace = CGColorSpace.CreateDeviceRGB())
using (CGBitmapContext context = new CGBitmapContext(
MIplImage.ImageData,
Width, Height,
8,
Width * 4,
cspace,
CGImageAlphaInfo.PremultipliedLast))
context.DrawImage(rect, cgImage);
} else
{
using (Image<Rgba, Byte> tmp = new Image<Rgba, Byte>(cgImage))
ConvertFrom(tmp);
}
}
/// <summary>
/// Convert this Image object to CGImage
/// </summary>
public CGImage ToCGImage()
{
//Don't do this, Xamarin.iOS won't be able to resolve: if (this is Image<Rgba, Byte>)
if (typeof(TColor) == typeof(Rgba) && typeof(TDepth) == typeof(Byte))
{
using (CGColorSpace cspace = CGColorSpace.CreateDeviceRGB())
using (CGBitmapContext context = new CGBitmapContext(
MIplImage.ImageData,
Width, Height,
8,
Width * 4,
cspace,
CGImageAlphaInfo.PremultipliedLast))
{
CGImage cgImage = context.ToImage();
return cgImage;
}
} else
{
using (Image<Rgba, Byte> tmp = Convert<Rgba, Byte>())
{
return tmp.ToCGImage();
}
}
}
/// <summary>
/// Creating an Image from the UIImage
/// </summary>
public Image(UIImage uiImage)
: this( (int) uiImage.Size.Width, (int) uiImage.Size.Height)
{
using (CGImage cgImage = uiImage.CGImage)
{
ConvertFromCGImage(cgImage);
}
}
/// <summary>
/// Convert this Image object to UIImage
/// </summary>
public UIImage ToUIImage()
{
using (CGImage cgImage = ToCGImage())
{
return UIImage.FromImage(cgImage);
}
}
}
}
#endif

170
Emgu.CV/PInvoke/iOS/MatiOS.cs

@ -1,170 +0,0 @@
//----------------------------------------------------------------------------
// Copyright (C) 2004-2019 by EMGU Corporation. All rights reserved.
//----------------------------------------------------------------------------
#if __IOS__
using System;
using System.Drawing;
using Emgu.CV;
using Emgu.CV.Structure;
using CoreGraphics;
using Emgu.CV.CvEnum;
using UIKit;
namespace Emgu.CV
{
public static partial class CvInvoke
{
internal static void ConvertCGImageToArray(CGImage cgImage, IOutputArray mat, ImreadModes modes = ImreadModes.AnyColor)
{
Size sz = new Size((int)cgImage.Width, (int)cgImage.Height);
using (Mat m = new Mat(sz, DepthType.Cv8U, 4))
{
RectangleF rect = new RectangleF(PointF.Empty, new SizeF(cgImage.Width, cgImage.Height));
using (CGColorSpace cspace = CGColorSpace.CreateDeviceRGB())
using (CGBitmapContext context = new CGBitmapContext(
m.DataPointer,
sz.Width, sz.Height,
8,
sz.Width * 4,
cspace,
CGImageAlphaInfo.PremultipliedLast))
context.DrawImage(rect, cgImage);
if (modes == ImreadModes.Grayscale)
{
CvInvoke.CvtColor(m, mat, ColorConversion.Rgba2Gray);
}
else if (modes == ImreadModes.AnyColor)
{
CvInvoke.CvtColor(m, mat, ColorConversion.Rgba2Bgra);
}
else if (modes == ImreadModes.ReducedColor2)
{
using (Mat tmp = new Mat())
{
CvInvoke.PyrDown(m, tmp);
CvInvoke.CvtColor(tmp, mat, ColorConversion.Rgba2Bgr);
}
}
else if (modes == ImreadModes.ReducedGrayscale2)
{
using (Mat tmp = new Mat())
{
CvInvoke.PyrDown(m, tmp);
CvInvoke.CvtColor(tmp, mat, ColorConversion.Rgba2Gray);
}
}
else if (modes == ImreadModes.ReducedColor4 || modes == ImreadModes.ReducedColor8 || modes == ImreadModes.ReducedGrayscale4 || modes == ImreadModes.ReducedGrayscale8 || modes == ImreadModes.LoadGdal)
{
throw new NotImplementedException(String.Format("Conversion from PNG using mode {0} is not supported", modes));
}
else
{
CvInvoke.CvtColor(m, mat, ColorConversion.Rgba2Bgr);
}
}
}
}
public partial class Mat
{
/// <summary>
/// Initializes a new instance of the <see cref="Emgu.CV.Mat"/> class from CGImage
/// </summary>
/// <param name="mode">The color conversion mode. By default, it convert the UIImage to BGRA color type to preserve all the image channels.</param>
/// <param name="cgImage">The CGImage.</param>
public Mat(CGImage cgImage, ImreadModes mode = ImreadModes.AnyColor)
: this()
{
CvInvoke.ConvertCGImageToArray(cgImage, this, mode);
}
private static CGImage RgbaByteMatToCGImage(Mat bgraByte)
{
using (CGColorSpace cspace = CGColorSpace.CreateDeviceRGB())
using (CGBitmapContext context = new CGBitmapContext(
bgraByte.DataPointer,
bgraByte.Width, bgraByte.Height,
8,
bgraByte.Width * 4,
cspace,
CGImageAlphaInfo.PremultipliedLast))
return context.ToImage();
}
/// <summary>
/// Converts to CGImage
/// </summary>
/// <returns>The CGImage.</returns>
public CGImage ToCGImage()
{
int nchannels = NumberOfChannels;
DepthType d = Depth;
if (nchannels == 4 && d == DepthType.Cv8U)
{
//bgra
using (Mat tmp = new Mat())
{
CvInvoke.CvtColor(this, tmp, ColorConversion.Bgra2Rgba);
return RgbaByteMatToCGImage(tmp);
}
}
else if (nchannels == 3 && d == DepthType.Cv8U)
{
//bgr
using (Mat tmp = new Mat())
{
CvInvoke.CvtColor(this, tmp, ColorConversion.Bgr2Rgba);
return RgbaByteMatToCGImage(tmp);
}
}
else if (nchannels == 1 && d == DepthType.Cv8U)
{
using (Mat tmp = new Mat())
{
CvInvoke.CvtColor(this, tmp, ColorConversion.Gray2Rgba);
return RgbaByteMatToCGImage(tmp);
}
}
else
{
throw new Exception(String.Format("Converting from Mat of {0} channels {1} to CGImage is not supported. Please convert Mat to 3 channel Bgr image of Byte before calling this function.", nchannels, d));
}
}
#if __IOS__
/// <summary>
/// Initializes a new instance of the <see cref="Emgu.CV.Mat"/> class from UIImage
/// </summary>
/// <param name="mode">The color conversion mode. By default, it convert the UIImage to BGRA color type to preserve all the image channels.</param>
/// <param name="uiImage">The UIImage.</param>
public Mat(UIImage uiImage, ImreadModes mode = ImreadModes.AnyColor)
: this ()
{
using(CGImage cgImage = uiImage.CGImage)
{
CvInvoke.ConvertCGImageToArray(cgImage, this, mode);
}
}
/// <summary>
/// Converts to UIImage.
/// </summary>
/// <returns>The UIImage.</returns>
public UIImage ToUIImage()
{
using (CGImage tmp = ToCGImage())
{
return UIImage.FromImage(tmp);
}
}
#else
#endif
}
}
#endif

143
Emgu.CV/PInvoke/iOS/UMatiOS.cs

@ -1,143 +0,0 @@
//----------------------------------------------------------------------------
// Copyright (C) 2004-2019 by EMGU Corporation. All rights reserved.
//----------------------------------------------------------------------------
#if __UNIFIED__
using System;
using System.Drawing;
using Emgu.CV;
using Emgu.CV.Structure;
using CoreGraphics;
using Emgu.CV.CvEnum;
#if __IOS__
using UIKit;
#else
using AppKit;
#endif
namespace Emgu.CV
{
public partial class UMat
{
/// <summary>
/// Initializes a new instance of the <see cref="Emgu.CV.Mat"/> class from CGImage
/// </summary>
/// <param name="mode">The color conversion mode. By default, it convert the UIImage to BGRA color type to preserve all the image channels.</param>
/// <param name="cgImage">The CGImage.</param>
public UMat(CGImage cgImage, ImreadModes mode = ImreadModes.AnyColor)
: this()
{
CvInvoke.ConvertCGImageToArray(cgImage, this, mode);
}
private static CGImage RgbaByteMatToCGImage(Mat bgraByte)
{
using (CGColorSpace cspace = CGColorSpace.CreateDeviceRGB())
using (CGBitmapContext context = new CGBitmapContext(
bgraByte.DataPointer,
bgraByte.Width, bgraByte.Height,
8,
bgraByte.Width * 4,
cspace,
CGImageAlphaInfo.PremultipliedLast))
return context.ToImage();
}
/// <summary>
/// Converts to CGImage
/// </summary>
/// <returns>The CGImage.</returns>
public CGImage ToCGImage()
{
int nchannels = NumberOfChannels;
DepthType d = Depth;
if (nchannels == 4 && d == DepthType.Cv8U)
{
//bgra
using (Mat tmp = new Mat())
{
CvInvoke.CvtColor(this, tmp, ColorConversion.Bgra2Rgba);
return RgbaByteMatToCGImage(tmp);
}
}
else if (nchannels == 3 && d == DepthType.Cv8U)
{
//bgr
using (Mat tmp = new Mat())
{
CvInvoke.CvtColor(this, tmp, ColorConversion.Bgr2Rgba);
return RgbaByteMatToCGImage(tmp);
}
}
else if (nchannels == 1 && d == DepthType.Cv8U)
{
using (Mat tmp = new Mat())
{
CvInvoke.CvtColor(this, tmp, ColorConversion.Gray2Rgba);
return RgbaByteMatToCGImage(tmp);
}
}
else
{
throw new Exception(String.Format("Converting from Mat of {0} channels {1} to CGImage is not supported. Please convert Mat to 3 channel Bgr image of Byte before calling this function.", nchannels, d));
}
}
#if __IOS__
/// <summary>
/// Initializes a new instance of the <see cref="Emgu.CV.UMat"/> class from UIImage
/// </summary>
/// <param name="mode">The color conversion mode. By default, it convert the UIImage to BGRA color type to preserve all the image channels.</param>
/// <param name="uiImage">The UIImage.</param>
public UMat(UIImage uiImage, ImreadModes mode = ImreadModes.AnyColor)
: this ()
{
using(CGImage cgImage = uiImage.CGImage)
{
CvInvoke.ConvertCGImageToArray(cgImage, this, mode);
}
}
/// <summary>
/// Converts to UIImage.
/// </summary>
/// <returns>The UIImage.</returns>
public UIImage ToUIImage()
{
using (CGImage tmp = ToCGImage())
{
return UIImage.FromImage(tmp);
}
}
#else
/// <summary>
/// Initializes a new instance of the <see cref="Emgu.CV.Mat"/> class from NSImage
/// </summary>
/// <param name="mode">The color conversion mode. By default, it convert the UIImage to BGRA color type to preserve all the image channels.</param>
/// <param name="nsImage">The NSImage.</param>
public UMat(NSImage nsImage, ImreadModes mode = ImreadModes.AnyColor)
: this()
{
using (CGImage cgImage = nsImage.CGImage)
{
CvInvoke.ConvertCGImageToArray(cgImage, this, mode);
}
}
/// <summary>
/// Converts to NSImage.
/// </summary>
/// <returns>The NSImage.</returns>
public NSImage ToNSImage()
{
using (CGImage tmp = ToCGImage())
{
return new NSImage(tmp, new CGSize(tmp.Width, tmp.Height));
}
}
#endif
}
}
#endif

2
Solution/iOS/Emgu.CV.iOS.Example.sln

@ -13,7 +13,7 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Emgu.CV.OCR", "..\..\Emgu.C
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Emgu.CV.Contrib", "..\..\Emgu.CV.Contrib\Emgu.CV.Contrib.shproj", "{11E54A7E-778D-466C-A176-71E150976AC1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Emgu.CV.World.IOS", "..\..\Emgu.CV.World\Emgu.CV.World.IOS.csproj", "{0EE2B36C-F7CD-49FA-A270-D7D988CFF6E5}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Emgu.CV.World.IOS", "..\..\Emgu.CV.World\iOS\Emgu.CV.World.IOS.csproj", "{0EE2B36C-F7CD-49FA-A270-D7D988CFF6E5}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Emgu.CV.XamarinForms", "..\..\Emgu.CV.Example\XamarinForms\Core\Emgu.CV.XamarinForms.shproj", "{F2A5CE86-0B21-40D2-AD3F-BB2D1D716CFE}"
EndProject

Loading…
Cancel
Save