Reputation: 413
I am attempting to bridge between VTK (3D visualization library) and OpenCV (image processing library).
Currently, I am doing the following:
vtkWindowToImageFilter
converts vtkRenderWindow
(scene) into vtkImageData
(pixels of render window).
I then have to copy each pixel of vtkImageData
into a cv::Mat
for processing and display with OpenCV.
This process needs to run in real time, so the redundant copy (scene pixels into ImageData
into Mat
) severely impacts performance. I would like to map directly from scene pixels to cv::Mat
.
As the scene changes, I would like the cv::Mat
to automatically reference the scene. Essentially, I would like a cv::Mat<uchar *>
, rather than a cv::Mat<uchar>
. Does that make sense? Or am I overcomplicating it?
Upvotes: 1
Views: 267
Reputation: 11
vtkSmartPointer<vtkImageData> image = vtkSmartPointer<vtkImageData>::New();
int dims[3];
image->GetImageData()->GetDimensions(dims);
cv::Mat matImage(cv::Size(dims[0], dims[1]), CV_8UC3, image->GetImageData()->GetScalarPointer());`
I succeeded implementing vtkimagedata*
directly into cv::Mat
pointer array..
some functions such as
cv::flip
or matImage -= cv::Scalar(255,0,0)
directly working on vtkimagedata.
but functions like cv::resize
or cv::Canny
doesn't work.
Upvotes: 1