修改交互功能
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+138
-11
@@ -1124,6 +1124,134 @@ UTextureRenderTarget2D* UNeoKinectManager::CreateTexture(int32 Width, int32 Heig
|
||||
return Texture;
|
||||
}
|
||||
|
||||
long long lastTime = 0;
|
||||
long long currentTime = 0;
|
||||
long long GetCurrentTimeInMilliseconds()
|
||||
{
|
||||
// 使用std::chrono获取当前时间点
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
|
||||
// 将时间点转换为时间戳(自纪元以来的持续时间)
|
||||
auto duration = now.time_since_epoch();
|
||||
|
||||
// 将持续时间转换为毫秒
|
||||
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
|
||||
|
||||
return milliseconds;
|
||||
}
|
||||
|
||||
cv::RNG rng(12345); // 固定种子
|
||||
cv::Scalar color(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
|
||||
void changeColor(cv::Mat& src)
|
||||
{
|
||||
for (int i = 0; i < src.rows; i++) {
|
||||
for (int j = 0; j < src.cols; j++) {
|
||||
cv::Vec4b& pixel = src.at<cv::Vec4b>(i, j);
|
||||
//if (pixel[0] <= 50 || pixel[1] <= 50 || pixel[2] <= 50)
|
||||
{
|
||||
pixel[0] = color[0]; // B通道
|
||||
pixel[1] = color[1]; // G通道
|
||||
pixel[2] = color[2]; // R通道
|
||||
// A通道保持不变
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// pixel[0] = 0; // B通道
|
||||
// pixel[1] = 0; // G通道
|
||||
// pixel[2] = 0; // R通道
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void changeColor2(cv::Mat& src)
|
||||
{
|
||||
for (int i = 0; i < src.rows; i++)
|
||||
{
|
||||
for (int j = 0; j < src.cols; j++)
|
||||
{
|
||||
cv::Vec4b& pixel = src.at<cv::Vec4b>(i, j);
|
||||
if (pixel[0] > 0 || pixel[1] > 0 || pixel[2] > 0)
|
||||
{ // 检查R通道(OpenCV中BGR顺序)
|
||||
pixel[0] = color[0]; // B通道
|
||||
pixel[1] = color[1]; // G通道
|
||||
pixel[2] = color[2]; // R通道
|
||||
// A通道保持不变
|
||||
}
|
||||
else
|
||||
{
|
||||
pixel[0] = 0; // B通道
|
||||
pixel[1] = 0; // G通道
|
||||
pixel[2] = 0; // R通道
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void combine(cv::Mat& src, cv::Mat& dst)
|
||||
{
|
||||
for (int i = 0; i < src.rows; i++)
|
||||
{
|
||||
for (int j = 0; j < src.cols; j++)
|
||||
{
|
||||
const cv::Vec4b& pixel = src.at<cv::Vec4b>(i, j);
|
||||
if (pixel[0] > 0 || pixel[1] > 0 || pixel[2] > 0)
|
||||
{ // 检查R通道(OpenCV中BGR顺序)
|
||||
cv::Vec4b& detPixel = dst.at<cv::Vec4b>(i, j);
|
||||
detPixel = pixel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void merge(cv::Mat& src1, cv::Mat& src2, cv::Mat& dst)
|
||||
{
|
||||
for (int i = 0; i < src1.rows; i++)
|
||||
{
|
||||
for (int j = 0; j < src1.cols; j++)
|
||||
{
|
||||
const cv::Vec4b& pixel1 = src1.at<cv::Vec4b>(i, j);
|
||||
const cv::Vec4b& pixel2 = src2.at<cv::Vec4b>(i, j);
|
||||
if (pixel1[0] > 0 || pixel1[1] > 0 || pixel1[2] > 0)
|
||||
{
|
||||
cv::Vec4b& detPixel = dst.at<cv::Vec4b>(i, j);
|
||||
detPixel = pixel1;
|
||||
}
|
||||
if (pixel2[0] > 0 || pixel2[1] > 0 || pixel2[2] > 0)
|
||||
{
|
||||
cv::Vec4b& detPixel = dst.at<cv::Vec4b>(i, j);
|
||||
detPixel = pixel2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void scalar(cv::Mat& src, cv::Mat& dst)
|
||||
{
|
||||
cv::Rect roi(16, 9, src.cols - 16, src.rows - 9);
|
||||
cv::Mat roiMat = src(roi);
|
||||
cv::resize(roiMat, dst, src.size(), 0, 0, cv::INTER_CUBIC);
|
||||
}
|
||||
|
||||
|
||||
void applyMosaic(cv::Mat& image, int blockSize = 10) {
|
||||
for (int y = 0; y < image.rows; y += blockSize) {
|
||||
for (int x = 0; x < image.cols; x += blockSize) {
|
||||
cv::Rect block(x, y, cv::min(blockSize, image.cols - x),
|
||||
cv::min(blockSize, image.rows - y));
|
||||
cv::Scalar _color = cv::mean(image(block));
|
||||
cv::rectangle(image, block, _color, cv::FILLED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
void UNeoKinectManager::UpdateFrames()
|
||||
{
|
||||
// if the game thread issued a shutdown, the textures may become invalid at any time
|
||||
@@ -1142,24 +1270,23 @@ void UNeoKinectManager::UpdateFrames()
|
||||
{
|
||||
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);
|
||||
if (i == static_cast<int32>(EKinectFrame::BodyIndex_ColorSpace))
|
||||
{
|
||||
memcpy(rawImg.data, Buffer, FrameData.Height * FrameData.Width * FrameData.PixelSize);
|
||||
cv::resize(rawImg, dst1, 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);
|
||||
cv::resize(processedImage, processedImage, cv::Size(FrameData.Width, FrameData.Height), 0, 0, cv::INTER_CUBIC);
|
||||
cv::morphologyEx(dst1, dst1, cv::MORPH_OPEN, kernel); // 去噪
|
||||
cv::morphologyEx(dst1, dst1, cv::MORPH_CLOSE, kernel); // 填充
|
||||
cv::GaussianBlur(dst1, dst1, cv::Size(5, 5), 1.0);
|
||||
//applyMosaic(rawImg, 32);
|
||||
cv::resize(dst1, rawImg, 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
|
||||
rawImg.data
|
||||
);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user