[vtkusers] From vtkImageData to Iplimage (OpenCV)
ignacioavellino at gmail.com
Wed Sep 12 10:18:23 EDT 2012
Solved, here comes the code:
vtkImageData* image = windowToImageFilter->GetOutput();
// Check number of components.
const int numComponents = image->GetNumberOfScalarComponents(); // 3
// Construct the OpenCv Mat
cv::Mat openCVImage(dims, dims, CV_8UC4, image->GetScalarPointer());
// Unsigned int, 4 channels
cvtColor(fingerOpenCVImage, fingerOpenCVImage, CV_BGRA2GRAY);
// Flip because of different origins between vtk and OpenCV
NOTE: I think vtk is giving me the image in BGRA, so I perform a conversion
from BGRA to GRAY. Doing it to RGB did not give me the expected results, but
since I just need a black and white image I did not did deeper.
If you need to keep colors, just figure out if vtk is storing the image in
RGBA, BGRA or how and transform into RGB.
Hop it helps :)
View this message in context: http://vtk.1045678.n5.nabble.com/From-vtkImageData-to-Iplimage-OpenCV-tp5716020p5716031.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers