i have a prob with my code..

#include "ml.h"
#include "highgui.h"
#include "cv.h"
#include <iostream.h>

//IplImage* img = new IplImage(mat);
//IplImage iplimg = mat; and just use &iplimg wherever you need an IplImage. There is no need for dynamic allocation

#define TRAIN_SAMPLE_COUNT 150
#define SIGMA 60

void main( int argc, char** argv )
{
	//Setup Matrices for TrainData set and Class Labels.
	//Most of OpenCV Machine Learning algorithms accept CV_32FC1 matrix format as their input/ouput
	CvMat* trainClass=cvCreateMat(TRAIN_SAMPLE_COUNT,1,CV_32FC1);
	CvMat* trainData=cvCreateMat(TRAIN_SAMPLE_COUNT,2,CV_32FC1);


	//IplImage* img = new IplImage(trainClass);

	//Creating a image to represent outputs
	IplImage* frame  = cvCreateImage(cvSize(500,500), IPL_DEPTH_8U, 3);
	//a vector to use for predicting data
	CvMat* sample=cvCreateMat(1,2,CV_32FC1);

	//Setting up Train Data
	CvMat subtrainData;
	cvGetRows(trainData,&subtrainData,0,TRAIN_SAMPLE_COUNT/3);

	CvMat trainData_col;
	cvGetCols(&subtrainData,&trainData_col,0,1);
	CvRNG rng_state = cvRNG(-1);
	cvRandArr(&rng_state,&trainData_col,CV_RAND_NORMAL,cvScalar(100),cvScalar(SIGMA));
	cvGetCols(&subtrainData,&trainData_col,1,2);
	cvRandArr(&rng_state,&trainData_col,CV_RAND_NORMAL,cvScalar(300),cvScalar(SIGMA));


	cvGetRows(trainData,&subtrainData,TRAIN_SAMPLE_COUNT/3,2*TRAIN_SAMPLE_COUNT/3);
	cvRandArr(&rng_state,&subtrainData,CV_RAND_NORMAL,cvScalar(400),cvScalar(SIGMA));

	cvGetRows(trainData,&subtrainData,2*TRAIN_SAMPLE_COUNT/3,TRAIN_SAMPLE_COUNT);

	cvGetCols(&subtrainData,&trainData_col,0,1);
	cvRandArr(&rng_state,&trainData_col,CV_RAND_NORMAL,cvScalar(300),cvScalar(SIGMA));
	cvGetCols(&subtrainData,&trainData_col,1,2);
	cvRandArr(&rng_state,&trainData_col,CV_RAND_NORMAL,cvScalar(100),cvScalar(SIGMA));

	//Setting up train classes
	CvMat subclassData;
	cvGetRows(trainClass,&subclassData,0,TRAIN_SAMPLE_COUNT/3);
	cvSet(&subclassData,cvScalar(1));
	cvGetRows(trainClass,&subclassData,TRAIN_SAMPLE_COUNT/3,2*TRAIN_SAMPLE_COUNT/3);
	cvSet(&subclassData,cvScalar(2));
	cvGetRows(trainClass,&subclassData,2*TRAIN_SAMPLE_COUNT/3,TRAIN_SAMPLE_COUNT);
	cvSet(&subclassData,cvScalar(3));
	//Setting up SVM parameters
	CvSVMParams params;
	params.kernel_type=CvSVM::LINEAR;
	params.svm_type=CvSVM::C_SVC;
	params.C=1;
	params.term_crit=cvTermCriteria(CV_TERMCRIT_ITER,100,0.000001);
	CvSVM svm;

	//Training the model
	bool res=svm.train(trainData,trainClass,cv::Mat(),cv::Mat(),params);

errors:
1)'cv' : is not a class or namespace name
2)'Mat' : undeclared identifier

Edited 4 Years Ago by Narue: added code tags

Well, what is cv::Mat() supposed to be?
Can you find it in the cv.h file?
...was it supposed to be your own CvMat instantiation (sublcassData)?

Well, what is cv::Mat() supposed to be?
Can you find it in the cv.h file?
...was it supposed to be your own CvMat instantiation (sublcassData)?

did u mean it Mat in the cv.h???
i can't find Mat in the cv.h...

Yes. You have the line:

bool res=svm.train(trainData,trainClass,cv::Mat(),cv::Mat(),params);

That is referencing a static method "cv::Mat()", but it's not defined in your code, so either it is in the .h file, or you're missing it somewhere.

This article has been dead for over six months. Start a new discussion instead.