UnaNancyOwen
4/28/2016 - 3:03 PM

Convert Rendered Image to cv::Mat from pcl::visualization::PCLVisualizer

Convert Rendered Image to cv::Mat from pcl::visualization::PCLVisualizer

#include <pcl/visualization/pcl_visualizer.h>
#include <vtkRenderWindow.h>
#include <opencv2/opencv.hpp>

// Retrieve Rendered Image by pcl::visualization::PCLVisualizer
vtkSmartPointer<vtkRenderWindow> render = viewer->getRenderWindow();
std::unique_ptr<uchar> pixels( render->GetRGBACharPixelData( 0, 0, render->GetSize()[0] - 1, render->GetSize()[1] - 1, 1 ) );

// Rendered Image to cv::Mat
cv::Mat image = cv::Mat( render->GetSize()[1], render->GetSize()[0], CV_8UC4, &pixels.get()[0] );
cv::cvtColor( image, image, cv::COLOR_RGBA2BGRA );
cv::flip( image, image, 0 );