Search code examples
c++opencvimage-processingneural-network

How train neural network in OpenCV on histograms


I want to train mlp in OpenCV to recognize if there is an specified object on an image.

The problem is as far as I know, constructors of Mat object (with which mlp operates) can use just simple variables types. So I can't use Mat of Mat, vector<Mat> or Mat of hists even despite the fact it consists of floats, I don't see the way to split the objects inside it, if I use the only one Mat object to collect all hists. Sorry if question is stupid.

P.S. I need to use mlp concrete, because Haar cascade is used already and alternative way is necessary to look of.


Solution

  • Mat trainingDataMat(600, 8, CV_32FC1, trainingData);

    Mat labelsMat(600, 1, CV_32SC1, labels);

    Ptr svm = SVM::create();

    svm->setType(SVM::C_SVC);

    svm->setKernel(SVM::LINEAR);

    svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));

    svm->train(trainingDataMat, ROW_SAMPLE, labelsMat);