Okay, I finally have the solution to this. It was just on thing that needed
changing. Since OpenCV creates BGR image, I needed to convert the BGR to RGB
using cv::cvtColor(imagebgr, imageRGB, CV_BGR2RGB) and then give it to
fromIpl2Vtk(...) function below. Just one other thing. Since VTK and OpenCV
use different origins for the image, I first did
cv::flip(origImage,flipImage, -1). I am sure some of you may have figured it
out... but I just wanted to document it.
bool fromIpl2Vtk( cv::Mat _src, vtkImageData* _dest )
{
assert( _src.data != NULL );
vtkImageImport *importer = vtkImageImport::New();
if ( _dest )
{
importer->SetOutput( _dest );
}
importer->SetDataSpacing( 1, 1, 1 );
importer->SetDataOrigin( 0, 0, 0 );
importer->SetWholeExtent( 0, _src.size().width-1, 0,
_src.size().height-1, 0, 0 );
importer->SetDataExtentToWholeExtent();
importer->SetDataScalarTypeToUnsignedChar();
importer->SetNumberOfScalarComponents( _src.channels() );
importer->SetImportVoidPointer( _src.data );
importer->Update();
return true;
}
hope it works...
Best regards,
Anant.
-----------
Anant S. Vemuri
Post by Anant VemuriI have also been trying to interface both Iplimage and vtkimagedata. Here
is what I did
void fromIpl2Vtk( IplImage* _src, vtkImageData* _dest )
{
vtkImageImport *importer = vtkImageImport::New();
if ( _dest )
{
importer->SetOutput( _dest );
}
importer->SetDataSpacing( 1, 1, 1 );
importer->SetDataOrigin( 0, 0, 0 );
importer->SetWholeExtent( 0, _src->width-1, 0, _src->height-1, 0,
_src->nChannels-1 );
importer->SetDataExtentToWholeExtent();
importer->SetDataScalarTypeToUnsignedChar();
importer->SetNumberOfScalarComponents( _src->nChannels );
importer->SetImportVoidPointer( _src->imageData );
importer->Update();
}
This works, but somehow vtk only recognizes the first channel that is
blue, which is the first channel of IplImage (BGR...BGR...) ... I was
wondering if anyone had any suggestions to fix this.
thanks.
Post by Samunda PereraDear all,
I have a pointer to a image stored in memory (example void* frame or
similar data type obtained from opencv) .
How to display this 2D image data as a image in VTK window?
Thanks & Regards,
Samu
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers