Pergunta

I am visualizing data in VTK and I want to grab the framebuffer of the renderwindow and show it in an OpenCV application.

I am currently attempting this through:

void aig::VirtualScene::Mat(cv::Mat &m) {
  typedef unsigned char pixel;
  pixel *pixels = this->window_->GetRGBACharPixelData(0, 0, this->w_, this->h_, true);
  m = cv::Mat(this->h_, this->w_, CV_8UC4, pixels);
}

But I am ending up with a distorted image:

http://i.imgur.com/4nOxNzJ.png

(both upside down and slanted, which I assume is a step issue.

Is there an obvious error in this code? I know the upside down issue is because of the origin of the two data coordinates. Mostly interested in the slant issue.

Foi útil?

Solução

Looking at the definition of GetRGBACharPixelData:

virtual unsigned char *GetPixelData(int x,int y,int x2,int y2,int front);

You can see that it takes the index of the top-right angle (x2, y2), not the size of the subimage.

Hence what you want is:

pixel *pixels = this->window_->GetRGBACharPixelData(0, 0, this->w_ - 1, this->h_ - 1, true);
                                                                   ^^^^         ^^^^
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top