有没有一种方法可以将OpenCV mat格式化为SFML图像?或者还有其他方法在SFML窗口中显示mat吗? 我尝试将mat数组转换为uchar数组,但结果是黑屏。
cv::VideoCapture cap(0); // open the video file for reading
sf::Event event;
sf::Image image;
sf::Texture texture;
sf::Sprite sprite;
sprite.setTexture(texture);
cv::Mat frame;
sf::RenderWindow window(sf::VideoMode(1200, 900),"my Window");
cap >> frame;
uchar* camData = new uchar[frame.total()*4];
cv::Mat continuousRGBA(frame.size(), CV_8UC4, camData);
cv::cvtColor(frame, continuousRGBA, CV_BGR2RGBA, 4);
image.create(frame.cols,frame.rows,camData);
texture.loadFromImage(image);
while (window.isOpen()){
cap >> frame;
cv::cvtColor(frame, continuousRGBA, CV_BGR2RGBA, 4);
image.create(frame.cols,frame.rows,camData);
texture.loadFromImage(image);
while (window.pollEvent(event)){
if (event.type == sf::Event::Closed)
window.close();
}
window.draw(sprite);
window.display();
}