资源简介

基于opencv的视觉词袋训练程序,用来提取图片的视觉词典

资源截图

代码片段和文件信息

#include
#include 


#include 

using namespace cv;
using namespace std;

int main()
{
string tr_img_path = “D:\\image\\train\\“;
int tr_img_num = 200;

Mat tr_image;
vector tr_img_keypoints;

Mat tr_descriptor;

for (int i=1; i<=tr_img_num;i++)
{
char temp[10];
_itoa(i temp 10);
string tr_img_index(temp);
string tr_img_name = tr_img_path + “image“ + tr_img_index + “.jpg“;

tr_image = imread(tr_img_name 0);

CV_Assert(!tr_image.empty() && tr_image.depth() == CV_8U);


Mat descriptor;

//initModule_nonfree();
SIFT mySift(400);
mySift(tr_image Mat()tr_img_keypointsdescriptor);

cout<<“The feature extraction for ----- image “ << tr_img_index<<“ ----- has done!“<
/*ofstream test;
test.open(“d:\\text.txt“);
for (int j=0; jriptor.rows; j++)
{
for (int k=0; kriptor.cols; k++)
{
test<riptor.at(j k)<<“  “;
}
test< }
test.close();*/

tr_descriptor.push_back(descriptor);
}

cout< cout<<“The total number of the descriptors for the training set is “<riptor.rows< cout<<“The dimension of the descriptors for the training set is “<riptor.cols<
cout< cout<<“Start training visual words......“<
BOWKMeansTrainer myBOW(100);
Mat VisualWords;

VisualWords = myBOW.cluster(tr_descriptor);

cout<<“Visual words training finish!“<
FileStorage fs;
fs.open(“VisualWords.xml“ FileStorage::WRITE);
cout<<“1“<
fs<<“VisualWords“< cout<<“2“<
fs.release();

cout<<“Successfully saved to the VisualWords.xml!“<


return 0;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      60416  2016-11-16 14:40  1\TestBagofFeatures\Debug\TestBagofFeatures.exe

     文件     634716  2016-11-16 14:40  1\TestBagofFeatures\Debug\TestBagofFeatures.ilk

     文件    1526784  2016-11-16 14:40  1\TestBagofFeatures\Debug\TestBagofFeatures.pdb

     文件       7310  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures\Debug\BuildLog.htm

     文件     186060  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures\Debug\main.obj

     文件         69  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures\Debug\mt.dep

     文件        663  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures\Debug\TestBagofFeatures.exe.embed.manifest

     文件        728  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures\Debug\TestBagofFeatures.exe.embed.manifest.res

     文件        621  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures\Debug\TestBagofFeatures.exe.intermediate.manifest

     文件     691200  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures\Debug\vc90.idb

     文件     978944  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures\Debug\vc90.pdb

     文件       1806  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures\main.cpp

     文件       4099  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures\TestBagofFeatures.vcproj

     文件       1427  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures\TestBagofFeatures.vcproj.7136780DB741428.Administrator.user

     文件       1413  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures\TestBagofFeatures.vcproj.apple-PC.hadoop1.user

     文件     220768  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures\VisualWords.xml

     文件    1166336  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures.ncb

     文件        917  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures.sln

    ..A..H.      9728  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures.suo

     文件        766  2016-11-16 14:40  1\TestBagofFeatures\使用说明请参看右侧注释===〉〉.txt

     目录          0  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures\Debug

     目录          0  2016-11-16 14:40  1\TestBagofFeatures\Debug

     目录          0  2016-11-16 14:40  1\TestBagofFeatures\TestBagofFeatures

     目录          0  2016-11-16 14:40  1\TestBagofFeatures

     目录          0  2016-11-16 14:40  1

----------- ---------  ---------- -----  ----

              5494771                    25


评论

共有 条评论