OpenCV Error: Assertion failed (samples.cols == var_count && samples.type() == CV_32F) in cv::ml::SV
VS2019+OpenCV4.0
在完成分类器的训练,直接predict是没有问题的,但是保存xml文件后,再用以下的语句加载训练好的xml模型,predict出现了问题。
svm->save("svm.xml")
svm->load<SVM>("trained-svm.xml");
OpenCV Error: Assertion failed (samples.cols == var_count && samples.type() == CV_32F) in cv::ml::SV
在以下链接找到了解决办法。
https://answers.opencv.org/question/103031/opencv-31-c-svmload-does-not-set-var_count-correctly/
SVM::load() is a static function, which returns a new instance.
you have to use it like:
svm = Algorithm::load<SVM>("svm.xml");
改成以上语句后predict成功!
_________________________________________________________________________________________________________________________________________________
每一个不曾起舞的日子,都是对生命的辜负。
But it is the same with man as with the tree. The more he seeks to rise into the height and light, the more vigorously do his roots struggle earthward, downward, into the dark, the deep - into evil.
其实人跟树是一样的,越是向往高处的阳光,它的根就越要伸向黑暗的地底。----尼采
每一个不曾起舞的日子,都是对生命的辜负。
But it is the same with man as with the tree. The more he seeks to rise into the height and light, the more vigorously do his roots struggle earthward, downward, into the dark, the deep - into evil.
其实人跟树是一样的,越是向往高处的阳光,它的根就越要伸向黑暗的地底。----尼采