UE开发笔记_1

本文介绍了如何在UnrealEngine(UE)中使用OpenCV库,包括如何添加依赖、结构体和函数的定义,以及VisualStudio2022的开发快捷键。还涉及了生成随机数、UTF-8编码设置和将OpenCVMat转换为纹理的过程,以及使用Qt实现的定时任务。
摘要由CSDN通过智能技术生成

1.编写打包后才需要执行的代码

#if WITH_EDITORONLY_DATA

#else
//编写打包后才需要执行的代码
#endif

2.在UE中使用opencv

PublicDependencyModuleNames.AddRange(
	new string[]
	{
		"Core",
		"OpenCV",
		"OpenCVHelper"
		// ... add other public dependencies that you statically link with here ...
	}
);
"Plugins": [
	{
		"Name": "OpenCVLensDistortion",
		"Enabled": true
	}
]

3.UE中定义结构体

USTRUCT(BlueprintType)
struct FPointCloudArgument
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = FPointCloudArgument)
	UTexture2D* refPTex1 = nullptr;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = FPointCloudArgument)
	UTexture2D* refPTex2 = nullptr;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = FPointCloudArgument)
	UTexture2D* refPTex3 = nullptr;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = FPointCloudArgument)
	FVector  position;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = FPointCloudArgument)
	FVector size;
};

4.UE中定义函数

UFUNCTION(BlueprintCallable)
static FPointCloudArgument CreateTextureXByPointCloud(const TMap<FVector,float>& maps);

5.VS2022快捷键

Ctrl+K+D格式化代码
Ctrl+K+O头文件源文件切换
Ctrl+Shift+F全局搜索
Ctrl+F本文件内容搜索
Ctrl+D粘贴光标所在行代码

6.启动命令行

D:\LMJ\app\WindowsNoEditor\stream.exe -AudioMixer -PixelStreamingIP=152.136.123.42 -PixelStreamingPort=8888 -NvEncFrameRateNum=30 -NvEncH264ConfigLevel=5.1

7.在0到100之间生成随机数

#include <iostream>
#include <random>

int main() {
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> distrib(0, 100);
    int random_number = distrib(gen);
    system("pause");
    return 0;
}

8.配置UTF-8编码

#pragma execution_character_set("utf-8")  

9.将mat格式转纹理

// 将mat格式转纹理
UTexture2D* ConvertMatToTexture(const cv::Mat& OpenCVImage)
{
	// 获取图像数据的宽度和高度
	int32 Width = OpenCVImage.cols;
	int32 Height = OpenCVImage.rows;
	// 创建 UTexture2D 对象
	UTexture2D* Texture = UTexture2D::CreateTransient(Width, Height, PF_B8G8R8A8);
	if (!Texture->IsValidLowLevel())
	{
		return nullptr;
	}
	Texture->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
	Texture->PowerOfTwoMode	= ETexturePowerOfTwoSetting::None;
	//创建纹理
#if WITH_EDITORONLY_DATA
	Texture->MipGenSettings = TextureMipGenSettings::TMGS_NoMipmaps;
#endif		
	Texture->SRGB = false;

	Texture->UpdateResource();
	// 锁定纹理以进行写入操作
	uint8* TextureData = static_cast<uint8*>(Texture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE));
	// 将 OpenCV 图像数据复制到纹理数据中
	FMemory::Memcpy(TextureData, OpenCVImage.data, Width * Height * 4);
	// 解锁纹理
	Texture->PlatformData->Mips[0].BulkData.Unlock();
	// 更新纹理设置
	Texture->UpdateResource();
	return Texture;
}

9.QT定时任务

#pragma once
#pragma execution_character_set("utf-8")

#include <QtWidgets/QWidget>
#include "ui_ZNController.h"
#include <QMessageBox>
#include <QTime>
#include <QFileInfo>
#include <QProcess>
#include <QDir>

class ZNController : public QWidget
{
    Q_OBJECT

public:
    ZNController(QWidget* parent = nullptr);
    ~ZNController();
    void init();//初始化函数

private:
    Ui::ZNControllerClass ui;
    QTime chargingTimer;
    void timerEvent(QTimerEvent* event);
};


#include "ZNController.h"

ZNController::ZNController(QWidget* parent)
    : QWidget(parent)
{
    ui.setupUi(this);
    init();
}

ZNController::~ZNController()
{}

void ZNController::init()
{
    chargingTimer.start();
    startTimer(20000);//定时任务,每隔5秒执行一次

}

void ZNController::timerEvent(QTimerEvent* event)
{
    //QString exeFilePath = QCoreApplication::applicationFilePath(); //获取exe的完全路径
    //QString exeFilePath = "D:/LMJ/app/WindowsNoEditor/stream.exe";
    //QString exeFileName = QFileInfo(exeFilePath).fileName(); //获取exe的名称
    QString exeFileName = "ZNBase-Win64-Shipping.exe"; //获取exe的名称
    QProcess p;
    QString c = "taskkill /im " + exeFileName + " /f";    //exeFileName为要杀死的进程名
    p.execute(c);
    p.close();

    QProcess process(this);
    QString str = "C:/Users/Administrator.SY-202309041549/Desktop/ZNBase/2024.4.28.0958_2048+832/WindowsNoEditor/ZNBase.exe";//加可执行文件路径
    QStringList arguments;
    arguments << "-AudioMixer" << "-PixelStreamingIP=" << "172.16.16.19" << "-PixelStreamingPort=" << "8888";
    process.startDetached(str, arguments);//启动可执行文件 

}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值