UE4使用OpenCV插件调用电脑摄像头
UE4使用OpenCV插件調(diào)用電腦攝像頭
使用的是UE4.27,參考兩位大佬博客
https://blog.csdn.net/d137578736/article/details/79037849?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-1-79037849-blog-126785890.pc_relevant_vip_default&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-1-79037849-blog-126785890.pc_relevant_vip_default&utm_relevant_index=2
https://blog.csdn.net/Accepted_10086/article/details/126785890
講的很詳細(xì),但是遇到了一些問題。
1 創(chuàng)建UE4.27工程
選擇創(chuàng)建C++類。
2 下載OpenCV插件。
插件參考第二個大佬博客。
將下載的三個文件復(fù)制到工程文件夾下。
關(guān)閉打開的UE項(xiàng)目和VS,右鍵uproject文件。選擇第三個,生成VS項(xiàng)目文件。
3 修改OpenCV代碼
雙擊.sln文件,打開項(xiàng)目,在Source->項(xiàng)目名下,找到項(xiàng)目名.build.cs文件。
在文件開頭加
using System.IO;在類中public前面加
private string ThirdPartyPath {get{return Path.GetFullPath(Path.Combine(ModuleDirectory, "../../ThirdParty"));} }在注釋后面加
string OpenCVPath = Path.Combine(ThirdPartyPath, "OpenCV/");PublicIncludePaths.AddRange(new string[]{Path.Combine(OpenCVPath,"Includes")});PublicLibraryPaths.Add(Path.Combine(OpenCVPath, "Libraries/Win64"));整體代碼如下:
// Copyright Epic Games, Inc. All Rights Reserved.using UnrealBuildTool; using System.IO;public class test_opencv : ModuleRules {private string ThirdPartyPath{get{return Path.GetFullPath(Path.Combine(ModuleDirectory, "../../ThirdParty"));}}public test_opencv(ReadOnlyTargetRules Target) : base(Target){PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });PrivateDependencyModuleNames.AddRange(new string[] { });// Uncomment if you are using Slate UI// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });// Uncomment if you are using online features// PrivateDependencyModuleNames.Add("OnlineSubsystem");// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to truestring OpenCVPath = Path.Combine(ThirdPartyPath, "OpenCV/");PublicIncludePaths.AddRange(new string[]{Path.Combine(OpenCVPath,"Includes")});PublicLibraryPaths.Add(Path.Combine(OpenCVPath, "Libraries/Win64"));} }然后右鍵項(xiàng)目,生成。編譯成功。
然后調(diào)試
打開UE4,在編輯-插件中可以搜索OpenCV可以看到插件添加成功!(沒有啟用記得啟用!)
4 創(chuàng)建材質(zhì)及藍(lán)圖
新手包如下
打開Texture搜索T_Ceramic_Tile_M,找到后右鍵創(chuàng)建材質(zhì),命名為M_WebCam雙擊打開。
斷開所有連線,然后連接到自發(fā)光顏色,然后右鍵材質(zhì)選擇第三個,修改名字為Video Texture。再選中右邊的材質(zhì)設(shè)置為
保存退出后,進(jìn)入藍(lán)圖文件夾,添加一個藍(lán)圖類,選擇webcamReader。
雙擊打開藍(lán)圖后,添加組件,選擇平臺,會生成一個Plane組件
右鍵 組件,選擇變量,添加
變量設(shè)置為
然后右鍵添加事件和實(shí)例,設(shè)置等,完成后如下圖。
因?yàn)槲沂荱E小白,添加這些都是自己根據(jù)博客琢磨。右鍵點(diǎn)擊然后搜索,慢慢來。例如創(chuàng)建動態(tài)材質(zhì)實(shí)例,在添加Plane組件后,右鍵搜索,然后添加就好。
最后將藍(lán)圖保存,拖到場景中運(yùn)行就能看到效果。
總結(jié)
以上是生活随笔為你收集整理的UE4使用OpenCV插件调用电脑摄像头的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Vue实现动态路由导航
- 下一篇: mac c语言 新手,第1次买Mac必看