Ara you OK?
我看你是思想出现了偏差
哇!你认出了错别单词!恭喜你获得一次向我支付宝充值助我重返欧洲的机会!
这个页面管关不掉了,你自己看着办吧

UE4笔记-15版本 Plugins引用OpenCV

记录个旧版本的Build.cs备查 

Note:在4.20版本中已经有个官方的Plugins集成了OpenCV :OpenCVLensDistortion 需要用的话自己引用就可以(记得是3.X的版本,想用最新的4.X自己撸个第三方插件吧)

现在的版本(4.20)Build.cs已经变化很多了。

因为已经存在官方的demo(Editor添加插件的时候,有第三方插件选项),就不贴新的build.cs了

整体来说就是多了个插件的module,第三方DLL或.SO/.a必须放在Module里,挺奇葩的,

 

4.15的引用第三方OpenCV的plugin 的build.cs:

/*

*/

using System;
using System.IO;
using System.Collections.Generic;
using UnrealBuildTool;

public class LQCVPlug: ModuleRules
{

    protected string PluginRootDirectory
    {
        get { return Path.GetFullPath(Path.Combine(ModuleDirectory, "../../")); }
    }

    protected string ThirdPartyPath
    {
        get { return Path.Combine(PluginRootDirectory, "ThirdParty/"); }
    }

    protected string BinariesDir
    {
        get { return Path.Combine(PluginRootDirectory, "Binaries"); }
    }

    protected List<string> OpenCVModules = new List<string>()
    {
        "opencv_core",
        "opencv_calib3d",    // camera calibration
        "opencv_features2d", // cv::SimpleBlobDetector for calibration
        "opencv_videoio",    // VideoCapture
        "opencv_aruco",        // Aruco markers
        "opencv_imgproc",   // Aruco needs this
        "opencv_flann",     // Aruco needs this
        "opencv_imgcodecs",    // imwrite
        "opencv_video"        // Kalman filter, suprisingly it is in modules/video/...
    };

    protected string OpenCVVersion = "310";

    protected string PlatformString(TargetInfo Target)
    {
        if (Target.Platform == UnrealTargetPlatform.Win64) { return "Win64"; }
        if (Target.Platform == UnrealTargetPlatform.Win32) { return "Win32"; }
        if (Target.Platform == UnrealTargetPlatform.Linux) { return "Linux"; }
        if (Target.Platform == UnrealTargetPlatform.Android) { return "Android"; }
        return "Unknown";
    }

    protected string BinariesDirForTarget(TargetInfo Target)
    {
        return Path.Combine(BinariesDir, PlatformString(Target));
    }

    public bool IsDebug(TargetInfo Target)
    {
        return Target.Configuration == UnrealTargetConfiguration.Debug && BuildConfiguration.bDebugBuildsActuallyUseDebugCRT;
    }

    public void LoadOpenCV(TargetInfo Target)
    {
        string opencv_dir = Path.Combine(ThirdPartyPath, "opencv");

        PublicIncludePaths.Add(Path.Combine(opencv_dir, "include"));

        if (Target.Platform == UnrealTargetPlatform.Win64)
        {
            Console.WriteLine("AUR: OpenCV for Win64");

            var suffix = OpenCVVersion;

            if (IsDebug(Target))
            {
                Console.WriteLine("AUR: Debug");
                suffix += "d";
            }
            else
            {
                Console.WriteLine("AUR: Not debug");
            }

            var lib_dir = Path.Combine(opencv_dir, "lib", "Win64");

            PublicAdditionalLibraries.AddRange
            (
                OpenCVModules.ConvertAll(m => Path.Combine(lib_dir, m + suffix + ".lib"))
            );

            PublicDelayLoadDLLs.AddRange
            (
                OpenCVModules.ConvertAll(m => Path.Combine(BinariesDirForTarget(Target), m + suffix + ".dll"))
            );
        }
        else if (Target.Platform == UnrealTargetPlatform.Linux)
        {
            Console.WriteLine("AUR: OpenCV for Linux");

            var opencv_libs = OpenCVModules.ConvertAll(m => Path.Combine(BinariesDirForTarget(Target), "lib" + m + ".so"));

            PublicAdditionalLibraries.AddRange(opencv_libs);
            PublicDelayLoadDLLs.AddRange(opencv_libs);
        }
        else if (Target.Platform == UnrealTargetPlatform.Android)
        {
            Console.WriteLine("AUR: OpenCV for Android");
            Console.WriteLine("AUR: OpenCV for Android with arch = ", Target.Architecture);

            var arch = "armeabi-v7a"; //Target.Architecture

            var src_dir = Path.Combine(opencv_dir, "install", "Android", "sdk", "native");
            var modules_lib_dir = Path.Combine(src_dir, "libs", arch);

            var opencv_libs = OpenCVModules.ConvertAll
            (
                m => Path.Combine(modules_lib_dir, "lib" + m + ".a")
            );

            PublicLibraryPaths.Add(modules_lib_dir);
            PublicAdditionalLibraries.AddRange(opencv_libs);
            /*
            var thirdparty_lib_dir = Path.Combine(src_dir, "3rdparty", "libs", arch);
            var thirdparty_libs = new List<string>(Directory.GetFiles(thirdparty_lib_dir)).ConvertAll
            (
                fn => Path.Combine(thirdparty_lib_dir, fn)
            );
            PublicLibraryPaths.Add(thirdparty_lib_dir);
            PublicAdditionalLibraries.AddRange(thirdparty_libs);
            */
        }
        else
        {
            Console.WriteLine("AUR: No prebuilt binaries for OpenCV on platform " + Target.Platform);
        }

        // Force execption handling across all modules.
        UEBuildConfiguration.bForceEnableExceptions = true;
    }

    public LQCVPlug(TargetInfo Target)
    {
        
        PublicIncludePaths.AddRange(
            new string[] {
                "LQCVPlug/Public"
                
                // ... add public include paths required here ...
            }
            );
                
        
        PrivateIncludePaths.AddRange(
            new string[] {
                "LQCVPlug/Private",
                
                // ... add other private include paths required here ...
            }
            );

        PublicDependencyModuleNames.AddRange(
            new string[]
            {
                "Core",
                "CoreUObject",
                "Engine",
                "Slate",
                "SlateCore",
                "Networking",
                "Sockets",
                "RenderCore",
                "RHI",
                "ImageWrapper",
                "FreeType2"
                // ... add private dependencies that you statically link with here ...    
            }
            );

        DynamicallyLoadedModuleNames.AddRange(
            new string[]
            {
                // ... add any modules that your module loads dynamically here ...
            }
            );

        LoadOpenCV(Target);
        //LoadFreeType2(Target);


        Console.WriteLine("Include headers from directories:");
        PublicIncludePaths.ForEach(m => Console.WriteLine("    " + m));

        Console.WriteLine("Libraries - static:");
        PublicAdditionalLibraries.ForEach(m => Console.WriteLine("    " + m));

        Console.WriteLine("Libraries - dynamic:");
        PublicDelayLoadDLLs.ForEach(m => Console.WriteLine("    " + m));
        
    }
}

 

posted @ 2018-10-22 16:24  林清  阅读(2627)  评论(0编辑  收藏  举报