adynathos / AugmentedUnreality

Augmented reality for Unreal Engine 4
Other
289 stars 114 forks source link

Convert an image from the scene to OpenCV #16

Closed rubenalvesbcn closed 6 years ago

rubenalvesbcn commented 6 years ago

Hi!

First, I'd like to say that this is not an issue, it's more a question.

I see in this plugin and in many other tutorials that is easy to convert a stream from the camera to Unreal using OpenCV.

But I've never seen the opposite, how to convert an image from the Unreal Scene (FTextureRenderTargetResource, UTextureRenderTarget2D, UTexture2D, USceneCaptureComponent2D) to OpenCV (cv::Mat).

Do you know how we could do this?

adynathos commented 6 years ago

Here they show how to get the pointer to the pixel data stored by the texture: Accessing pixel values of Texture2D

This loop converts a texture pixel pointer to cv::Mat. To go the other way, reverse the order of the assignments - if we didn't change the names it would look like this: src_pixel.val[2] = dest_pixel_ptr->R;

Also initialize the matrix with the correct size and type.