diff --git a/modules/viz/include/opencv2/viz.hpp b/modules/viz/include/opencv2/viz.hpp index a532ba783..bf44a2c03 100644 --- a/modules/viz/include/opencv2/viz.hpp +++ b/modules/viz/include/opencv2/viz.hpp @@ -99,8 +99,7 @@ namespace cv CV_EXPORTS Mat readCloud (const String& file, OutputArray colors = noArray(), OutputArray normals = noArray()); /////////////////////////////////////////////////////////////////////////////////////////////// - /// Reads mesh. Only ply format is supported now. The function tries to read texture from png-file, - /// and in case of faulure, just leaves the texture field empty. + /// Reads mesh. Only ply format is supported now and no texture load support CV_EXPORTS Mesh readMesh(const String& file); diff --git a/modules/viz/include/opencv2/viz/types.hpp b/modules/viz/include/opencv2/viz/types.hpp index cdd89d3a0..e61c837be 100644 --- a/modules/viz/include/opencv2/viz/types.hpp +++ b/modules/viz/include/opencv2/viz/types.hpp @@ -115,7 +115,7 @@ namespace cv Mat texture, tcoords; - //! Loads mesh from a given ply file + //! Loads mesh from a given ply file (no texture load support for now) static Mesh load(const String& file); }; diff --git a/modules/viz/src/types.cpp b/modules/viz/src/types.cpp index bf61432cb..2e32a6327 100644 --- a/modules/viz/src/types.cpp +++ b/modules/viz/src/types.cpp @@ -73,7 +73,6 @@ cv::viz::Mesh cv::viz::Mesh::load(const String& file) sink->Write(); // Now handle the polygons - vtkSmartPointer polygons = polydata->GetPolys(); mesh.polygons.create(1, polygons->GetSize(), CV_32SC1); int* poly_ptr = mesh.polygons.ptr(); @@ -87,25 +86,6 @@ cv::viz::Mesh cv::viz::Mesh::load(const String& file) *poly_ptr++ = (int)cell_points[i]; } - String::size_type pos = file.find_last_of('.'); - String png = (pos == String::npos) ? file : file.substr(0, pos+1) + "png"; - - vtkSmartPointer png_reader = vtkSmartPointer::New(); - - if (png_reader->CanReadFile(png.c_str())) - { - png_reader->SetFileName(png.c_str()); - png_reader->Update(); - vtkSmartPointer imagedata = png_reader->GetOutput(); - - Size sz(imagedata->GetDimensions()[0], imagedata->GetDimensions()[1]); - int channels = imagedata->GetNumberOfScalarComponents(); - CV_Assert(imagedata->GetScalarType() == VTK_UNSIGNED_CHAR); - - void *ptr = imagedata->GetScalarPointer(0,0,0); - Mat(sz, CV_8UC(channels), ptr).copyTo(mesh.texture); - } - return mesh; } diff --git a/modules/viz/test/test_viz3d.cpp b/modules/viz/test/test_viz3d.cpp index 66ec25db8..bdfda6d9b 100644 --- a/modules/viz/test/test_viz3d.cpp +++ b/modules/viz/test/test_viz3d.cpp @@ -47,19 +47,11 @@ TEST(Viz_viz3d, develop) { cv::Mat cloud = cv::viz::readCloud(get_dragon_ply_file_path()); - //cv::viz::Mesh3d mesh = cv::viz::Mesh3d::load(get_dragon_ply_file_path()); - //theRNG().fill(mesh.colors, RNG::UNIFORM, 0, 255); - cv::viz::Viz3d viz("abc"); viz.setBackgroundMeshLab(); viz.showWidget("coo", cv::viz::WCoordinateSystem(1)); - //viz.showWidget("cloud", cv::viz::WPaintedCloud(cloud, Vec3d(0.0, 0.0, -1.0), Vec3d(0.0, 0.0, 1.0))); - //viz.showWidget("cloud", cv::viz::WPaintedCloud(cloud, Vec3d(0.0, 0.0, -1.0), Vec3d(0.0, 0.0, 1.0), cv::viz::Color::green(), cv::viz::Color::red())); viz.showWidget("cloud", cv::viz::WPaintedCloud(cloud)); - //viz.showWidget("h", cv::viz::Widget::fromPlyFile("d:/horse-red.ply")); - //viz.showWidget("a", cv::viz::WArrow(cv::Point3f(0,0,0), cv::Point3f(1,1,1))); - //---->>>>> //std::vector gt, es; //cv::viz::readTrajectory(gt, "d:/Datasets/trajs/gt%05d.xml"); @@ -67,12 +59,5 @@ TEST(Viz_viz3d, develop) //cv::Mat cloud = cv::viz::readCloud(get_dragon_ply_file_path()); //---->>>>> - //theRNG().fill(colors, cv::RNG::UNIFORM, 0, 255); - //viz.showWidget("c", cv::viz::WCloud(cloud, colors)); - //viz.showWidget("c", cv::viz::WCloud(cloud, cv::viz::Color::bluberry())); - - //viz.showWidget("l", cv::viz::WLine(Point3f(0,0,0), Point3f(1,1,1))); - //viz.showWidget("s", cv::viz::WSphere(Point3f(0,0,0), 1)); - //viz.showWidget("d", cv::viz::WCircle(Point3f(0,0,0), 1)); viz.spin(); } diff --git a/modules/viz/test/tests_simple.cpp b/modules/viz/test/tests_simple.cpp index 7f91c899b..ec475580e 100644 --- a/modules/viz/test/tests_simple.cpp +++ b/modules/viz/test/tests_simple.cpp @@ -145,6 +145,42 @@ TEST(Viz, show_mesh_random_colors) viz.spin(); } +TEST(Viz, show_textured_mesh) +{ + Mat lena = imread(Path::combine(cvtest::TS::ptr()->get_data_path(), "lena.png")); + + std::vector points; + std::vector tcoords; + std::vector polygons; + for(size_t i = 0; i < 64; ++i) + { + double angle = CV_PI/2 * i/64.0; + points.push_back(Vec3d(0.00, cos(angle), sin(angle))*0.75); + points.push_back(Vec3d(1.57, cos(angle), sin(angle))*0.75); + tcoords.push_back(Vec2d(0.0, i/64.0)); + tcoords.push_back(Vec2d(1.0, i/64.0)); + } + + for(size_t i = 0; i < points.size()/2-1; ++i) + { + int polys[] = {3, 2*i, 2*i+1, 2*i+2, 3, 2*i+1, 2*i+2, 2*i+3}; + polygons.insert(polygons.end(), polys, polys + sizeof(polys)/sizeof(polys[0])); + } + + cv::viz::Mesh mesh; + mesh.cloud = Mat(points, true).reshape(3, 1); + mesh.tcoords = Mat(tcoords, true).reshape(2, 1); + mesh.polygons = Mat(polygons, true).reshape(1, 1); + mesh.texture = lena; + + Viz3d viz("show_textured_mesh"); + viz.setBackgroundMeshLab(); + viz.showWidget("coosys", WCoordinateSystem()); + viz.showWidget("mesh", WMesh(mesh)); + viz.setRenderingProperty("mesh", SHADING, SHADING_PHONG); + viz.spin(); +} + TEST(Viz, show_polyline) { Mat polyline(1, 32, CV_64FC3);