Texture2D to cv::Mat conversion

Hi everybody,

I had some C++ code that integrated OpenCV and it worked great in UE4. I tried to port that to UE5, but it keeps crashing whenever I try to initialize an OpenCV CV::Mat. Here is a tiny snippet that I use for testing and keeps crashing on me:

FTexture2DMipMap* MyMipMap = &MyTexture2D->PlatformData->Mips[0];
FByteBulkData* RawImageData = &MyMipMap->BulkData;

uint8* Pixels = static_cast<uint8*>(RawImageData->Lock(LOCK_READ_ONLY));

int32 SizeX = MyTexture2D->GetSizeX();
int32 SizeY = MyTexture2D->GetSizeY();
cv::Vec3b* newColor = new cv::Vec3b();

cv::Mat* imageMat = new cv::Mat(SizeY, SizeX, CV_8UC4, Pixels);//CV_64FC3);
RawImageData->Unlock();
return;

Any help is much appreciated !!

2 Likes

Issue solved by using the OpenCV version that came with the engine rather than downloading separately

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.