Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
Below code Is used to convert a OpenCV Mat image Into SFML image. How to convert SFML image back to Mat image?

C++
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
C++
sf::Texture texture;
sf::Event event;
sf::Sprite sprite;
texture.loadFromImage(image);
sprite.setTexture(texture);


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

C++
void* buffer = & image; 
        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 )

C++
imshow("img", converted);



c++ - How to create an image in opencv from a buffer that holds image in RGBA format - Stack Overflow

What I have tried:

I could only convert OpenCV Mat to SFML.
Posted
Updated 27-Sep-16 20:18pm
v4
Comments
Arthur V. Ratz 3-Dec-16 6:33am    
Probably, you cannot convert SFML to OpenCV Mat or so.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900