将RenderTexture复制到图像 [英] Copy RenderTexture to Image

查看:864
本文介绍了将RenderTexture复制到图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图复制 sf :: RenderTexture (与 sf :: Image & sf :: Text 上),到Opencv Mat对象。我们可以将 sf :: Image 转换为 cv :: Mat (Opencv)by

I'm trying to copy sf::RenderTexture (with sf::Image & sf::Text on it), to Opencv Mat object. We can convert an sf::Image to cv::Mat (Opencv) by

sf::Image img;
cv::Size size(img.getSize().x, img.getSize().y);    
cv::Mat mat(size,CV_8UC4, (void*)img.getPixelsPtr(), cv::Mat::AUTO_STEP);
cv::cvtColor(mat, mat, cv::COLOR_RGBA2BGRA);

据我所知,在SFML中我们不能直接添加文本到 sf :: Image 但是我们必须使用RenderWindow或RenderTexture。我想只有解决方法是按照以下顺序加载对象

as far as I know, in SFML we cannot add text directly to sf::Image but we have to use RenderWindow or RenderTexture for that. I guess only workaround is to load objects in following order


sf :: Image - > sf :: Texture - > sf :: Sprite - > sf :: RenderTexture

sf::Image --> sf::Texture --> sf::Sprite -->sf::RenderTexture

sf :: Text - > sf :: RenderTexture

sf::Text --> sf::RenderTexture

最后将RenderTexture复制到sf :: Image然后将其转换为cv :: Mat

我想将sf :: RenderTexture复制到sf :: Image需要很长时间。


任何其他解决方法?像使用sf :: Image :: loadFromMemory();

Finally Copy RenderTexture to sf::Image then convert it to cv::Mat
I suppose it will take long time to copy sf::RenderTexture back to sf::Image.

any other workaround for this? like using sf::Image::loadFromMemory();

PS:一些引用这里& 这里

P.S: Some references here & here

推荐答案

不,对于SFML没有真正的替代品。从VRAM复制到RAM不是很快,但应该仍然能够执行在一个okay-ish帧率。也许你应该试试看看性能是否真的影响你的场景。

No, there isn't really an alternative when it comes to SFML. Copying from VRAM to RAM isn't very fast, but should still be able to perform at a okay-ish framerate. Maybe you should just give it a try and see whether the performance does really impact your scenario.

这里的问题是SFML在GPU空间中操作,因此文本呈现

The issue here is that SFML operates in the GPU space, so text rendering is made for rendering with your GPU similar thing with sprite, but what you actually seem to want is CPU rendering of text and sprites.

如果你只翻译sprite(没有缩放/缩放),你可以使用它来渲染你的GPU与sprite类似的东西,但是你真正想要的是CPU渲染的文本和sprites。旋转),应该相对容易在 sf :: Image 之上构建此类功能。

If you only translate sprites (no scaling/rotating) it should be relatively easy to build such functionality on top of sf::Image.

您可能希望直接使用freetype,而不将字体数据移动到GPU。

For text rendering you might want to use freetype directly and not move the font data to the GPU.

这篇关于将RenderTexture复制到图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆