Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

undefined reference to cv::ml::SVM::create()

I was trying to use SVM and i wrote this short code:-

```

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include "opencv2/imgcodecs.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/ml.hpp>

using namespace cv;
//using namespace cv::ml;
int main(int, char**)
{
    // Data for visual representation
    int width = 512, height = 512;
    Mat image = Mat::zeros(height, width, CV_8UC3);
    // Set up training data
    int labels[4] = { 1, -1, -1, -1 };
    Mat labelsMat(4, 1, CV_32SC1, labels);
    float trainingData[4][2] = { { 501, 10 }, { 255, 10 }, { 501, 255 }, { 10, 501 } };
    Mat trainingDataMat(4, 2, CV_32FC1, trainingData);

    // Set up SVM's parameters
    Ptr<ml::SVM> svm = ml::SVM::create();

}

And my link libraries are:-

(../../opencv-3.4.1/build/lib/libopencv_core.so ) (/home/mithun/opencv-3.4.1/build/lib/libopencv_highgui.so) (/home/mithun/opencv-3.4.1/build/lib/libopencv_imgproc.so) (../../opencv-3.4.1/build/lib/libopencv_imgcodecs.so) (../../opencv-3.4.1/build/lib/libopencv_objdetect.so)

And I also have set the include directories correctly. But i get the error as shown in the heading. I might be missing some directory link. Can someone help?