在VTK帧缓冲区和OpenCV Mat数据之间转换 [英] Converting between VTK framebuffer and OpenCV Mat data
问题描述
我正在VTK中可视化数据,我想获取渲染窗口的帧缓冲区并将其显示在OpenCV应用程序中.
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:
(上下颠倒,我认为这是一个 step 问题.
(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.
推荐答案
查看GetRGBACharPixelData
的定义:
virtual unsigned char *GetPixelData(int x,int y,int x2,int y2,int front);
您会看到它采用的是右上角的索引(x2,y2),而不是子图像的 size .
You can see that it takes the index of the top-right angle (x2, y2), not the size of the subimage.
因此,您想要的是:
pixel *pixels = this->window_->GetRGBACharPixelData(0, 0, this->w_ - 1, this->h_ - 1, true);
^^^^ ^^^^
这篇关于在VTK帧缓冲区和OpenCV Mat数据之间转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!