Converting between VTK framebuffer and OpenCV Mat data

早过忘川 提交于 2019-12-01 21:42:15

问题


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:

(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.


回答1:


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);
                                                                   ^^^^         ^^^^


来源:https://stackoverflow.com/questions/22262199/converting-between-vtk-framebuffer-and-opencv-mat-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!