增加调整kinect图片位置和大小的功能

This commit is contained in:
liuyunhui
2025-10-22 14:07:41 +08:00
parent ef9f8b870d
commit da25b9686b
4 changed files with 38 additions and 4 deletions
@@ -76,6 +76,9 @@ FFrameTextureData UNeoKinectManager::FramesData[static_cast<int32>(EKinectFrame:
UNeoKinectManager* UNeoKinectManager::EventsDispatcher = nullptr;
FTSTicker::FDelegateHandle UNeoKinectManager::TickerHandle;
float UNeoKinectManager::m_scale = 1.0f;
int UNeoKinectManager::m_shiftX = 0;
int UNeoKinectManager::m_shiftY = 0;
#pragma endregion Statics
//~ INITIALIZATION / UNINITIALIZATION
@@ -1251,7 +1254,23 @@ cv::Mat rawImg = cv::Mat::zeros(cv::Size(1920, 1080), CV_8UC1);
cv::Mat result = cv::Mat::zeros(cv::Size(960, 540), CV_8UC1);
cv::Mat dst1 = cv::Mat::zeros(cv::Size(960, 540), CV_8UC1);
cv::Mat dst2 = cv::Mat::zeros(cv::Size(960, 540), CV_8UC1);
cv::Mat showMat = cv::Mat::zeros(cv::Size(960, 540), CV_8UC1);
cv::Mat showMat = cv::Mat::zeros(cv::Size(1920, 1080), CV_8UC1);
void UNeoKinectManager::SetScaleAndShift(float scale, int shiftX, int shiftY)
{
m_scale = scale;
m_shiftX = shiftX;
m_shiftY = shiftY;
int orig_cx = showMat.cols / 2, orig_cy = showMat.rows / 2;
int new_cx = static_cast<int>(orig_cx * m_scale);
int new_cy = static_cast<int>(orig_cy * m_scale);
m_shiftX += new_cx - orig_cx;
m_shiftX += new_cy - orig_cy;
}
cv::Mat affine_mat(2, 3, CV_64FC1);
void UNeoKinectManager::UpdateFrames()
{
// if the game thread issued a shutdown, the textures may become invalid at any time
@@ -1281,12 +1300,19 @@ void UNeoKinectManager::UpdateFrames()
//applyMosaic(rawImg, 32);
cv::resize(dst1, rawImg, cv::Size(FrameData.Width, FrameData.Height), 0, 0, cv::INTER_CUBIC);
affine_mat.at<double>(0, 0) = m_scale;
affine_mat.at<double>(0, 1) = 0;
affine_mat.at<double>(0, 2) = m_shiftX;
affine_mat.at<double>(1, 0) = 0;
affine_mat.at<double>(1, 1) = m_scale;
affine_mat.at<double>(1, 2) = m_shiftY;
warpAffine(rawImg, showMat, affine_mat, rawImg.size(), cv::INTER_LINEAR, cv::BORDER_CONSTANT, cv::Scalar(255));
RHIUpdateTexture2D(
FrameData.Texture->GetRenderTargetResource()->GetRenderTargetTexture(),
0,
FUpdateTextureRegion2D(0, 0, 0, 0, FrameData.Width, FrameData.Height),
FrameData.Width * FrameData.PixelSize,
rawImg.data
showMat.data
);
}
else
@@ -546,6 +546,8 @@ public:
UFUNCTION(BlueprintPure, Category = "NeoKinect|Constants", meta = (Keywords = "length number size capability"))
static int32 GetJointCount();
UFUNCTION(BlueprintCallable, Category = "NeoKinect|Constants", meta = (Keywords = "body index scale and shift"))
static void SetScaleAndShift(float scale, int shiftX, int shiftY);
/*////////////////////////////////////////////////////////////////////////////
BLUEPRINT FUNCTIONS END
@@ -554,6 +556,9 @@ public:
private:
static float m_scale;
static int m_shiftX;
static int m_shiftY;
/** NeoKinect API sensor */
static NeoKinect::KinectSensor* Kinect;
/** Does the sensor polling */