问题
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