小编jof*_*fra的帖子

将cv :: Mat转换为SDL_Texture

我正在尝试使用SDL播放视频.为此,我使用opencv加载视频,并获取帧.然后我只需要将这些帧转换为我需要它们,SDL_Texture*然后我就可以在屏幕上绘制它们了.

这是我的问题,我将它转换为a SDL_Surface*然后转换SDL_Texture为失败,我不知道为什么.这是我的代码:

void Cutscene::play()
{
  this->onLoop();
  this->onRender();

  while(!frameMat.empty())
  {
    this->onLoop();
    this->onRender();
  }
}

void Cutscene::onLoop()
{
  video >> frameMat;

  convertCV_MatToSDL_Texture();
}

void Cutscene::onRender()
{
  Image::onDraw(GameEngine::getInstance()->getRenderer(), frameTexture);

}

void Cutscene::convertCV_MatToSDL_Texture()
{
  IplImage opencvimg2 = (IplImage)frameMat;
  IplImage* opencvimg = &opencvimg2;

  //Convert to SDL_Surface
  frameSurface = SDL_CreateRGBSurfaceFrom((void*)opencvimg->imageData,
                         opencvimg->width, opencvimg->height,
                         opencvimg->depth*opencvimg->nChannels,
                         opencvimg->widthStep,
                         0xff0000, 0x00ff00, 0x0000ff, 0);

  if(frameSurface == NULL)
  {
    SDL_Log("Couldn't convert Mat to Surface.");
    return;
  }

  //Convert to SDL_Texture
  frameTexture = SDL_CreateTextureFromSurface(
                    GameEngine::getInstance()->getRenderer(), frameSurface);
  if(frameTexture == NULL) …
Run Code Online (Sandbox Code Playgroud)

c++ video opencv sdl-2

3
推荐指数
1
解决办法
1667
查看次数

标签 统计

c++ ×1

opencv ×1

sdl-2 ×1

video ×1