修改Kinect交互
This commit is contained in:
Binary file not shown.
Binary file not shown.
+4
@@ -19,6 +19,8 @@ public class NeoKinectUnreal : ModuleRules
|
|||||||
{
|
{
|
||||||
"Core",
|
"Core",
|
||||||
"CoreUObject",
|
"CoreUObject",
|
||||||
|
"OpenCV",
|
||||||
|
"OpenCVHelper"
|
||||||
// ... add other public dependencies that you statically link with here ...
|
// ... add other public dependencies that you statically link with here ...
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -34,6 +36,7 @@ public class NeoKinectUnreal : ModuleRules
|
|||||||
|
|
||||||
string neoKinectPath = Path.Combine(thirdPartyPath, "NeoKinect");
|
string neoKinectPath = Path.Combine(thirdPartyPath, "NeoKinect");
|
||||||
string kinectPath = Path.Combine(thirdPartyPath, "Kinect");
|
string kinectPath = Path.Combine(thirdPartyPath, "Kinect");
|
||||||
|
//string openCVPath = Path.Combine(thirdPartyPath, "OpenCV");
|
||||||
|
|
||||||
PublicSystemLibraryPaths.Add(Path.Combine(neoKinectPath, "Lib"));
|
PublicSystemLibraryPaths.Add(Path.Combine(neoKinectPath, "Lib"));
|
||||||
PublicIncludePaths.Add(Path.Combine(neoKinectPath, "Inc"));
|
PublicIncludePaths.Add(Path.Combine(neoKinectPath, "Inc"));
|
||||||
@@ -64,5 +67,6 @@ public class NeoKinectUnreal : ModuleRules
|
|||||||
const string ProjectDLLDir = "$(ProjectDir)/Binaries/Win64";
|
const string ProjectDLLDir = "$(ProjectDir)/Binaries/Win64";
|
||||||
RuntimeDependencies.Add(Path.Combine(ProjectDLLDir, KinectFaceDllName));
|
RuntimeDependencies.Add(Path.Combine(ProjectDLLDir, KinectFaceDllName));
|
||||||
RuntimeDependencies.Add(Path.Combine(ProjectDLLDir, "NuiDatabase/..."), StagedFileType.NonUFS);
|
RuntimeDependencies.Add(Path.Combine(ProjectDLLDir, "NuiDatabase/..."), StagedFileType.NonUFS);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-2
@@ -12,7 +12,9 @@
|
|||||||
#include "Engine/TextureRenderTarget2D.h"
|
#include "Engine/TextureRenderTarget2D.h"
|
||||||
#include "HAL/PlatformProcess.h"
|
#include "HAL/PlatformProcess.h"
|
||||||
#include "UObject/Package.h"
|
#include "UObject/Package.h"
|
||||||
|
#include "PreOpenCVHeaders.h"
|
||||||
|
#include "opencv2/opencv.hpp"
|
||||||
|
#include "PostOpenCVHeaders.h"
|
||||||
using namespace NeoKinect;
|
using namespace NeoKinect;
|
||||||
|
|
||||||
//~ STRUCTS METHODS
|
//~ STRUCTS METHODS
|
||||||
@@ -74,7 +76,6 @@ FFrameTextureData UNeoKinectManager::FramesData[static_cast<int32>(EKinectFrame:
|
|||||||
UNeoKinectManager* UNeoKinectManager::EventsDispatcher = nullptr;
|
UNeoKinectManager* UNeoKinectManager::EventsDispatcher = nullptr;
|
||||||
FTSTicker::FDelegateHandle UNeoKinectManager::TickerHandle;
|
FTSTicker::FDelegateHandle UNeoKinectManager::TickerHandle;
|
||||||
|
|
||||||
|
|
||||||
#pragma endregion Statics
|
#pragma endregion Statics
|
||||||
|
|
||||||
//~ INITIALIZATION / UNINITIALIZATION
|
//~ INITIALIZATION / UNINITIALIZATION
|
||||||
@@ -238,6 +239,7 @@ void UNeoKinectManager::InitStatics()
|
|||||||
fd.UFrameType = static_cast<EKinectFrame>(i);
|
fd.UFrameType = static_cast<EKinectFrame>(i);
|
||||||
fd.BufferSize = fd.Width * fd.Height * fd.PixelSize;
|
fd.BufferSize = fd.Width * fd.Height * fd.PixelSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#pragma endregion Initialization_Uninitialization
|
#pragma endregion Initialization_Uninitialization
|
||||||
|
|
||||||
@@ -1139,6 +1141,42 @@ void UNeoKinectManager::UpdateFrames()
|
|||||||
if (Buffer && FrameData.IsTextureValid())
|
if (Buffer && FrameData.IsTextureValid())
|
||||||
{
|
{
|
||||||
ThreadBuffer.Lock();
|
ThreadBuffer.Lock();
|
||||||
|
{
|
||||||
|
if (FrameData.KFrameType == KinectFrameType::BodyIndex)
|
||||||
|
{
|
||||||
|
cv::Mat binaryImage(FrameData.Height, FrameData.Width, CV_8UC4);
|
||||||
|
memcpy(binaryImage.data, Buffer, FrameData.Height * FrameData.Width * FrameData.PixelSize);
|
||||||
|
cv::Mat processedImage;
|
||||||
|
cv::resize(binaryImage, processedImage, cv::Size(FrameData.Width / 2, FrameData.Height / 2), 0, 0, cv::INTER_CUBIC);
|
||||||
|
cv::Mat kernel = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5));
|
||||||
|
cv::morphologyEx(processedImage, processedImage, cv::MORPH_OPEN, kernel); // 去噪
|
||||||
|
cv::morphologyEx(processedImage, processedImage, cv::MORPH_CLOSE, kernel); // 填充
|
||||||
|
cv::GaussianBlur(processedImage, processedImage, cv::Size(5, 5), 1.0);
|
||||||
|
std::vector<std::vector<cv::Point>> contours;
|
||||||
|
cv::findContours(processedImage, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
|
||||||
|
std::vector<std::vector<cv::Point>> approxContours(contours.size());
|
||||||
|
for (size_t j = 0; j < contours.size(); j++) {
|
||||||
|
cv::approxPolyDP(contours[j], approxContours[j], 2.0, true);
|
||||||
|
}
|
||||||
|
double minArea = 500; // 示例阈值
|
||||||
|
for (auto it = approxContours.begin(); it != approxContours.end(); ) {
|
||||||
|
if (cv::contourArea(*it) < minArea) it = approxContours.erase(it);
|
||||||
|
else ++it;
|
||||||
|
}
|
||||||
|
cv::drawContours(processedImage, approxContours, -1, cv::Scalar(0));
|
||||||
|
cv::resize(processedImage, processedImage, cv::Size(FrameData.Width, FrameData.Height), 0, 0, cv::INTER_CUBIC);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
RHIUpdateTexture2D(
|
||||||
|
FrameData.Texture->GetRenderTargetResource()->GetRenderTargetTexture(),
|
||||||
|
0,
|
||||||
|
FUpdateTextureRegion2D(0, 0, 0, 0, FrameData.Width, FrameData.Height),
|
||||||
|
FrameData.Width * FrameData.PixelSize,
|
||||||
|
processedImage.data
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
RHIUpdateTexture2D(
|
RHIUpdateTexture2D(
|
||||||
FrameData.Texture->GetRenderTargetResource()->GetRenderTargetTexture(),
|
FrameData.Texture->GetRenderTargetResource()->GetRenderTargetTexture(),
|
||||||
@@ -1148,6 +1186,7 @@ void UNeoKinectManager::UpdateFrames()
|
|||||||
Buffer
|
Buffer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ThreadBuffer.Unlock();
|
ThreadBuffer.Unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -7,7 +7,6 @@
|
|||||||
#include "NeoKinectEnums.h"
|
#include "NeoKinectEnums.h"
|
||||||
#include "PixelFormat.h"
|
#include "PixelFormat.h"
|
||||||
#include "Containers/Ticker.h"
|
#include "Containers/Ticker.h"
|
||||||
|
|
||||||
#include "NeoKinectManager.generated.h"
|
#include "NeoKinectManager.generated.h"
|
||||||
|
|
||||||
class FKinectThread;
|
class FKinectThread;
|
||||||
|
|||||||
Reference in New Issue
Block a user