How to integrate opencv in unreal 4.27. ABOUT ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER

To integrate opencv into 4.27

  1. Import lib and dll in build.cs.
  2. I made a WebcamReader according to the tutorial.

https://unreal.gg-labs.com/wiki-archives/ar-vr/integrating-opencv-into-unreal-engine-4

Here is a link to the tutorial you referenced.
But I think the tutorial is an older version of Unreal.
I’m using 4.27, and I somehow solved it in build.cs, but I don’t know what to do with ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER.

When I searched, the latest version changed to ENQUEUE_RENDER_COMMAND and told me to do it instead, but how should I use it?

Below is the part from the tutorial.

ENQUEUE_UNIQUE_RENDER_COMMAND_TWOPARAMETER(
             UpdateTextureRegionsData,
             FUpdateTextureRegionsData*, RegionData, RegionData,
             bool, bFreeData, bFreeData,
             {
             for (uint32 RegionIndex = 0; RegionIndex < RegionData->NumRegions; ++RegionIndex)
             {
                 int32 CurrentFirstMip = RegionData->Texture2DResource->GetCurrentFirstMip();
                 if (RegionData->MipIndex >= CurrentFirstMip)
                 {
                     RHIUpdateTexture2D(
                         RegionData->Texture2DResource->GetTexture2DRHI(),
                         RegionData->MipIndex - CurrentFirstMip,
                         RegionData->Regions[RegionIndex],
                         RegionData->SrcPitch,
                         RegionData->SrcData
                         + RegionData->Regions[RegionIndex].SrcY * RegionData->SrcPitch
                         + RegionData->Regions[RegionIndex].SrcX * RegionData->SrcBpp
                         );
                 }
             }
             if (bFreeData)
             {
                 FMemory::Free(RegionData->Regions);
                 FMemory::Free(RegionData->SrcData);
             }
             delete RegionData;
         });

Hey @JoHyeok32 , sorry I tried to submit the code I have been using but had some weird issue, anyway this is where I got up to (I have been trying with UE5 but the changes seem to create to many issues so I’m going back to version 4.27), let me know how it goes

AWebcamReader::UpdateTextureRegions(UTexture2D* Texture, int32 MipIndex, uint32 NumRegions, FUpdateTextureRegion2D* Regions, uint32 SrcPitch, uint32 SrcBpp, uint8* SrcData, bool bFreeData)
{
    if (Texture->GetResource())
    {
        struct FUpdateTextureRegionsData
        {
            FTexture2DResource* Texture2DResource;
            int32 MipIndex;
            uint32 NumRegions;
            FUpdateTextureRegion2D* Regions;
            uint32 SrcPitch;
            uint32 SrcBpp;
            uint8* SrcData;
        };

        FUpdateTextureRegionsData* RegionData = new FUpdateTextureRegionsData;

        RegionData->Texture2DResource = (FTexture2DResource*)Texture->GetResource();
        RegionData->MipIndex = MipIndex;
        RegionData->NumRegions = NumRegions;
        RegionData->Regions = Regions;
        RegionData->SrcPitch = SrcPitch;
        RegionData->SrcBpp = SrcBpp;
        RegionData->SrcData = SrcData;

        ENQUEUE_RENDER_COMMAND(UpdateTextureRegionsData)(
            [RegionData, bFreeData, Texture](FRHICommandListImmediate& RHICmdList)
            {
                for (uint32 RegionIndex = 0; RegionIndex < RegionData->NumRegions; ++RegionIndex)
                {
                    int32 CurrentFirstMip = RegionData->Texture2DResource->GetCurrentFirstMip();
                    if (RegionData->MipIndex >= CurrentFirstMip)
                    {
                        RHIUpdateTexture2D(
                            RegionData->Texture2DResource->GetTexture2DRHI(),
                            RegionData->MipIndex - CurrentFirstMip,
                            RegionData->Regions[RegionIndex],
                            RegionData->SrcPitch,
                            RegionData->SrcData
                            + RegionData->Regions[RegionIndex].SrcY * RegionData->SrcPitch
                            + RegionData->Regions[RegionIndex].SrcX * RegionData->SrcBpp
                        );
                    }
                }
                if (bFreeData)
                {
                    FMemory::Free(RegionData->Regions);
                    FMemory::Free(RegionData->SrcData);
                }
                delete RegionData;
            });
    }
}