Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Thanks to LorenaGdL, I think I know the cause of the problem.

In the case of linear SVM, getSupportVectors() actually returns one "compressed" support vector that can be used in fast prediction. This method improves performance but have difficulty retrieving "uncompressed" support vectors. In the 3.1.0 version of OpenCV, this has been fixed by adding another function SVM::getUncompressedSupportVectors(), which returns all support vectors as a matrix.

One possible solution, as suggested by LorenaGdL, is to use a POLY type of kernel. The following code set a SVM to have POLY kernel.

svm->setKernel(SVM::POLY);
svm->setGamma(1);
svm->setCoef0(0);
svm->setDegree(1.0);

Thanks to LorenaGdL, I think I know the cause of the problem.

In the case of linear SVM, getSupportVectors() actually returns one "compressed" support vector that can be used in fast prediction. This method improves performance but have difficulty retrieving "uncompressed" support vectors. In the 3.1.0 version of OpenCV, this has been fixed by adding another function SVM::getUncompressedSupportVectors(), which returns all support vectors as a matrix.

One possible solution, as suggested by LorenaGdL, is to use a POLY type of kernel. The following code set a SVM to have a POLY kernel that behaves the same as a LINEAR kernel.

svm->setKernel(SVM::POLY);
svm->setGamma(1);
svm->setCoef0(0);
svm->setDegree(1.0);