mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge pull request #24961 from savuor:rv/ply_mesh
PLY mesh support #24961 **Warning:** The PR changes exising API. Fixes #24960 Connected PR: [#1145@extra](https://github.com/opencv/opencv_extra/pull/1145) ### Changes * Adds faces loading from and saving to PLY files * Fixes incorrect PLY loading (see issue) * Adds per-vertex color loading / saving ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
committed by
GitHub
parent
466ad96b1d
commit
f96111ef05
@@ -132,14 +132,14 @@ TEST(PointCloud, LoadSaveMeshObj)
|
||||
auto folder = cvtest::TS::ptr()->get_data_path();
|
||||
std::string new_path = tempfile("new_mesh.obj");
|
||||
|
||||
cv::loadMesh(folder + "pointcloudio/orig.obj", points, normals, indices);
|
||||
cv::saveMesh(new_path, points, normals, indices);
|
||||
cv::loadMesh(folder + "pointcloudio/orig.obj", points, indices, normals);
|
||||
cv::saveMesh(new_path, points, indices, normals);
|
||||
|
||||
std::vector<cv::Point3f> points_gold;
|
||||
std::vector<cv::Point3f> normals_gold;
|
||||
std::vector<std::vector<int32_t>> indices_gold;
|
||||
|
||||
cv::loadMesh(new_path, points_gold, normals_gold, indices_gold);
|
||||
cv::loadMesh(new_path, points_gold, indices_gold, normals_gold);
|
||||
|
||||
EXPECT_EQ(normals_gold, normals);
|
||||
EXPECT_EQ(points_gold, points);
|
||||
@@ -148,29 +148,44 @@ TEST(PointCloud, LoadSaveMeshObj)
|
||||
std::remove(new_path.c_str());
|
||||
}
|
||||
|
||||
TEST(PointCloud, LoadSaveMeshPly)
|
||||
typedef std::string PlyTestParamsType;
|
||||
typedef testing::TestWithParam<PlyTestParamsType> PlyTest;
|
||||
|
||||
TEST_P(PlyTest, LoadSaveMesh)
|
||||
{
|
||||
std::vector<cv::Point3f> points;
|
||||
std::vector<cv::Point3f> normals;
|
||||
std::vector<std::vector<int32_t>> indices;
|
||||
std::string fname = GetParam();
|
||||
|
||||
std::vector<cv::Point3f> points_gold, normals_gold, colors_gold;
|
||||
std::vector<std::vector<int32_t>> indices_gold;
|
||||
|
||||
auto folder = cvtest::TS::ptr()->get_data_path();
|
||||
std::string new_path = tempfile("new_mesh.ply");
|
||||
|
||||
// we don't support meshes in PLY format right now but it should exit silently
|
||||
cv::loadMesh(folder + "pointcloudio/orig.ply", points, normals, indices);
|
||||
EXPECT_TRUE(points.empty());
|
||||
EXPECT_TRUE(normals.empty());
|
||||
EXPECT_TRUE(indices.empty());
|
||||
cv::loadMesh(folder + fname, points_gold, indices_gold, normals_gold, colors_gold);
|
||||
EXPECT_FALSE(points_gold.empty());
|
||||
EXPECT_FALSE(indices_gold.empty());
|
||||
|
||||
cv::saveMesh(new_path, points, normals, indices);
|
||||
EXPECT_TRUE(points.empty());
|
||||
EXPECT_TRUE(normals.empty());
|
||||
EXPECT_TRUE(indices.empty());
|
||||
cv::saveMesh(new_path, points_gold, indices_gold, normals_gold, colors_gold);
|
||||
|
||||
std::vector<cv::Point3f> points, normals, colors;
|
||||
std::vector<std::vector<int32_t>> indices;
|
||||
cv::loadMesh(new_path, points, indices, normals, colors);
|
||||
|
||||
if (!normals.empty())
|
||||
{
|
||||
EXPECT_LE(cv::norm(normals_gold, normals, NORM_INF), 0);
|
||||
}
|
||||
EXPECT_LE(cv::norm(points_gold, points, NORM_INF), 0);
|
||||
EXPECT_LE(cv::norm(colors_gold, colors, NORM_INF), 0);
|
||||
EXPECT_EQ(indices_gold, indices);
|
||||
std::remove(new_path.c_str());
|
||||
}
|
||||
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(PointCloud, PlyTest,
|
||||
::testing::Values("pointcloudio/orig.ply", "pointcloudio/orig_ascii_fidx.ply", "pointcloudio/orig_bin_fidx.ply",
|
||||
"pointcloudio/orig_ascii_vidx.ply", "pointcloudio/orig_bin.ply", "viz/dragon.ply"));
|
||||
|
||||
TEST(PointCloud, NonexistentFile)
|
||||
{
|
||||
std::vector<cv::Point3f> points;
|
||||
|
||||
Reference in New Issue
Block a user