convert k4a::image to cv::Mat ,and it will stutter after about a minute later

chong peng 106 Reputation points
2020-10-15T00:57:33.61+00:00

Environment:
win10;
VS2017,
i7-9700KF,
RAM:48G,
2080TI;
UnrealEngine4.25.3

question One:
i convert k4a::image to Mat,and Mat to Texture2D of unreal engine 4.25.3,but it will cyclical stutter after about a minute later,
i think the problem is what AzureKinectDK will Memory recycling when RAM is almost full or cycle time
right ?please help me !!!

question Two;
do this:
k4a::image tansformedImage,transformedRGB;
k4a::image img = sensorCapture.get_color_image();
k4a::image depth = sensorCapture.get_depth_image();
tansformedImage=trans.depth_image_to_color_camera(depth);
cv::Mat ColorFra= K4a2RGBMat(img);
cv::Mat TranFra = K4a2DepthMat(tansformedImage);

/UnrealEngine render thread func/
AsyncTask(ENamedThreads::GameThread, &
{
/Test the following two functions/
Mat2RGBTexture(ColorFra); //only run this func, the system-Task Manager - Performance - memory will increase from 7G to 27G,and cycle;
Mat2TransformedTexture(TranFra);//Only run this func, the sustem-Task Manager - Performance - memory will increase from 7G to 17G,and cycle;

important:

run two functions ,the RAM will full ,and almost Stuck,the RAM will increase 7G to 50G,and more;
});

two question ,thank u!!!

Azure Kinect DK
Azure Kinect DK
A Microsoft developer kit and peripheral device with advanced artificial intelligence sensors for sophisticated computer vision and speech models.
292 questions
{count} vote

Accepted answer
  1. chong peng 106 Reputation points
    2020-10-18T14:24:53.003+00:00

    I have solved the problem successfully

    void AzureKinectDevice::k4a2TextureRGB(k4a::image inImg)
    {

    uint8_t* data = inImg.get_buffer();
    int T_Width = inImg.get_width_pixels();
    int T_height = inImg.get_height_pixels();
    UTexture2D* NewTexture = UTexture2D::CreateTransient((int32)T_Width, (int32)T_height);
    //if it's size is stable,shouldn't create Utexture2D in while() loop func or tick 
    void* Datas = NewTexture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
    FMemory::Memcpy(Datas, data, inImg.get_size());
    //call of tick or while(1), FMemory::Memcpy will cause RAM increasing to almost full ,although Temporary object will be released
    //suggest :  FMemory::Memmove(Datas, data, inImg.get_size());
    NewTexture->PlatformData->Mips[0].BulkData.Unlock();
    NewTexture->UpdateResource();
    

    }

    Refer to the link
    https://github.com/UEBoy2019/Convert-KinectDK-k4a-image-to-Texture2D-for-UnrealEngine-4.25-/blob/master/k4a::image%20to%20Texture2D%20for%20UnrealEngine4.25%20.cpp

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.