Skip to content

Commit 30dc169

Browse files
authored
Merge pull request #10 from g0415shenw/main
将TArray<color>转mat放到子线程进行
2 parents e3006c2 + 3b37cda commit 30dc169

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

Source/InVideo/Private/InSceneRecord.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,27 +150,18 @@ void AInSceneRecord::HandleFrameData(TArray<FColor> Bitmap, int32 x, int32 y)
150150
m_WrapOpenCv->m_VideoWriter.open(cvFilePath, cv::VideoWriter::fourcc('X', 'V', 'I', 'D'), m_Fps, cv::Size(m_ImageX, m_ImageY));
151151
}
152152

153-
int count = 0;
154-
for (int i = 0; i < Bitmap.Num(); i++)
155-
{
156-
m_ImageBuf[count] = Bitmap[i].B;
157-
m_ImageBuf[count + 1] = Bitmap[i].G;
158-
m_ImageBuf[count + 2] = Bitmap[i].R;
159-
count += 3;
160-
}
161-
162153
if (false == m_WrapOpenCv->m_VideoWriter.isOpened())
163154
{
164155
UE_LOG(LogTemp, Error, TEXT("AInSceneRecord m_VideoWriter isOpened"));
165156
return;
166157
}
158+
167159
if (nullptr == m_Thread)
168160
{
169161
m_Thread = FRunnableThread::Create(this, TEXT("SceneRecord Thread"));
170162
}
171-
cv::Mat img(m_ImageY,m_ImageX,CV_8UC3, (unsigned char*)m_ImageBuf);
172-
auto newImg = img.clone();
173-
m_WrapOpenCv->m_ImageQueue.Enqueue(newImg);
163+
164+
m_WrapOpenCv->m_ImageQueue.Enqueue(Bitmap);
174165
}
175166

176167
bool AInSceneRecord::Init()
@@ -185,8 +176,20 @@ uint32 AInSceneRecord::Run()
185176
{
186177
if (false == m_WrapOpenCv->m_ImageQueue.IsEmpty())
187178
{
188-
cv::Mat img;
189-
m_WrapOpenCv->m_ImageQueue.Dequeue(img);
179+
TArray<FColor> Bitmap;
180+
m_WrapOpenCv->m_ImageQueue.Dequeue(Bitmap);
181+
182+
int count = 0;
183+
for (int i = 0; i < Bitmap.Num(); i++)
184+
{
185+
m_ImageBuf[count] = Bitmap[i].B;
186+
m_ImageBuf[count + 1] = Bitmap[i].G;
187+
m_ImageBuf[count + 2] = Bitmap[i].R;
188+
count += 3;
189+
}
190+
191+
cv::Mat img(m_ImageY, m_ImageX, CV_8UC3, (unsigned char*)m_ImageBuf);
192+
190193
m_WrapOpenCv->m_VideoWriter.write(img);
191194
continue;
192195
}

Source/InVideo/Public/InSceneRecord.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class INVIDEO_API AInSceneRecord : public AActor, public FRunnable
5353
{
5454
public:
5555
cv::VideoWriter m_VideoWriter;
56-
TQueue<cv::Mat> m_ImageQueue;
56+
TQueue<TArray<FColor>> m_ImageQueue;
5757
};
5858
WrapOpenCv* m_WrapOpenCv = nullptr;
5959

0 commit comments

Comments
 (0)