SVM in OpenCV: Visual Studio 2008 reported error wrongly (or is it right?)

狂风中的少年 提交于 2019-12-08 01:28:31

问题


I'm using MS Visual Studio 2008, OpenCV, C++ and SVM for a OCR-related project. At least I can run the code until yesterday, when I open the project to continue working, VS reported this error:

error C2664: 'bool CvSVM::train(const CvMat *,const CvMat *,const CvMat *,const CvMat *,CvSVMParams)' : cannot convert parameter 1 from 'cv::Mat' to 'const CvMat *'

It didn't happen before and I haven't changed any code relating to it (I only changed the parameters for the kernel).

The code got error is:

Mat curTrainData, curTrainLabel;
CvSVM svm;
.
.
.
svm.train(curTrainData, curTrainLabel, Mat(), Mat(), params);

If I hover on the code, I still got this tip: image.

Which means my syntax isn't wrong. So why do VS bother to report such an error?


回答1:


The problem is you're using Opencv c++ reference than c reference. I mean CvMat is of C part of Opencv, Whereas cv:: Mat which belongs to “cv” namespace is of c++ part. So my suggestion is convert it into required format. Here is a link to the opencv cheat sheet, just check out the first few lines of code. it will tell you how to do it. Convert from Mat to CvMat



来源:https://stackoverflow.com/questions/9809722/svm-in-opencv-visual-studio-2008-reported-error-wrongly-or-is-it-right

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!