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);//启动可执行文件
}