PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.89k stars 4.61k forks source link

error LNK2019: unresolved external symbol svm_free_model_content referenced in function "public: __cdecl pcl::SVMClassify::~SVMClassify(void)" (??1SVMClassify@pcl@@QEAA@XZ) #4694

Closed Yqy666 closed 2 years ago

Yqy666 commented 3 years ago

Describe the bug

Hi,Developers!I am working on a project that uses svm as a classifier for segmented objects from a Velodyne LIDAR。 But when I want to try to compile ,i get the following errors concerning the classifier:

error LNK2019: unresolved external symbol svm_destroy_param referenced in function "public: __cdecl pcl::SVM::~SVM(void)" (??1SVM@pcl@@QEAA@XZ) error LNK2019: unresolved external symbol svm_free_model_content referenced in function "public: __cdecl pcl::SVMClassify::~SVMClassify(void)" (??1SVMClassify@pcl@@QEAA@XZ)

Context

I have modified the files svm.h and svm_wrapper.h in my local code according to https://github.com/PointCloudLibrary/pcl/issues/1726

Current Behavior

The IDE still gave an error to LNK2019

To Reproduce

`#include

include

include <Eigen/Core>

include "pcl/point_types.h"

include "pcl/point_cloud.h"

include "pcl/io/pcd_io.h"

include <pcl/search/kdtree.h>

include <pcl/features/normal_3d_omp.h>

include <pcl/filters/voxel_grid.h>

include <pcl/features/vfh.h>

include <pcl/visualization/pcl_plotter.h>

include <pcl/ml/svm_wrapper.h>

int number(142); pcl::SVMParam param; int nrfold(0);

void downsample(pcl::PointCloudpcl::PointXYZ::Ptr &points, float leaf_size, pcl::PointCloudpcl::PointXYZ::Ptr &downsampled_out) { pcl::VoxelGridpcl::PointXYZ vox_grid; vox_grid.setLeafSize(leaf_size, leaf_size, leaf_size); vox_grid.setInputCloud(points); vox_grid.filter(*downsampled_out); }

void compute_surface_normals(pcl::PointCloudpcl::PointXYZ::Ptr &points, float normal_radius, pcl::PointCloudpcl::Normal::Ptr &normals_out) { pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> norm_est;

// Use a KdTree to perform neighborhood searches norm_est.setSearchMethod(pcl::search::KdTree::Ptr(new pcl::search::KdTree));

// Specify the size of the local neighborhood to use when computing the surface normals norm_est.setRadiusSearch(normal_radius);

// Set the input points norm_est.setInputCloud(points);

// Estimate the surface normals and store the result in "normals_out" norm_est.compute(*normals_out); }

void compute_VFH_features(pcl::PointCloudpcl::PointXYZ::Ptr &points, pcl::PointCloudpcl::Normal::Ptr &normals, pcl::PointCloudpcl::VFHSignature308::Ptr &descriptors_out) {

pcl::VFHEstimation<pcl::PointXYZ, pcl::Normal, pcl::VFHSignature308> vfh_est;

vfh_est.setInputCloud(points); vfh_est.setInputNormals(normals); vfh_est.setSearchMethod(pcl::search::KdTree::Ptr(new pcl::search::KdTree));

vfh_est.setNormalizeBins(true); // Also, we can normalize the SDC with the maximum size found between // the centroid and any of the cluster's points. vfh_est.setNormalizeDistance(false);

// std::cout << "start compute VFH features descriptors" << std::endl;

vfh_est.compute(*descriptors_out); // std::cout << "Compute VFH descriptors successfully" << std::endl; }

/* Function : output the .txt file for Libsvm use/ void write2file(pcl::PointCloudpcl::VFHSignature308::Ptr &descriptors_vfh, const int count) { if (count == 0) { ofstream outFile("VFH_svm_features.txt"); if (!outFile) { printf("Error opening output file: %s!\n", "VFH_svm_features.txt"); exit(1); } for (size_t j = 0; j < descriptors_vfh->size(); j++) { outFile << "0 "; for (int q = 0; q < 308; q++) { outFile << (q + 1) << ":" << descriptors_vfh->at(j).histogram[q] << " "; } } outFile << std::endl; } else { ofstream ofresult("VFH_svm_features.txt", ios::app); for (size_t k = 0; k < descriptors_vfh->size(); k++) { ofresult << count << " "; for (int p = 0; p < 308; p++) { ofresult << (p + 1) << ":" << descriptorsvfh->at(k).histogram[p] << " "; } } ofresult << std::endl; if (count == number) ofresult.close(); } }

void write2svmdata(pcl::PointCloudpcl::VFHSignature308::Ptr &descriptors_vfh, const int count, std::vectorpcl::SVMData &trainning_set) { std::vectorpcl::SVMDataPoint svm_set; for (size_t j = 0; j < descriptors_vfh->size(); j++) { for (int q = 0; q < 308; q++) { pcl::SVMDataPoint svm_point; svm_point.idx = int(q + 1); svm_point.value = descriptors_vfh->at(j).histogram[q]; svm_set.push_back(svm_point); } } pcl::SVMData svm_data; svm_data.label = count; svm_data.SV = svm_set; trainning_set.push_back(svm_data); }

int main() { const char *modelFileName = "person_svm";

std::vector tranningdataset; for (int i = 0; i < (number + 1); i++) { pcl::PointCloud::Ptr points1(new pcl::PointCloud); pcl::PointCloud::Ptr downsampled1(new pcl::PointCloud); pcl::PointCloud::Ptr normals1(new pcl::PointCloud); pcl::PointCloud::Ptr descriptors_vfh1(new pcl::PointCloud);

std::stringstream ss0;
std::stringstream ss1, ss2;
//C://Users//QYQY//Desktop//np
ss1 << "C://Users//QYQY//Desktop//np//pedestrian" << i << ".pcd";
pcl::io::loadPCDFile(ss1.str(), *points1);
const float voxel_grid_leaf_size1 = 4.0;
downsample(points1, voxel_grid_leaf_size1, downsampled1);
const float normal_radius1 = 4.5;
compute_surface_normals(downsampled1, normal_radius1, normals1);

compute_VFH_features(downsampled1, normals1, descriptors_vfh1);

std::cout << "write features of model No." << i << std::endl;
// Store the VF histogram into the txt for libsvm input
write2svmdata(descriptors_vfh1, i, tranning_dataset);

} std::cout << "All the SVM datas have been created" << std::endl;

// SVM trainning pcl::SVMTrain Mytrainner; Mytrainner.setParameters(param_); Mytrainner.resetTrainingSet(); Mytrainner.setInputTrainingSet(tranning_dataset); Mytrainner.trainClassifier(); Mytrainner.saveClassifierModel(modelFileName); std::cout << "Output trainning model : " << modelFileName << std::endl; return (0);`

Your Environment (please complete the following information):

Possible Solution

Not obligatory, but suggest a fix/reason for the bug. Feel free to create a PR if you feel comfortable.

Additional context

Add any other context about the problem here.

RollingIsland commented 2 years ago

I also got this problem. I checked the pcl_ml.lib by using "dumpbin -header" in vs commandline, and didn't find the svm symbols. So perhaps for the allinone package the svm is not compiled. I found a easy solution is to download and add "svm.cpp" and "svm_wrapper.cpp" directly in your own project. So they will be treated as your own code and won't have a link error.

Yqy666 commented 2 years ago

Yeah, I later found that the reason for the problem was the lack of relevant documents of SVM. After I added them, the problem had been solved, but I forgot to reply the solution to the problem here at that time. As six to seven months have passed, if it weren't for your reply, I might have forgotten this problem. In a word, thank you for your reply. Thank you very much!