예제 #1
0
        /// <summary>
        /// Static Constructor to setup opencv environment
        /// </summary>
        static CvInvoke()
        {
            List <String> modules = CvInvoke.OpenCVModuleList;

            modules.RemoveAll(String.IsNullOrEmpty);

            _libraryLoaded = true;
#if ANDROID || (UNITY_ANDROID && !UNITY_EDITOR)
            System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
            FileInfo      file             = new FileInfo(asm.Location);
            DirectoryInfo directory        = file.Directory;

#if (UNITY_ANDROID && !UNITY_EDITOR)
            UnityEngine.AndroidJavaObject jo = new UnityEngine.AndroidJavaObject("java.lang.System");
#endif
            foreach (String module in modules)
            {
                //IntPtr handle = Emgu.Util.Toolbox.LoadLibrary(module);
                //Debug.WriteLine(string.Format(handle == IntPtr.Zero ? "Failed to load {0}." : "Loaded {0}.", module));
                try
                {
                    Console.WriteLine(string.Format("Trying to load {0}.", module));
#if ANDROID
                    Java.Lang.JavaSystem.LoadLibrary(module);
#else //(UNITY_ANDROID && !UNITY_EDITOR)
                    jo.CallStatic("loadLibrary", module);
#endif
                    Console.WriteLine(string.Format("Loaded {0}.", module));
                }
                catch (Exception e)
                {
                    _libraryLoaded = false;
                    Console.WriteLine(String.Format("Failed to load {0}: {1}", module, e.Message));
                }
            }
#elif IOS || UNITY_IPHONE || NETFX_CORE
#else
            if (Emgu.Util.Platform.OperationSystem != Emgu.Util.TypeEnum.OS.MacOSX)
            {
                String formatString = GetModuleFormatString();
                for (int i = 0; i < modules.Count; ++i)
                {
                    modules[i] = String.Format(formatString, modules[i]);
                }

                _libraryLoaded &= LoadUnmanagedModules(null, modules.ToArray());
            }
#endif

#if !UNITY_IPHONE
            //Use the custom error handler
            RedirectError(CvErrorHandlerThrowException, IntPtr.Zero, IntPtr.Zero);
#endif
        }
예제 #2
0
        /// <summary>
        /// Attempts to load tensorflow modules from the specific location
        /// </summary>
        /// <param name="modules">The names of tensorflow modules.</param>
        /// <returns>True if all the modules has been loaded successfully</returns>
        public static bool DefaultLoadUnmanagedModules(String[] modules)
        {
            bool libraryLoaded = true;

#if __ANDROID__
            foreach (String module in modules)
            {
                try
                {
                    Console.WriteLine(string.Format("Trying to load {0} ({1} bit).", module, Marshal.SizeOf <IntPtr>() * 8));
                    Java.Lang.JavaSystem.LoadLibrary(module);
                    Console.WriteLine(string.Format("Loaded {0}.", module));
                }
                catch (Exception e)
                {
                    libraryLoaded = false;
                    Console.WriteLine(String.Format("Failed to load {0}: {1}", module, e.Message));
                }
            }
#elif (UNITY_ANDROID && !UNITY_EDITOR)
            UnityEngine.AndroidJavaObject jo = new UnityEngine.AndroidJavaObject("java.lang.System");

            foreach (String module in modules)
            {
                try
                {
                    Console.WriteLine(string.Format("Trying to load {0} ({1} bit).", module, Marshal.SizeOf <IntPtr>() * 8));
                    jo.CallStatic("loadLibrary", module);
                    Console.WriteLine(string.Format("Loaded {0}.", module));
                }
                catch (Exception e)
                {
                    libraryLoaded = false;
                    Console.WriteLine(String.Format("Failed to load {0}: {1}", module, e.Message));
                }
            }
#elif __IOS__ || UNITY_IOS || NETFX_CORE
#else
#if !(UNITY_EDITOR || UNITY_STANDALONE || UNITY_ANDROID)
            if (!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX))
#endif
            {
                String formatString = GetModuleFormatString();
                for (int i = 0; i < modules.Length; ++i)
                {
                    modules[i] = String.Format(formatString, modules[i]);
                }

                libraryLoaded &= LoadUnmanagedModules(null, modules);
            }
#endif
            return(libraryLoaded);
        }
예제 #3
0
파일: CvInvoke.cs 프로젝트: virzak/emgucv
        /// <summary>
        /// Attempts to load opencv modules from the specific location
        /// </summary>
        /// <param name="modules">The names of opencv modules. e.g. "opencv_cxcore.dll" on windows.</param>
        /// <returns>True if all the modules has been loaded successfully</returns>
        public static bool DefaultLoadUnmanagedModules(String[] modules)
        {
            bool libraryLoaded = true;

#if __ANDROID__
            foreach (String module in modules)
            {
                try
                {
                    Console.WriteLine(string.Format("Trying to load {0}.", module));
                    Java.Lang.JavaSystem.LoadLibrary(module);
                    Console.WriteLine(string.Format("Loaded {0}.", module));
                }
                catch (Exception e)
                {
                    libraryLoaded = false;
                    Console.WriteLine(String.Format("Failed to load {0}: {1}", module, e.Message));
                }
            }
#elif (UNITY_ANDROID && !UNITY_EDITOR)
            UnityEngine.AndroidJavaObject jo = new UnityEngine.AndroidJavaObject("java.lang.System");
            foreach (String module in modules)
            {
                try
                {
                    Console.WriteLine(string.Format("Trying to load {0}.", module));
                    jo.CallStatic("loadLibrary", module);
                    Console.WriteLine(string.Format("Loaded {0}.", module));
                }
                catch (Exception e)
                {
                    libraryLoaded = false;
                    Console.WriteLine(String.Format("Failed to load {0}: {1}", module, e.Message));
                }
            }
#elif __IOS__ || UNITY_IOS || NETFX_CORE
#else
            if (Emgu.Util.Platform.OperationSystem != Emgu.Util.TypeEnum.OS.MacOS)
            {
                String formatString = GetModuleFormatString();
                for (int i = 0; i < modules.Length; ++i)
                {
                    modules[i] = String.Format(formatString, modules[i]);
                }

                libraryLoaded &= LoadUnmanagedModules(null, modules);
            }
#endif
            return(libraryLoaded);
        }
예제 #4
0
파일: CvInvoke.cs 프로젝트: rgladkyi/emgucv
        /// <summary>
        /// Attempts to load opencv modules from the specific location
        /// </summary>
        /// <param name="modules">The names of opencv modules. e.g. "opencv_cxcore.dll" on windows.</param>
        /// <returns>True if all the modules has been loaded successfully</returns>
        public static bool DefaultLoadUnmanagedModules(String[] modules)
        {
            bool libraryLoaded = true;

#if __ANDROID__ || (UNITY_ANDROID && !UNITY_EDITOR)
            System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
            FileInfo      file             = new FileInfo(asm.Location);
            DirectoryInfo directory        = file.Directory;


#if (UNITY_ANDROID && !UNITY_EDITOR)
            UnityEngine.AndroidJavaObject jo = new UnityEngine.AndroidJavaObject("java.lang.System");
#endif
            foreach (String module in modules)
            {
                //IntPtr handle = Emgu.Util.Toolbox.LoadLibrary(module);
                //Debug.WriteLine(string.Format(handle == IntPtr.Zero ? "Failed to load {0}." : "Loaded {0}.", module));
                try
                {
                    Console.WriteLine(string.Format("Trying to load {0}.", module));
#if __ANDROID__
                    Java.Lang.JavaSystem.LoadLibrary(module);
#else //(UNITY_ANDROID && !UNITY_EDITOR)
                    jo.CallStatic("loadLibrary", module);
#endif
                    Console.WriteLine(string.Format("Loaded {0}.", module));
                }
                catch (Exception e)
                {
                    libraryLoaded = false;
                    Console.WriteLine(String.Format("Failed to load {0}: {1}", module, e.Message));
                }
            }
#elif __IOS__ || UNITY_IOS || NETFX_CORE
#else
            if (Emgu.Util.Platform.OperationSystem != Emgu.Util.TypeEnum.OS.MacOSX)
            {
                String formatString = GetModuleFormatString();
                for (int i = 0; i < modules.Length; ++i)
                {
                    modules[i] = String.Format(formatString, modules[i]);
                }

                libraryLoaded &= LoadUnmanagedModules(null, modules);
            }
#endif
            return(libraryLoaded);
        }
예제 #5
0
        static StackObject *CallStatic_1(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 3);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Object[] @args = (System.Object[]) typeof(System.Object[]).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.String @methodName = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            UnityEngine.AndroidJavaObject instance_of_this_method = (UnityEngine.AndroidJavaObject) typeof(UnityEngine.AndroidJavaObject).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.CallStatic(@methodName, @args);

            return(__ret);
        }
예제 #6
0
      /// <summary>
      /// Attempts to load opencv modules from the specific location
      /// </summary>
      /// <param name="modules">The names of opencv modules. e.g. "opencv_cxcore.dll" on windows.</param>
      /// <returns>True if all the modules has been loaded successfully</returns>
      public static bool DefaultLoadUnmanagedModules(String[] modules)
      {
         bool libraryLoaded = true;
#if __ANDROID__ || (UNITY_ANDROID && !UNITY_EDITOR)

         System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
         FileInfo file = new FileInfo(asm.Location);
         DirectoryInfo directory = file.Directory;

#if (UNITY_ANDROID && !UNITY_EDITOR)
         UnityEngine.AndroidJavaObject jo = new UnityEngine.AndroidJavaObject("java.lang.System");
#endif
         foreach (String module in modules)
         {
            //IntPtr handle = Emgu.Util.Toolbox.LoadLibrary(module);
            //Debug.WriteLine(string.Format(handle == IntPtr.Zero ? "Failed to load {0}." : "Loaded {0}.", module));
            try
            {

               Console.WriteLine(string.Format("Trying to load {0}.", module));
#if __ANDROID__
               Java.Lang.JavaSystem.LoadLibrary(module);
#else //(UNITY_ANDROID && !UNITY_EDITOR)

               jo.CallStatic("loadLibrary", module); 
#endif
               Console.WriteLine(string.Format("Loaded {0}.", module));
            }
            catch (Exception e)
            {
               libraryLoaded = false;
               Console.WriteLine(String.Format("Failed to load {0}: {1}", module, e.Message));
            }
         }
#elif IOS || UNITY_IPHONE || NETFX_CORE
#else
         if (Emgu.Util.Platform.OperationSystem != Emgu.Util.TypeEnum.OS.MacOSX)
         {
            String formatString = GetModuleFormatString();
            for (int i = 0; i < modules.Length; ++i)
               modules[i] = String.Format(formatString, modules[i]);

            libraryLoaded &= LoadUnmanagedModules(null, modules);
         }
#endif
         return libraryLoaded;
      }
예제 #7
0
        /// <summary>
        /// Attempts to load tensorflow modules from the specific location
        /// </summary>
        /// <param name="modules">The names of tensorflow modules.</param>
        /// <returns>True if all the modules has been loaded successfully</returns>
        public static bool DefaultLoadUnmanagedModules(String[] modules)
        {
            bool libraryLoaded = true;

            System.Reflection.Assembly monoAndroidAssembly = Emgu.TF.Util.Toolbox.FindAssembly("Mono.Android.dll");
            if (monoAndroidAssembly != null)
            {
                //Running on Android
                Type javaSystemType = monoAndroidAssembly.GetType("Java.Lang.JavaSystem");
                if (javaSystemType != null)
                {
                    System.Reflection.MethodInfo loadLibraryMethodInfo = javaSystemType.GetMethod("LoadLibrary");
                    if (loadLibraryMethodInfo != null)
                    {
                        foreach (String module in modules)
                        {
                            try
                            {
                                Trace.WriteLine(string.Format("Trying to load {0} ({1} bit).", module,
                                                              IntPtr.Size * 8));
                                loadLibraryMethodInfo.Invoke(null, new object[] { module });
                                //Java.Lang.JavaSystem.LoadLibrary(module);
                                Trace.WriteLine(string.Format("Loaded {0}.", module));
                            }
                            catch (Exception e)
                            {
                                libraryLoaded = false;
                                Trace.WriteLine(String.Format("Failed to load {0}: {1}", module, e.Message));
                            }
                        }
                        return(libraryLoaded);
                    }
                }
            }

#if (UNITY_ANDROID && !UNITY_EDITOR)
            UnityEngine.AndroidJavaObject jo = new UnityEngine.AndroidJavaObject("java.lang.System");

            foreach (String module in modules)
            {
                try
                {
                    Trace.WriteLine(string.Format("Trying to load {0} ({1} bit).", module, Marshal.SizeOf <IntPtr>() * 8));
                    jo.CallStatic("loadLibrary", module);
                    Trace.WriteLine(string.Format("Loaded {0}.", module));
                }
                catch (Exception e)
                {
                    libraryLoaded = false;
                    Trace.WriteLine(String.Format("Failed to load {0}: {1}", module, e.Message));
                }
            }
#elif __IOS__ || UNITY_IOS || NETFX_CORE
#else
#if !(UNITY_EDITOR || UNITY_STANDALONE || UNITY_ANDROID)
            if (!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices
                                                                                .OSPlatform.OSX))
#endif
            {
                String formatString = GetModuleFormatString();
                for (int i = 0; i < modules.Length; ++i)
                {
                    modules[i] = String.Format(formatString, modules[i]);
                }

                libraryLoaded &= LoadUnmanagedModules(null, modules);
            }
#endif
            return(libraryLoaded);
        }
예제 #8
0
      /// <summary>
      /// Static Constructor to setup opencv environment
      /// </summary>
      static CvInvoke()
      {
         List<String> modules = CvInvoke.OpenCVModuleList;
         modules.RemoveAll(String.IsNullOrEmpty);

         _libraryLoaded = true;
#if ANDROID || (UNITY_ANDROID && !UNITY_EDITOR)
		 
         System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
         FileInfo file = new FileInfo(asm.Location);
         DirectoryInfo directory = file.Directory;

#if (UNITY_ANDROID && !UNITY_EDITOR)
         UnityEngine.AndroidJavaObject jo = new UnityEngine.AndroidJavaObject("java.lang.System");
#endif
         foreach (String module in modules)
         {
            //IntPtr handle = Emgu.Util.Toolbox.LoadLibrary(module);
            //Debug.WriteLine(string.Format(handle == IntPtr.Zero ? "Failed to load {0}." : "Loaded {0}.", module));
            try
            {
			
               Console.WriteLine(string.Format("Trying to load {0}.", module));
#if ANDROID
               Java.Lang.JavaSystem.LoadLibrary(module);
#else //(UNITY_ANDROID && !UNITY_EDITOR)

               jo.CallStatic("loadLibrary", module); 
#endif
               Console.WriteLine(string.Format("Loaded {0}.", module));
            }
            catch (Exception e)
            {
               _libraryLoaded = false; 
               Console.WriteLine(String.Format("Failed to load {0}: {1}", module, e.Message));
            }
         }
#elif IOS || UNITY_IPHONE || NETFX_CORE
#else
         if (Emgu.Util.Platform.OperationSystem != Emgu.Util.TypeEnum.OS.MacOSX)
         {
            String formatString = GetModuleFormatString();
            for (int i = 0; i < modules.Count; ++i)
               modules[i] = String.Format(formatString, modules[i]);

            _libraryLoaded &= LoadUnmanagedModules(null, modules.ToArray());
         }
#endif

#if !UNITY_IPHONE
         //Use the custom error handler
         RedirectError(CvErrorHandlerThrowException, IntPtr.Zero, IntPtr.Zero);
#endif
      }
예제 #9
0
        /// <summary>
        /// Attempts to load opencv modules from the specific location
        /// </summary>
        /// <param name="modules">The names of opencv modules. e.g. "opencv_core.dll" on windows.</param>
        /// <returns>True if all the modules has been loaded successfully</returns>
        public static bool DefaultLoadUnmanagedModules(String[] modules)
        {
            bool libraryLoaded = true;

#if (UNITY_ANDROID && !UNITY_EDITOR)
            UnityEngine.AndroidJavaObject jo = new UnityEngine.AndroidJavaObject("java.lang.System");
            foreach (String module in modules)
            {
                try
                {
                    Console.WriteLine(string.Format("Trying to load {0}.", module));
                    jo.CallStatic("loadLibrary", module);
                    Console.WriteLine(string.Format("Loaded {0}.", module));
                }
                catch (Exception e)
                {
                    libraryLoaded = false;
                    Console.WriteLine(String.Format("Failed to load {0}: {1}", module, e.Message));
                }
            }
#elif UNITY_IOS
#else
            if (Emgu.Util.Platform.OperationSystem == Platform.OS.IOS)
            {
                return(libraryLoaded);
            }
            else if (Emgu.Util.Platform.OperationSystem == Platform.OS.Android)
            {
                System.Reflection.Assembly monoAndroidAssembly = Emgu.Util.Toolbox.FindAssembly("Mono.Android.dll");

                //Running on Xamarin Android
                Type javaSystemType = monoAndroidAssembly.GetType("Java.Lang.JavaSystem");
                if (javaSystemType != null)
                {
                    System.Reflection.MethodInfo loadLibraryMethodInfo = javaSystemType.GetMethod("LoadLibrary");
                    if (loadLibraryMethodInfo != null)
                    {
                        foreach (String module in modules)
                        {
                            if (module.StartsWith("opencv_videoio_ffmpeg"))
                            {
                                continue; //skip the ffmpeg modules.
                            }
                            try
                            {
                                System.Diagnostics.Trace.WriteLine(string.Format("Trying to load {0} ({1} bit).", module,
                                                                                 IntPtr.Size * 8));
                                loadLibraryMethodInfo.Invoke(null, new object[] { module });
                                //Java.Lang.JavaSystem.LoadLibrary(module);
                                System.Diagnostics.Trace.WriteLine(string.Format("Loaded {0}.", module));
                            }
                            catch (Exception e)
                            {
                                libraryLoaded = false;
                                System.Diagnostics.Trace.WriteLine(String.Format("Failed to load {0}: {1}", module, e.Message));
                            }
                        }
                        return(libraryLoaded);
                    }
                }
            }
            else if (Emgu.Util.Platform.OperationSystem != Emgu.Util.Platform.OS.MacOS)
            {
                String formatString = GetModuleFormatString();
                for (int i = 0; i < modules.Length; ++i)
                {
                    modules[i] = String.Format(formatString, modules[i]);
                }

                libraryLoaded &= LoadUnmanagedModules(null, modules);
            }
#endif
            return(libraryLoaded);
        }