• UE5_OpenCV库的加载方式


    UE5使用opencv库要在系统中添加opencv的环境变量

    在项目文件夹下新建ThirdParty,拷贝bin,新建OpenCV文件夹,拷贝include、lib

     

     

     

     

    打开项目,找到source目录下的build.cs文件

    修改build.cs内容,添加头文件路径,dll路径,lib路径

    1. // Copyright Epic Games, Inc. All Rights Reserved.
    2. using UnrealBuildTool;
    3. using System.IO;
    4. public class newopencv : ModuleRules
    5. {
    6. private string ModulePath
    7. {
    8. get
    9. {
    10. return ModuleDirectory;
    11. }
    12. }
    13. private string ThirPartyPath
    14. {
    15. get
    16. {
    17. return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/"));
    18. }
    19. }
    20. public bool loadopencv(ReadOnlyTargetRules Target)
    21. {
    22. string OpenCVPath = Path.Combine(ThirPartyPath, "OpenCV");
    23. string libpath = "";
    24. if (Target.Platform == UnrealTargetPlatform.Win64)
    25. {
    26. PublicIncludePaths.AddRange(new string[]{Path.Combine(OpenCVPath,"include")});
    27. libpath = Path.Combine(OpenCVPath, "lib");
    28. PublicSystemLibraryPaths.Add(libpath);
    29. PublicAdditionalLibraries.Add("opencv_world480.lib");
    30. RuntimeDependencies.Add(Path.Combine("$(BinaryOutputDir)","opencv_world320.dll"),Path.Combine(libpath,"opencv_videoio_ffmpeg480_64.dll"));
    31. RuntimeDependencies.Add(Path.Combine("$(BinaryOutputDir)","opencv_ffmpeg320_64.dll"),Path.Combine(libpath,"opencv_world480.dll"));
    32. return true;
    33. }
    34. return false;
    35. }
    36. public newopencv(ReadOnlyTargetRules Target) : base(Target)
    37. {
    38. PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
    39. PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore","RenderCore","RHI" });
    40. //PrivateDependencyModuleNames.AddRange(new string[] { "OpenVDB" });
    41. //PublicDependencyModuleNames.Add("UMG");
    42. loadopencv(Target);
    43. // Uncomment if you are using Slate UI
    44. PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
    45. // Uncomment if you are using online features
    46. // PrivateDependencyModuleNames.Add("OnlineSubsystem");
    47. // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
    48. }
    49. }

    OpenCV库加载完成,以下是opencv读取外部png设置给ui的方法

    1. // Fill out your copyright notice in the Description page of Project Settings.
    2. #include "userwidgetClass.h"
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include "Windows/WindowsTextInputMethodSystem.h"
    8. void UuserwidgetClass::NativeConstruct()
    9. {
    10. Super::NativeConstruct();
    11. openCV_RW_png();
    12. }
    13. void UuserwidgetClass::openCV_RW_png()
    14. {
    15. cv::Mat img;
    16. img = cv::imread("E:\\mlao.PNG");
    17. // 确保图像是BGR格式
    18. if (img.channels() == 3)
    19. {
    20. cv::cvtColor(img, img, cv::COLOR_BGR2RGBA);
    21. }
    22. // 确保图像是8位无符号整数类型
    23. if (img.depth() != CV_8U)
    24. {
    25. img.convertTo(img, CV_8U);
    26. }
    27. UTexture2D* texture = UTexture2D::CreateTransient(img.cols,img.rows,PF_R8G8B8A8);
    28. void* texturedata = texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
    29. FMemory::Memcpy(texturedata,img.data,img.total()*img.elemSize());
    30. texture->PlatformData->Mips[0].BulkData.Unlock();
    31. texture->UpdateResource();
    32. FSlateBrush Brush;
    33. Brush.SetResourceObject(texture);
    34. Image_abc->SetBrush(Brush);
    35. }

  • 相关阅读:
    Centos7如何扩容未做lvm的GPT硬盘
    plumelog介绍与应用-一个简单易用的java分布式日志系统
    微信支付申请
    系列文章之一文纵览【机器学习】(5) 常见评估方法:混淆矩阵、正确率、精确率、召回率、F值、预测概率、ROC曲线和AUC | 均方误差、决定系数、SVR | 超参数的设置 | 模型的过拟合与防止
    春秋云境CVE-2018-20604
    Vue Router 路由动态缓存组件
    全向移动机器人运动参数校准
    redux最佳实战(一)
    QGIS下载各种DEM的插件(SRTM 90m/30m -ALOS 30m -Cop 30m/90m-NASADEM Global DEM)
    TSINGSEE青犀AI智能分析+视频监控工业园区周界安全防范方案
  • 原文地址:https://blog.csdn.net/weixin_42318094/article/details/132946767