Ask Your Question
0

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

asked 2018-03-14 07:17:21 -0600

metal_turtle gravatar image

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-03-14 07:20:05 -0600

berak gravatar image

easy answer: -lopencv_ml is missing in you libraries list

edit flag offensive delete link more

Comments

Thanks a lot! I searched a lot of sites but they don't explain what libraries are needed.Another question: How would I know what libraries to add if this happens to another function or algorithm?

metal_turtle gravatar imagemetal_turtle ( 2018-03-14 07:26:19 -0600 )edit

if you include the ml header, you'll need the lib, too.

(same as you do for highguui, imgproc, etc. above already)

berak gravatar imageberak ( 2018-03-14 07:28:33 -0600 )edit

Oh yea thats right.

metal_turtle gravatar imagemetal_turtle ( 2018-03-14 07:42:10 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-03-14 07:17:21 -0600

Seen: 968 times

Last updated: Mar 14 '18