Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to convert SFML image to OpenCV Mat in c++?

Below code is used to convert an OpenCV Mat image into SFML image. How to convert SFML image back to Mat image?

cv::Mat frameBGR, frameBGRA; sf::Image image;
cv::cvtColor(frameBGR,frameRGBA, cv::COLOR_BGR2RGBA);
image.create(frameRGBA.cols, frameRGBA.rows, frameRGBA.ptr());

If texture or sprite can't be converted to OpenCV Mat,then is it possible to convert sf::Image to OpenGL and convert it back to cv::Mat

sf::Texture texture;
sf::Event event;
sf::Sprite sprite;
texture.loadFromImage(image);
sprite.setTexture(texture);

How to convert SFML image to OpenCV Mat in c++?

Below code is used to convert an OpenCV Mat image into SFML image. How to convert SFML image back to Mat image?

 cv::Mat frameBGR, frameBGRA;    sf::Image image;
image; cv::cvtColor(frameBGR,frameRGBA, cv::COLOR_BGR2RGBA);
image.create(frameRGBA.cols, frameRGBA.rows, frameRGBA.ptr());

frameRGBA.ptr());

If texture or sprite can't be converted to OpenCV Mat,then is it possible to convert sf::Image to OpenGL and convert it back to cv::Mat

 sf::Texture texture;
texture; sf::Event event;
event; sf::Sprite sprite;
texture.loadFromImage(image);
sprite.setTexture(texture);

sprite; texture.loadFromImage(image); sprite.setTexture(texture);

Update: I referred this post, but still was not able to convert.

    void* buffer = ℑ 
    cv::Mat image_mat = cv::Mat(cvSize(500, 500),CV_8UC4, buffer, cv::Mat::AUTO_STEP);  
    cvtColor(image_mat, converted,CV_RGBA2BGR);

It crashes at below line of code (when i display image )

imshow("img", converted);