91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 37.36MB
    文件類型: .zip
    金幣: 1
    下載: 0 次
    發布日期: 2023-07-23
  • 語言: C/C++
  • 標簽:

資源簡介

這是opencv svm圖像分類的整個工程代碼,在VS2010下打開即可。整個工程文件以及我的所有訓練的圖片存放在這里,需要的可以下載,自己在找訓練圖片寫代碼花了很多時間,下載完后自行解壓,訓練圖片和測試圖片可以從這免費下載http://download.csdn.net/detail/always2015/8944959,project data文件夾直接放在D盤就行,里面存放訓練的圖片和待測試圖片,以及訓練過程中生成的中間文件,現在這個下載object_classfication_end則是工程文件,我用的是vs2010打開即可,下面工程里有幾個要注意的地方: 1、在這個模塊中使用到了c++的boost庫,但是在這里有一個版本的限制。這個模塊的代碼只能在boost版本1.46以上使用,這個版本以下的就不能用了,直接運行就會出錯,這是最需要注意的。因為在1.46版本以上中對比CsSVM這個類一些成員函數做了一些私有化的修改,所以在使用該類初始化對象時候需要注意。 2、我的模塊所使用到的函數和產生的中間結果都是在一個categorizer類中聲明的,由于不同的執行階段中間結果有很多個,例如:訓練圖片聚類后所得到單詞表矩陣,svm分類器的訓練的結果等,中間結果的產生是相當耗時的,所以在剛開始就考慮到第一次運行時候把他以文件XML的格式保存下來,下次使用到的時候在讀取。將一個矩陣存入文本的時候可以直接用輸出流的方式將一個矩陣存入,但是讀取時候如果用輸入流直接一個矩陣變量的形式讀取,那就肯定報錯,因為輸入流不支持直接對矩陣的操作,所以這時候只能對矩陣的元素一個一個進行讀取了。 3、在測試的時候,如果輸入的圖片太小,或者全為黑色,當經過特征提取和單詞構造完成使用svm進行分類時候會出現錯誤。經過調試代碼,發現上述圖片在生成該圖片的單詞的時候所得到的單詞矩陣會是一個空矩陣,即該矩陣的行列數都為0,所以在使用svm分類器時候就出錯。所以在使用每個輸入圖片的單詞矩陣的時候先做一個判斷,如果該矩陣行列數都為0,那么該圖片直接跳過。

資源截圖

代碼片段和文件信息

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//boost?庫
#include

#include“Config.h“

using?namespace?cv;
using?namespace?std;
//定義一個boost庫的命名空間
namespace?fs=boost::filesystem;
using?namespace?fs;


class?categorizer
{
private?:
//從類目名稱到數據的map映射
map?result_objects;
//存放所有訓練圖片的BOW
map?allsamples_bow;
//從類目名稱到訓練圖集的映射,關鍵字可以重復出現
multimap?train_set;
//?訓練得到的SVM
CvSVM?*stor_svms;
//類目名稱,也就是TRAIN_FOLDER設置的目錄名
vector?category_name;
//類目數目
int?categories_size;
//用SURF特征構造視覺詞庫的聚類數目
int?clusters;
//存放訓練圖片詞典
Mat?vocab;

//特征檢測器detectors與描述子提取器extractors???泛型句柄類Ptr
Ptr?featureDecter;
PtrriptorExtractor>?descriptorExtractor;

Ptr?bowtrainer;
PtrriptorExtractor>?bowDescriptorExtractor;
PtrsedMatcher>?descriptorMacher;

//構造訓練集合
void?make_train_set();
//?移除擴展名,用來講模板組織成類目
string?remove_extention(string);

public:
//構造函數
categorizer(int);
//?聚類得出詞典
void?bulid_vacab();
//構造BOW
void?compute_bow_image();
//訓練分類器
void?trainSvm();
//將測試圖片分類
void?category_By_svm();
};

//?移除擴展名,用來講模板組織成類目
string?categorizer::remove_extention(string?full_name)
{
//find_last_of找出字符最后一次出現的地方
int?last_index=full_name.find_last_of(“.“);
string?name=full_name.substr(0last_index);
return?name;
}

//?構造函數
categorizer::categorizer(int?_clusters)
{
cout<<“開始初始化...“< clusters=_clusters;
//初始化指針
featureDecter=new?SurfFeatureDetector();
descriptorExtractor=new?SurfDescriptorExtractor();

bowtrainer=new?BOWKMeansTrainer(clusters);
descriptorMacher=new?FlannbasedMatcher();
bowDescriptorExtractor=new?BOWImgDescriptorExtractor(descriptorExtractordescriptorMacher);

//boost庫文件?遍歷數據文件夾??directory_iterator(p)就是迭代器的起點,無參數的directory_iterator()就是迭代器的終點。
directory_iterator?begin_iter(TEMPLATE_FOLDER);
directory_iterator?end_iter;
//獲取該目錄下的所有文件名
for(;begin_iter!=end_iter;++begin_iter)
{
string?filename=string(TEMPLATE_FOLDER)+begin_iter->path().filename().string();
string?sub_category?=remove_extention(begin_iter->path().filename().string());
//讀入模板圖片
Mat?image=imread(filename);
Mat?templ_image;

//存儲原圖模板
result_objects[sub_category]=image;
}

cout<<“初始化完畢...“< //讀取訓練集
make_train_set();
}


//構造訓練集合
void?categorizer::make_train_set()
{
cout<<“讀取訓練集...“< string?categor;
//遞歸迭代rescursive?直接定義兩個迭代器:i為迭代起點(有參數),end_iter迭代終點
for(recursive_directory_iterator?i(TRAIN_FOLDER)end_iter;i!=end_iter;i++)
{
//?level?==?0即為目錄,因為TRAIN__FOLDER中設置如此
if(i.level()==0)
{
//?將類目名稱設置為目錄的名稱
categor=(i->path()).filename().string();
categor

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2015-07-28?09:34??object_classfication_end\
?????目錄???????????0??2015-07-28?09:34??object_classfication_end\Debug\
?????文件??????396800??2015-07-13?16:12??object_classfication_end\Debug\object_classfication_end.exe
?????文件?????2557804??2015-07-13?16:12??object_classfication_end\Debug\object_classfication_end.ilk
?????文件?????4606976??2015-07-13?16:12??object_classfication_end\Debug\object_classfication_end.pdb
?????目錄???????????0??2015-07-28?09:34??object_classfication_end\Release\
?????文件??????111616??2015-05-28?20:40??object_classfication_end\Release\object_classfication_end.exe
?????文件?????1338368??2015-05-28?20:40??object_classfication_end\Release\object_classfication_end.pdb
?????目錄???????????0??2015-07-28?09:34??object_classfication_end\ipch\
?????目錄???????????0??2015-07-28?09:34??object_classfication_end\ipch\object_classfication_end-11ed1bd5\
?????文件???122224640??2015-07-28?09:29??object_classfication_end\ipch\object_classfication_end-11ed1bd5\object_classfication_end-a7045f3b.ipch
?????目錄???????????0??2015-07-28?09:34??object_classfication_end\object_classfication_end\
?????文件?????????273??2015-07-13?16:12??object_classfication_end\object_classfication_end\Config.h
?????目錄???????????0??2015-07-28?09:34??object_classfication_end\object_classfication_end\Debug\
?????文件??????186452??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\CL.read.1.tlog
?????文件????????1616??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\CL.write.1.tlog
?????文件????????2354??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\cl.command.1.tlog
?????文件???????????2??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\link-cvtres.read.1.tlog
?????文件???????????2??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\link-cvtres.write.1.tlog
?????文件???????????2??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\link.1056-cvtres.read.1.tlog
?????文件???????????2??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\link.1056-cvtres.write.1.tlog
?????文件???????????2??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\link.1056.read.1.tlog
?????文件???????????2??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\link.1056.write.1.tlog
?????文件???????????2??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\link.1128-cvtres.read.1.tlog
?????文件???????????2??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\link.1128-cvtres.write.1.tlog
?????文件???????????2??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\link.1128.read.1.tlog
?????文件???????????2??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\link.1128.write.1.tlog
?????文件???????????2??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\link.1196-cvtres.read.1.tlog
?????文件???????????2??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\link.1196-cvtres.write.1.tlog
?????文件???????????2??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\link.1196.read.1.tlog
?????文件???????????2??2015-07-13?16:12??object_classfication_end\object_classfication_end\Debug\link.1196.write.1.tlog
............此處省略477個文件信息

評論

共有 條評論

相關資源