今天实现了烟盒分类,效果一般。先把图片变成128*64,再用SVM+HOG,明天可以尝试先将烟盒变为二值图再分类。
//#include "stdafx.h"
#include "opencv2/opencv.hpp"
#include "windows.h"
#include "fstream"
#include <tchar.h>
using namespace std;
using namespace cv;
//思路:所有代训练的图片放在一个文件夹,生成一个txt文件,第一行是图片路径,第二行为图片类别
int _tmain(int argc, _TCHAR* argv[])
{
vector<string> img_path;//输入文件名变量
vector<int> img_catg;
int nLine = 0;
string buf;
ifstream svm_data( "C:\\Users\\liuliu\\Desktop\\train\\test.txt" );//训练样本图片的路径都写在这个txt文件中,使用bat批处理文件可以得到这个txt文件
unsigned long n;
while( svm_data )//将训练样本文件依次读取进来
{
if( getline( svm_data, buf ) ) //第一个参数表示输入流,第二个参数表示存放的字符串,第三个参数如果默认表示遇到回车就停止
{
nLine ++;
if( nLine % 2 == 0 )//注:奇数行是图片全路径,偶数行是标签
{