-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgDitis.h
87 lines (60 loc) · 2.53 KB
/
imgDitis.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*************************************************************************
> File Name: imgDitis.h
> Author: Xuxiansong
> Mail: 2808595125@163.com
> Created Time: 2017年07月19日 星期三 19时49分10秒
************************************************************************/
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/ml/ml.hpp>
#include <vector>
#include <string>
#include <dirent.h>
#pragma once
#define IMGDITIS_HOG_WINDOW_SIZE 80
#define IMGDITIS_HOG_BLOCK_SIZE 40
#define IMGDITIS_HOG_BLOCK_STRIDE 20
#define IMGDITIS_HOG_CELL_SIZE 20
#define IMGDITIS_HOG_BIN_COUNTS 9
// 28
// 14
// 7
// 7
// 9
#define IMGDITIS_SEG_IMG_WIDTH 80
#define IMGDITIS_SEG_IMG_HEIGHT 80
class ImgDitis{
public:
ImgDitis(const std::string& modelPath):mpHOG(NULL)
{
if(modelPath.empty()) std::cout<<" need trianning data>>>>>>>>>>>>>>\n";
msvmClassifier.load(modelPath.c_str());
//need to change param
mpHOG=new cv::HOGDescriptor(cv::Size(IMGDITIS_HOG_WINDOW_SIZE,IMGDITIS_HOG_WINDOW_SIZE), cv::Size(IMGDITIS_HOG_BLOCK_SIZE,IMGDITIS_HOG_BLOCK_SIZE),cv::Size(IMGDITIS_HOG_BLOCK_STRIDE,IMGDITIS_HOG_BLOCK_STRIDE), cv::Size(IMGDITIS_HOG_CELL_SIZE,IMGDITIS_HOG_CELL_SIZE),IMGDITIS_HOG_BIN_COUNTS);
}
~ImgDitis(){if(mpHOG)delete mpHOG;}
//main func
void img2NUMS(const cv::Mat& img, std::vector<int>& nums);
private:
int img2NUM(const cv::Mat& img, int& num);
void segmentNUM(const cv::Mat& img, std::vector<cv::Mat>& vnum_imgs);
cv::SVM msvmClassifier;
cv::HOGDescriptor *mpHOG;
};
class TrainningHOG{
public:
TrainningHOG(const std::string& saving_xml_file):msaving_files(saving_xml_file),mpHOG(NULL)
{
if(mpHOG==NULL)
mpHOG=new cv::HOGDescriptor(cv::Size(IMGDITIS_HOG_WINDOW_SIZE,IMGDITIS_HOG_WINDOW_SIZE), cv::Size(IMGDITIS_HOG_BLOCK_SIZE,IMGDITIS_HOG_BLOCK_SIZE),cv::Size(IMGDITIS_HOG_BLOCK_STRIDE,IMGDITIS_HOG_BLOCK_STRIDE), cv::Size(IMGDITIS_HOG_CELL_SIZE,IMGDITIS_HOG_CELL_SIZE),IMGDITIS_HOG_BIN_COUNTS);
}
~TrainningHOG(){if(mpHOG)delete mpHOG;}
void trainning(const std::vector<std::string>& trainningImags, const std::vector<int>& associ_nums);
private:
std::string msaving_files;
cv::HOGDescriptor *mpHOG;
};
//common func
void segment(const cv::Mat& im, std::vector<cv::Mat>& vnum_imgs);
typedef bool(*isYES)(const std::string& );
void taitsDir(std::string dir_path, std::vector<std::string>& vfull, isYES func= [](const std::string&)->bool{return 1;});