Why isn't my use of Super4PCS working?
XZRRRRRR opened this issue · 0 comments
Dear project author,
Hello! I hope this message finds you well. I have been using your provided library and I'm confident that I have installed it correctly along with the PCL library. However, when I tried to test it using the Stanford Bunny model, I found that Super4PCS is not functioning as expected. Do you have any insights or suggestions on what might be causing this issue?
Here is my specific environment:
Operating System: Windows 11
Compiler: Visual Studio 2022
PCL: 1.13.1
CMake Version: 3.27.0
And here is my source code:
`#include <Eigen/Core>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/common/time.h>
#include <pcl/console/print.h>
#include <pcl/features/fpfh_omp.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/io/obj_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include
#include
#include
#include <pcl/registration/super4pcs.h>
#include <gr/utils/shared.h>
// Types
typedef pcl::PointNormal PointNT;
typedef pcl::PointCloud PointCloudT;
typedef pcl::visualization::PointCloudColorHandlerCustom ColorHandlerT;
using namespace gr;
using loadfunc = std::function<int(const std::string&, pcl::PointCloud&)>;
const std::map<std::string, loadfunc> loaders =
{
{ "obj", pcl::io::loadOBJFile },
{ "ply", pcl::io::loadPLYFile },
{ "pcd", pcl::io::loadPCDFile }
};
std::string str_tolower(std::string s) {
std::transform(s.begin(), s.end(), s.begin(),
[](unsigned char c) { return std::tolower(c); } // correct
);
return s;
}
bool
load(const std::string& filename, PointCloudT::Ptr& pcloud) {
auto getFileExt = [](const std::string& s) -> std::string {
size_t i = s.rfind('.', s.length());
return i != std::string::npos
? str_tolower(s.substr(i + 1, s.length() - i))
: "";
};
std::string ext = getFileExt(filename);
auto l = loaders.find(ext);
if (l != loaders.end()) {
return (*l).second(filename, *pcloud) >= 0;
}
pcl::console::print_error("Unsupported file extension: %s\n", ext.c_str());
return false;
}
int main() {
// Point clouds
PointCloudT::Ptr object(new PointCloudT);
PointCloudT::Ptr object_aligned(new PointCloudT);
PointCloudT::Ptr scene(new PointCloudT);
PointCloudT::Ptr target(new PointCloudT);
std::string objPath = "D:\\Desktop\\bunny\\data\\bun000.ply";
std::string scenePath = "D:\\Desktop\\bunny\\data\\bun000.ply";
// Load object and scene
pcl::console::print_highlight("Loading point clouds...\n");
if (!(load(objPath, object) && load(scenePath, scene)))
{
pcl::console::print_error("Error loading object/scene file!\n");
return (-1);
}
Eigen::Matrix4f tras0 = Eigen::Matrix4f::Identity();
float theta = M_PI / 4;
tras0(0, 0) = cos(theta);
tras0(0, 2) = sin(theta);
tras0(2, 0) = -sin(theta);
tras0(2, 2) = cos(theta);
tras0(0, 3) = 2.5;
tras0(1, 3) = 0;
tras0(2, 3) = 5;
pcl::transformPointCloud(*scene, *target, tras0);
pcl::Super4PCS<PointNT, PointNT> align;
align.setInputSource(object);
align.setInputTarget(target);
align.setOverlap(0.5);
align.setDelta(0.08);
align.setMaxTimeSeconds(500);
align.align(*object_aligned);
if (align.hasConverged())
{
// Print results
printf("\n");
Eigen::Matrix4f transformation = align.getFinalTransformation();
pcl::console::print_info(" | %6.3f %6.3f %6.3f | \n", transformation(0, 0), transformation(0, 1), transformation(0, 2));
pcl::console::print_info("R = | %6.3f %6.3f %6.3f | \n", transformation(1, 0), transformation(1, 1), transformation(1, 2));
pcl::console::print_info(" | %6.3f %6.3f %6.3f | \n", transformation(2, 0), transformation(2, 1), transformation(2, 2));
pcl::console::print_info("\n");
pcl::console::print_info("t = < %0.3f, %0.3f, %0.3f >\n", transformation(0, 3), transformation(1, 3), transformation(2, 3));
pcl::console::print_info("\n");
// Show alignment
pcl::visualization::PCLVisualizer visu("Alignment - Super4PCS");
visu.addPointCloud(target, ColorHandlerT(target, 0.0, 255.0, 0.0), "scene");
visu.addPointCloud(object_aligned, ColorHandlerT(object_aligned, 0.0, 0.0, 255.0), "object_aligned");
visu.spin();
}
else
{
pcl::console::print_error("Alignment failed!\n");
return (-1);
}
return (0);
Do you have any insights or clues regarding this issue?