tarAthgiLegfU7

This commit is contained in:
Sch 2023-07-08 10:41:34 +08:00
parent fa27c3d28e
commit 62544e52d2
10 changed files with 58 additions and 18 deletions

View File

@ -3,6 +3,7 @@
#pragma once
#include "CoreMinimal.h"
#include "Engine/Texture2D.h"
#include "UObject/Interface.h"
#include "CutMainWidgetInterface.generated.h"
@ -24,5 +25,6 @@ class CUT5_API ICutMainWidgetInterface
public:
virtual void OnUpdateVideo(FGuid UUID, UTexture2D* Texture) {};
virtual void OnUpdateLightArray(const TArray<FColor>& LightArray) {};
};

View File

@ -24,26 +24,26 @@ int32 FOpencvUtils::GetVideoFrameCount(FString VideoPath)
return FrameCount;
}
TArray<FColor> FOpencvUtils::GetVideoFrameLightArray(FString VideoPath, int32 Width, int32 Height)
TArray<TArray<FColor>> FOpencvUtils::GetVideoFrameLightArray(FString VideoPath, int32 X, int32 Y)
{
cv::VideoCapture VideoCapture;
VideoCapture.open(TCHAR_TO_UTF8(*VideoPath));
TArray<FColor> LightArray;
TArray<TArray<FColor>> Colors;
while (VideoCapture.isOpened())
{
cv::Mat Array;
if (VideoCapture.grab())
{
TArray<FColor> LightArray;
VideoCapture.retrieve(Array);
cv::resize(Array, Array, cv::Size(Width, Height));
for (int32 i = 0; i < Array.rows; i++)
cv::resize(Array, Array, cv::Size(X, Y));
for (int32 i = 0; i < Array.cols * Array.rows; i++)
{
for (int32 j = 0; j < Array.cols; j++)
{
cv::Vec3b Pixel = Array.at<cv::Vec3b>(i, j);
LightArray.Add(FColor(Pixel[2], Pixel[1], Pixel[0]));
}
LightArray.Add(FColor(Array.data[i * 3 + 0], Array.data[i * 3 + 1], Array.data[i * 3 + 2], 255));
}
Colors.Add(LightArray);
}
if (Array.empty())
{
@ -51,5 +51,5 @@ TArray<FColor> FOpencvUtils::GetVideoFrameLightArray(FString VideoPath, int32 Wi
}
}
VideoCapture.release();
return LightArray;
return Colors;
}

View File

@ -6,6 +6,6 @@ class FOpencvUtils
{
public:
static int32 GetVideoFrameCount(FString VideoPath);
static TArray<FColor> GetVideoFrameLightArray(FString VideoPath, int32 Width, int32 Height);
static TArray<TArray<FColor>> GetVideoFrameLightArray(FString VideoPath, int32 X, int32 Y);
};

View File

@ -91,7 +91,7 @@ struct CUT5_API FClipData
// Light Array
TArray<FColor> LightArrayData;
TArray<TArray<FColor>> LightArrayData;

View File

@ -129,14 +129,18 @@ void SCutMainWindow::OnUpdateVideo(FGuid UUID, UTexture2D* Texture)
{
const int32 X = Texture->GetSizeX() / FGlobalData::LightArrayX;
const int32 Y = Texture->GetSizeY() / FGlobalData::LightArrayY;
const int32 ColorIndex = X * i + j * Y * Texture->GetSizeX();
LightArrayPanel->UpdateLightArray(i, j, *(Colors + ColorIndex));
// const int32 ColorIndex = X * i + j * Y * Texture->GetSizeX();
// LightArrayPanel->UpdateLightArray(i, j, *(Colors + ColorIndex));
}
}
Texture->GetPlatformData()->Mips[0].BulkData.Unlock();
}
void SCutMainWindow::OnUpdateLightArray(const TArray<FColor>& LightArray)
{
ICutMainWidgetInterface::OnUpdateLightArray(LightArray);
LightArrayPanel->LightGridColors = LightArray;
}
END_SLATE_FUNCTION_BUILD_OPTIMIZATION

View File

@ -35,5 +35,6 @@ public:
virtual void OnUpdateVideo(FGuid UUID, UTexture2D* Texture) override;
virtual void OnUpdateLightArray(const TArray<FColor>& LightArray) override;
};

View File

@ -4,6 +4,8 @@
#include "STimelineClip.h"
#include "SlateOptMacros.h"
#include "Engine/Engine.h"
#include "Engine/Texture2D.h"
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
@ -93,7 +95,6 @@ void STimelineClip::Seek(int32 Frame)
// ClipData->VideoCapture->read(Read);
UTexture2D* Texture = UTexture2D::CreateTransient(Read.cols, Read.rows, PF_B8G8R8A8);
if (Texture)
{
A = FDateTime::Now();
@ -116,6 +117,17 @@ void STimelineClip::Seek(int32 Frame)
}
break;
case ETrackType::LightArrayTrack:
{
const int32 Offset = Frame - (ClipData->ClipStartTime / FGlobalData::DefaultTimeTickSpace);
const int32 SeekMovieFrame = ClipData->VideoStartFrame + Offset;
if (SeekMovieFrame < ClipData->LightArrayData.Num())
{
MainWidgetInterface->OnUpdateLightArray(ClipData->LightArrayData[SeekMovieFrame]);
}
break;
}
default:
break;
}

View File

@ -11,6 +11,8 @@
#include <opencv2/imgproc.hpp>
#include <opencv2/core/mat.hpp>
#include "Widgets/Layout/SBox.h"
/**
*
*/

View File

@ -4,6 +4,8 @@
#include "STrackBody.h"
#include "SlateOptMacros.h"
#include "Cut5/Utils/OpencvUtils.h"
#include "Engine/Engine.h"
#include "Widgets/Layout/SConstraintCanvas.h"
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
@ -72,7 +74,17 @@ FReply STrackBody::OnDrop(const FGeometry& MyGeometry, const FDragDropEvent& Dra
{
const FTrackClipDragOperation& ClipDragOperation = static_cast<FTrackClipDragOperation&>(DragDropEvent.GetOperation().ToSharedRef().Get());
if (ClipDragOperation.TimelinePropertyData.Type != TrackHead->TrackData.TrackType)
return FReply::Handled().EndDragDrop();
{
if (ClipDragOperation.TimelinePropertyData.Type == ETrackType::VideoTrack && TrackHead->TrackData.TrackType == ETrackType::LightArrayTrack)
{
}
else
{
return FReply::Handled().EndDragDrop();
}
}
FClipData NewClipData;
NewClipData.ClipGuid = FGuid::NewGuid();
NewClipData.ClipType = ClipDragOperation.TimelinePropertyData.Type;
@ -83,10 +95,16 @@ FReply STrackBody::OnDrop(const FGeometry& MyGeometry, const FDragDropEvent& Dra
NewClipData.MoviePath = ClipDragOperation.TimelinePropertyData.MoviePath;
NewClipData.ClipEndTime = NewClipData.ClipStartTime + ClipDragOperation.TimelinePropertyData.MovieFrameLength * FGlobalData::DefaultTimeTickSpace;
NewClipData.VideoCapture = ClipDragOperation.VideoCapture;
if (TrackHead->TrackData.TrackType == ETrackType::LightArrayTrack)
{
NewClipData.ClipType = ETrackType::LightArrayTrack;
NewClipData.LightArrayData = FOpencvUtils::GetVideoFrameLightArray(ClipDragOperation.TimelinePropertyData.MoviePath, FGlobalData::LightArrayX, FGlobalData::LightArrayY);
}
}
else
else if (ClipDragOperation.TimelinePropertyData.Type == ETrackType::LightArrayTrack)
{
NewClipData.ClipEndTime = NewClipData.ClipStartTime + 200;
}

View File

@ -3,6 +3,7 @@
#pragma once
#include "CoreMinimal.h"
#include "Engine/Texture2D.h"
#include "Widgets/SCompoundWidget.h"
/**