fixing some appveyor CI errors, added test to check dictionary serialization against all type

This commit is contained in:
matlabbe
2025-12-23 09:52:21 -08:00
parent f7cb330e31
commit 837b08a4f3
3 changed files with 142 additions and 45 deletions
+4 -4
View File
@@ -284,7 +284,7 @@ TEST(Util3DRegistration, icpIdentityTransformConverges)
auto cloud_source = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>()); auto cloud_source = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
for (float i = 0; i < 5; ++i) for (float i = 0; i < 5; ++i)
{ {
cloud_source->emplace_back(i, i * 2.0f, 0.0f); cloud_source->push_back(pcl::PointXYZ(i, i * 2.0f, 0.0f));
} }
auto cloud_target = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>()); auto cloud_target = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
@@ -313,7 +313,7 @@ TEST(Util3DRegistration, icpTranslatedTransformConverges)
auto cloud_source = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>()); auto cloud_source = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>());
for (float i = 0; i < 5; ++i) for (float i = 0; i < 5; ++i)
{ {
cloud_source->emplace_back(i, i * 2.0f, 0); cloud_source->push_back(pcl::PointXYZ(i, i * 2.0f, 0));
} }
// Translate the cloud // Translate the cloud
@@ -348,7 +348,7 @@ TEST(Util3DRegistration, icp2DAlignsFlatClouds)
for (float y = 0; y < 5; ++y) for (float y = 0; y < 5; ++y)
{ {
if(y == 0 || y == 2 || y == 4 || x==0 || x==2 || x== 4){ if(y == 0 || y == 2 || y == 4 || x==0 || x==2 || x== 4){
cloud_source->emplace_back(x*0.05, y*0.05, (int)x%2==0?0.01:-0.01); cloud_source->push_back(pcl::PointXYZ(x*0.05, y*0.05, (int)x%2==0?0.01:-0.01));
} }
} }
} }
@@ -382,7 +382,7 @@ TEST(Util3DRegistration, icpPointToPlaneAlignsTranslatedPlane)
{ {
for (float y = -0.5f; y <= 0.5f; y += 0.1f) for (float y = -0.5f; y <= 0.5f; y += 0.1f)
{ {
cloud_source_raw->emplace_back(x, y, int(x*10)%2==0&&int(y*10)%2==0?0.01:-0.01); cloud_source_raw->push_back(pcl::PointXYZ(x, y, int(x*10)%2==0&&int(y*10)%2==0?0.01:-0.01));
} }
} }
+24
View File
@@ -35,21 +35,33 @@ TEST(Util3dSurface, computeNormalsComplexityVaryingNormals3D)
EXPECT_NEAR(complexity, 0.0f, 1e-3); EXPECT_NEAR(complexity, 0.0f, 1e-3);
pcl::PointCloud<pcl::PointNormal> cloudA; pcl::PointCloud<pcl::PointNormal> cloudA;
#if PCL_VERSION_COMPARE(>=, 1, 10, 0)
pcl::concatenate(floor, wallA, cloudA); pcl::concatenate(floor, wallA, cloudA);
#else
pcl::concatenatePointCloud(floor, wallA, cloudA);
#endif
// Two perpendicular surfaces // Two perpendicular surfaces
complexity = util3d::computeNormalsComplexity(cloudA); complexity = util3d::computeNormalsComplexity(cloudA);
EXPECT_NEAR(complexity, 0.0f, 1e-3); EXPECT_NEAR(complexity, 0.0f, 1e-3);
// Three perpendicular surfaces // Three perpendicular surfaces
pcl::PointCloud<pcl::PointNormal> cloudB; pcl::PointCloud<pcl::PointNormal> cloudB;
#if PCL_VERSION_COMPARE(>=, 1, 10, 0)
pcl::concatenate(cloudA, wallB, cloudB); pcl::concatenate(cloudA, wallB, cloudB);
#else
pcl::concatenatePointCloud(cloudA, wallB, cloudB);
#endif
complexity = util3d::computeNormalsComplexity(cloudB); complexity = util3d::computeNormalsComplexity(cloudB);
EXPECT_NEAR(complexity, 0.25f, 1e-3); EXPECT_NEAR(complexity, 0.25f, 1e-3);
// Three perpendicular surfaces (one small) // Three perpendicular surfaces (one small)
pcl::PointCloud<pcl::PointNormal> smallCloudB; pcl::PointCloud<pcl::PointNormal> smallCloudB;
#if PCL_VERSION_COMPARE(>=, 1, 10, 0)
pcl::concatenate(cloudA, smallWallB, smallCloudB); pcl::concatenate(cloudA, smallWallB, smallCloudB);
#else
pcl::concatenatePointCloud(cloudA, smallWallB, smallCloudB);
#endif
complexity = util3d::computeNormalsComplexity(smallCloudB); complexity = util3d::computeNormalsComplexity(smallCloudB);
EXPECT_LT(complexity, 0.25f); EXPECT_LT(complexity, 0.25f);
@@ -96,20 +108,32 @@ TEST(Util3dSurface, computeNormalsComplexityVaryingNormals2D)
EXPECT_NEAR(complexity, 0.0f, 1e-3); EXPECT_NEAR(complexity, 0.0f, 1e-3);
pcl::PointCloud<pcl::PointNormal> cloud; pcl::PointCloud<pcl::PointNormal> cloud;
#if PCL_VERSION_COMPARE(>=, 1, 10, 0)
pcl::concatenate(wallA, wallB, cloud); pcl::concatenate(wallA, wallB, cloud);
#else
pcl::concatenatePointCloud(wallA, wallB, cloud);
#endif
// Two perpendicular surfaces // Two perpendicular surfaces
complexity = util3d::computeNormalsComplexity(cloud, Transform(), true); complexity = util3d::computeNormalsComplexity(cloud, Transform(), true);
EXPECT_NEAR(complexity, 0.25f, 1e-3); EXPECT_NEAR(complexity, 0.25f, 1e-3);
pcl::PointCloud<pcl::PointNormal> cloudB; pcl::PointCloud<pcl::PointNormal> cloudB;
#if PCL_VERSION_COMPARE(>=, 1, 10, 0)
pcl::concatenate(wallA, smalllWallB, cloudB); pcl::concatenate(wallA, smalllWallB, cloudB);
#else
pcl::concatenatePointCloud(wallA, smalllWallB, cloudB);
#endif
// Two perpendicular surfaces (one small) // Two perpendicular surfaces (one small)
complexity = util3d::computeNormalsComplexity(cloudB, Transform(), true); complexity = util3d::computeNormalsComplexity(cloudB, Transform(), true);
EXPECT_LT(complexity, 0.25f); EXPECT_LT(complexity, 0.25f);
EXPECT_GT(complexity, 0.01f); EXPECT_GT(complexity, 0.01f);
pcl::PointCloud<pcl::PointNormal> corridorLikeCloud; pcl::PointCloud<pcl::PointNormal> corridorLikeCloud;
#if PCL_VERSION_COMPARE(>=, 1, 10, 0)
pcl::concatenate(wallA, negWallA, corridorLikeCloud); pcl::concatenate(wallA, negWallA, corridorLikeCloud);
#else
pcl::concatenatePointCloud(wallA, negWallA, corridorLikeCloud);
#endif
// Two parallel surfaces simulating a corridor // Two parallel surfaces simulating a corridor
cv::Mat vector,values; cv::Mat vector,values;
complexity = util3d::computeNormalsComplexity(corridorLikeCloud, Transform(), true, &vector, &values); complexity = util3d::computeNormalsComplexity(corridorLikeCloud, Transform(), true, &vector, &values);
+114 -41
View File
@@ -621,53 +621,126 @@ TEST_F(VWDictionaryTest, MemoryUsed)
TEST_F(VWDictionaryTest, SerializeDeserializeIndex) TEST_F(VWDictionaryTest, SerializeDeserializeIndex)
{ {
// Add words and build index // Test with all NNStrategy values
cv::Mat descriptors(5, 32, CV_32F); VWDictionary::NNStrategy strategies[] = {
cv::randu(descriptors, cv::Scalar(0), cv::Scalar(1)); VWDictionary::kNNFlannNaive,
dict->addNewWords(descriptors, 1); VWDictionary::kNNFlannKdTree,
dict->update(); VWDictionary::kNNFlannLSH,
VWDictionary::kNNBruteForce,
// Serialize VWDictionary::kNNBruteForceGPU
std::vector<unsigned char> data = dict->serializeIndex(); };
EXPECT_GT(data.size(), 0u);
// Create new dictionary and deserialize
VWDictionary dict2;
cv::Mat descriptors2(5, 32, CV_32F);
cv::randu(descriptors2, cv::Scalar(0), cv::Scalar(1));
dict2.addNewWords(descriptors2, 1);
// Deserialize should fail because we are not using the same descriptors
bool success = dict2.deserializeIndex(data);
EXPECT_FALSE(success);
success = dict2.deserializeIndex(data.data(), data.size());
EXPECT_FALSE(success);
// Same descriptors for(VWDictionary::NNStrategy strategy : strategies)
VWDictionary dict3; {
dict3.addNewWords(descriptors, 1); // Reset dictionary for each strategy
success = dict3.deserializeIndex(data); dict->clear();
EXPECT_TRUE(success); dict->setNNStrategy(strategy);
// Index should be loaded if(strategy == VWDictionary::kNNBruteForceGPU)
EXPECT_GT(dict3.getIndexedWordsCount(), 0u); {
#if CV_MAJOR_VERSION < 3
#ifdef HAVE_OPENCV_GPU
if(!cv::gpu::getCudaEnabledDeviceCount())
{
continue; // Skip if no GPU available
}
#else
continue; // Skip if GPU support not compiled
#endif
#else
#ifdef HAVE_OPENCV_CUDAFEATURES2D
if(!cv::cuda::getCudaEnabledDeviceCount())
{
continue; // Skip if no GPU available
}
#else
continue; // Skip if GPU support not compiled
#endif
#endif
}
// Should fail if index is already built // Add words and build index
success = dict3.deserializeIndex(data); cv::Mat descriptors(5, 32, CV_32F);
EXPECT_FALSE(success); cv::randu(descriptors, cv::Scalar(0), cv::Scalar(1));
// Convert to binary if using LSH strategy
if(strategy == VWDictionary::kNNFlannLSH)
{
// Convert float descriptors to binary
descriptors = VWDictionary::convert32FToBin(descriptors, true);
}
dict->addNewWords(descriptors, 1);
dict->update();
// Serialize
std::vector<unsigned char> data = dict->serializeIndex();
if(strategy < VWDictionary::kNNBruteForce)
{
// flann strategies
EXPECT_GT(data.size(), 0u) << "Strategy: " << VWDictionary::nnStrategyName(strategy);
}
else {
EXPECT_EQ(data.size(), 0u) << "Strategy: " << VWDictionary::nnStrategyName(strategy);
}
// Create new dictionary and deserialize
VWDictionary dict2;
dict2.setNNStrategy(strategy);
cv::Mat descriptors2(5, 32, CV_32F);
cv::randu(descriptors2, cv::Scalar(0), cv::Scalar(1));
// Convert to binary if using LSH strategy
if(strategy == VWDictionary::kNNFlannLSH)
{
descriptors2 = VWDictionary::convert32FToBin(descriptors2, true);
}
dict2.addNewWords(descriptors2, 1);
// Deserialize should fail because we are not using the same descriptors
bool success = dict2.deserializeIndex(data);
EXPECT_FALSE(success) << "Strategy: " << VWDictionary::nnStrategyName(strategy);
success = dict2.deserializeIndex(data.data(), data.size());
EXPECT_FALSE(success) << "Strategy: " << VWDictionary::nnStrategyName(strategy);
// raw bytes // Same descriptors
VWDictionary dict4; VWDictionary dict3;
dict4.addNewWords(descriptors, 1); dict3.setNNStrategy(strategy);
success = dict4.deserializeIndex(data.data(), data.size()); dict3.addNewWords(descriptors, 1);
EXPECT_TRUE(success); success = dict3.deserializeIndex(data);
if(strategy < VWDictionary::kNNBruteForce)
{
// flann strategies
EXPECT_TRUE(success) << "Strategy: " << VWDictionary::nnStrategyName(strategy);
// Index should be loaded // Index should be loaded
EXPECT_GT(dict4.getIndexedWordsCount(), 0u); EXPECT_GT(dict3.getIndexedWordsCount(), 0u) << "Strategy: " << VWDictionary::nnStrategyName(strategy);
}
else
{
EXPECT_FALSE(success) << "Strategy: " << VWDictionary::nnStrategyName(strategy);
continue;
}
// Should fail if index is already built // Should fail if index is already built
success = dict4.deserializeIndex(data.data(), data.size()); success = dict3.deserializeIndex(data);
EXPECT_FALSE(success); EXPECT_FALSE(success) << "Strategy: " << VWDictionary::nnStrategyName(strategy);
// raw bytes
VWDictionary dict4;
dict4.setNNStrategy(strategy);
dict4.addNewWords(descriptors, 1);
success = dict4.deserializeIndex(data.data(), data.size());
EXPECT_TRUE(success) << "Strategy: " << VWDictionary::nnStrategyName(strategy);
// Index should be loaded
EXPECT_GT(dict4.getIndexedWordsCount(), 0u) << "Strategy: " << VWDictionary::nnStrategyName(strategy);
// Should fail if index is already built
success = dict4.deserializeIndex(data.data(), data.size());
EXPECT_FALSE(success) << "Strategy: " << VWDictionary::nnStrategyName(strategy);
}
} }
TEST_F(VWDictionaryTest, IsModified) TEST_F(VWDictionaryTest, IsModified)