Upload
czech0923
View
191
Download
1
Embed Size (px)
Citation preview
Opencv Visual Recognition利用訓練出來的分類器做影像辨識
訓練分類器產生 .xml 檔 – 事前準備 Opencv2.0 有內建的 .exe 檔可以建立分類器
createsamples.exe haartraining.exe
除了準備上述兩個 .exe 檔之外,還需要正負樣本 正樣本 : 需要分類出的物品,角度越多種為佳 負樣本 : 與正樣本相似性高為佳
訓練分類器產生 .xml 檔 – 步驟 存放正樣本 (positive) 的資料夾當中,需要有一個描述文件 .txt ,可利用 cmd 產生
先 cd 到資料夾位置: 輸入 dir /b /s >positives.txt 產生包含圖片資訊的 .txt 檔
訓練分類器產生 .xml 檔 – 步驟 打開產生的 .txt 檔
利用 ctrl+h 編輯檔案 刪除圖檔路徑 並在最後新增分類數據:
1 0 0 200 250 其中 200 250 是圖片大小
訓練分類器產生 .xml 檔 – 步驟 修改完後的 positive.txt 如圖:
還要記得把 positive.txt 檔刪掉 ( 如下 )
訓練分類器產生 .xml 檔 – 步驟 負樣本 negative 也是如此產生 negative.txt 檔,但不用新增數據,一樣要刪掉
negatives.txt 那的一行文字
訓練分類器產生 .xml 檔 – 步驟 接下來使用 opencv_createsample.exe 建立 sample , cmd 輸入 opencv_createsample.exe –info positive/positives.txt –vec data/positives.vec
–num 50 –w 20 –h 20 -info 是代表正樣本圖片位置 -vec 則是要輸出的 vec 檔 目前是設定輸出到 data 的資料夾中 -num 是圖片張數 -w 重設圖片寬度 -h 重設圖片高度
訓練分類器產生 .xml 檔 – 步驟 接下來輸入 opencv_haartraining.exe –data data/data –vec data/positives.vec
–bg negative/negatives.txt –mem 1024 –w 20 –h 20 -data 是等一下產生的檔案位置 目前設定是放在 data 資料夾的 data 資料夾中 ( 會自己產生 ) -vec 剛才在 createsample.exe 產生的 vec 的路徑 -bg 負樣本的位置,我們是放在 negative 資料夾中的 negatives.txt -mem 記憶體愈大可處理的檔案愈大 -w -h 寬度 高度 須和上一步驟設相同大小
訓練分類器產生 .xml 檔 – 步驟 接下來既可以在資料夾當中找到 data.xml .xml 就是訓練好的分類器
在 visual studio 上使用 .xml 檔 因為建立的檔案是 CPU 的正負樣本,找到的對應上去的特徵就會圈起來標示,下列為幾個測資產生的結果。