2012-04-06 25 views
0

私のプロジェクトスコープは、サンプル画像の特徴セットを比較することによって、紙幣識別です。サンプル画像の特徴抽出部分を完成しました。さらに私は、サンプル画像の機能をテキストファイルまたはXMLファイルに保存し、その分類を分類する必要があります。 OpenCvでSVMクラシファイアを使用して画像分類部分を手伝ってくださいOpenCvを使用した画像特徴分類のSVM

これは私が完成した特徴抽出コードです。

INTメイン(intargc、チャー** ARGV) {グレースケール等の画像をロード //

//declaring Mat object.This will holds an image(like iplimage in old opencv versions). 

Mat gray_scale_img; 


//imread is used to load an image. in here i have load the image as a grayscale image. 

gray_scale_img=imread("100.jpg",CV_LOAD_IMAGE_GRAYSCALE); 


/*surf detector settings*/ 

//setting the threshold value.high value will result low number of keypoints. 
int hessian=100; 

//initializing the surf keypoint detector 
SurfFeatureDetectordetector(hessian); 


/*detect surf key points*/ 


//creating vector to store detected keypoints 
std::vector<KeyPoint>keypoints; 

//detect keypoints 
detector.detect(gray_scale_img,keypoints); 


/*extract descriptor vectors/feature vectors from each and every keypoints */ 

SurfDescriptorExtractor extractor; 


//this mat object will goinf to hold the extracted descriptors. 
Mat descriptors; 

//extracting descriptors/features 
extractor.compute(gray_scale_img,keypoints,descriptors); 

}

OpenCVのに

答えて

1

SVMはCvSVMクラスに実装されています。

マトリクス(行単位)の形の特徴ベクトルを持つ必要があります。

次のようにあなたがあなたの特徴ベクトルとして、高さ、幅を使用していると仮定すると、あなたのマットは、(あなたが20個の特徴ベクトルを持っていると仮定した場合)になります。

Mat FV(20,2, CV_32F); 
Mat flagmat(20,1,CV_8U); 

/* 
code to populate the matrix FV. 

Fill the matrix with values so that it will look something as follows: 

20 30 
30 40 
.. 
.. 
code to populate the matrix flagmat. 
Fill the matrix with labels of each corresponding feature vector in matrix FV. It will look something as follows: 
1 
-1 
1 
1 
-1 
1 
1 
1 
.. 
*/ 

CvSVM svm; 

svm.train(datamat, flagmat,Mat(),Mat(),CvSVMParams()); 

Mat testFV(20,2,CV_32F); 
Mat sample(1,2,CV_32F); 

/* similarly as described above fill testFV matrix*/ 
float res;// to store result 
for(int i =0;i<testFV.rows;i++) 
{ 

    sample.at<float>(0,0)=testFV.at<float>(i,0); 
    sample.at<float>(0,1)=testFV.at<float>(i,1); 
    float res = svm.predict(sample); 
    cout<<"predicted label: "<<res<<endl; 
} 

私はあなたが機能から数値を抽出することができますと仮定しています記述子/ベクトルを生成し、上記のコードのサンプル行列に置きます。フィーチャベクタは、使用しているフィーチャディスクリプタで置き換えることができます。

+0

ソースコードを取得できますか? –

関連する問題