Skip to content

Accessing GL::Texture raw data on the CPU #624

Closed Answered by eidetic-av
eidetic-av asked this question in Q&A
Discussion options

You must be logged in to vote

Ok I feel silly now! Just needed to walk away from the PC and look again after a break :)
My pixel format was normalised floats not unsigned ints.

Anyway! For anyone looking to convert magnum Texture2D into OpenCV cv::Mat and back... here's how I ended up doing it:

  using namespace Magnum;
  using namespace Corrade;

  // Grab the image on the CPU
  Image2D image = _input_texture->image(0, Image2D{PixelFormat::RGBA8Unorm});

  // and construct an opencv type from it
  cv::Mat mat(_frame_size.y(), _frame_size.x(), CV_8UC4, image.data());

  // run any opencv analysis...

  // opencv drawing... this sets all pixels to red
  mat.setTo(cv::Scalar(255, 0, 0, 255));

  // move the resulting cv…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by eidetic-av
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants