-
-
Save onauparc/00fb31abe92b8cb22a28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//in opencv/modules/viz/include/opencv2/viz/types.hpp | |
static Mesh load(InputArray pointCloud); | |
//in opencv/modules/viz/src/types.cpp | |
cv::viz::Mesh cv::viz::Mesh::load((InputArray pointCloud){ | |
vtkSmartPointer<vtkCloudMatSource> cloud_source = vtkSmartPointer<vtkCloudMatSource>::New(); | |
cloud_source->SetCloud(pointCloud); | |
cloud_source->Update(); | |
vtkSmartPointer<vtkPolyData> polydata = cloud_source->GetOutput(); | |
Mesh mesh; | |
// Now handle the polygons | |
vtkSmartPointer<vtkCellArray> polygons = polydata->GetPolys(); | |
mesh.polygons.create(1, polygons->GetSize(), CV_32SC1); | |
int* poly_ptr = mesh.polygons.ptr<int>(); | |
polygons->InitTraversal(); | |
vtkIdType nr_cell_points, *cell_points; | |
while (polygons->GetNextCell(nr_cell_points, cell_points)) | |
{ | |
*poly_ptr++ = nr_cell_points; | |
for (vtkIdType i = 0; i < nr_cell_points; ++i) | |
*poly_ptr++ = (int)cell_points[i]; | |
} | |
return mesh; | |
} | |
//in opencv_contrib/modules/structured_light/samples/dispTo3D.cpp | |
Mesh mesh = Mesh::load(pointCloud); //pointCloud è restituita da reproject3d | |
//Costruzione finestra per visualizzazione | |
viz::Viz3d myWindow("Coordinate Frame"); | |
//posizione della camera, dove guarda, dove è orientata | |
viz::makeCameraPose(Point3d(0,0,5), Point3d(0,0,0), Point3d(0,-1,0)); | |
/// Add coordinate axes | |
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem()); | |
myWindow.setBackgroundColor(viz::Color::gray()); | |
myWindow.spin(); | |
//WMesh da mesh | |
viz::WMesh mesh_widget(mesh); | |
mesh_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0); | |
myWindow.showWidget("point cloud", mesh_widget); | |
myWindow.spin(); | |
//prova ad aggiungere questo per vedere se si vede qualcosa | |
while(!myWindow.wasStopped()) | |
{ | |
} | |
//se non vedi niente togli il while e aggiungi questo che | |
//salva l'immagine di quello che mostra in filename (ovviamente cambia il filename con il path che preferisci) | |
string filename = "screenshot.png"; | |
myWindow.saveScreenshot(filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment