UE4配置opencv插件4.24版本
环境:Windows10+UE4.24.2+opencv3.4.9+vs2019网上的教程版本比较旧,试了一遍,编译报错。
步骤1:创建OpenCV新插件。
打开UE->编辑->插件->新插件,选择第三方库,插件名称OpenCV,点击创建插件,会在项目的目录下创建一个Plugins/OpenCV文件。OpenCV目录下的文件如下图所示。
步骤2:文件拷贝。
在官网下载opencv并解压。
将opencv_world349.lib、opencv_world340d.lib、opencv_ffmpeg349_64.dll、opencv_world349.dll拷贝至.\Plugins\OpenCV\Binaries\ThirdParty\OpenCVLibrary\Win64\目录下。
将opencv_world349.lib、opencv_world340d.lib、opencv_ffmpeg349_64.dll、opencv_world349.dll、opencv_world349.pdb、opencv_world349d.pdb拷贝至.\Plugins\OpenCV\Binaries\Win64目录下。
将解压后的include文件夹拷贝至.\Plugins\OpenCV\Binaries\ThirdParty目录下和.\Plugins\OpenCV\Source\ThirdParty\OpenCV目录下。
将解压后.\opencv\build\x64\vc15\lib和.\opencv\build\x64\vc15\bin里的文件(根据自己使用的cv14还是cv15找对应目录)拷到.\Plugins\OpenCV\Source\ThirdParty\OpenCV\OpenCVLibrary\x64\Release。
步骤3:更改OpenCV.Build.cs文件。
该文件位于.\Plugins\OpenCV\Source\OpenCV下。更改后如下:
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool;
using System.IO;
public class OpenCV : ModuleRules
{
private string ThirdPartyPath
{
get
{
return Path.GetFullPath(Path.Combine(ModuleDirectory, "../ThirdParty"));
}
}
public OpenCV(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
PublicIncludePaths.AddRange(
new string[] {
// ... add public include paths required here ...
}
);
PrivateIncludePaths.AddRange(
new string[] {
// ... add other private include paths required here ...
}
);
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"OpenCVLibrary",
"Projects",
"CoreUObject",
"Engine",
"InputCore",
"OpenCV"
// ... add other public dependencies that you statically link with here ...
}
);
PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine",
"Slate",
"SlateCore"
// ... add private dependencies that you statically link with here ...
}
);
DynamicallyLoadedModuleNames.AddRange(
new string[]
{
// ... add any modules that your module loads dynamically here ...
}
);
string OpenCVPath = Path.Combine(ThirdPartyPath, "OpenCV");
if (Target.Platform == UnrealTargetPlatform.Win64)//64位平台
{
string OpenCVIncludePath = Path.Combine(OpenCVPath, "Include");
string OpenCVLibPath = Path.Combine(OpenCVPath, "OpenCVLibrary", "x64", "Release");
PublicIncludePaths.Add(OpenCVIncludePath);
PublicLibraryPaths.Add(OpenCVLibPath);
//Add Static Libraries
PublicAdditionalLibraries.Add("opencv_world349.lib");
PublicAdditionalLibraries.Add("opencv_world349d.lib");
//Add Dynamic Libraries
PublicDelayLoadDLLs.Add("opencv_world349.dll");
PublicDelayLoadDLLs.Add("opencv_ffmpeg349_64.dll");
}
else if (Target.Platform == UnrealTargetPlatform.Win32)//32位平台
{
//32位的OpenCV库,仿照上面Win64的自己填写
}
else if (Target.Platform == UnrealTargetPlatform.Mac)
{
//Mac
}
}
}步骤4:更改包含目录。
选择项目->属性->C++目录->包含目录,添加include目录。
步骤5:编译。
在UE里编译看是否会报错。编译的时间可能会比较长,耐心等待。
以上就是配置全过程。下一篇将介绍如何在UE中基于C++调用opencv库,实现图像视频的处理。
问题:
fatal error LNK1181: 无法打开输入文件“opencv_world349.lib”
在本地项目文件当中找到项目的路径例如:E:\\TestOpenCV1\Plugins\OpenCV\Source\ThirdParty\OpenCVLibrary\x64\Release\lib
复制路径,然后指定库文件路径,打开vs右键项目属性,选择VC++目录,库文件,把路径复制上去。编译,就不会报错了
参考:
资源:
只包含opencv的build文件,不包含source,请谨慎下载。(如资源不能下载,请联系我,将更新链接)也可到官网自行下载。
版权声明:本文为CSDN博主「MOLWH」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:
页:
[1]