#include <iostream>
//#include <stdio.h>
#include <fstream>
#include <iomanip>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
//#include <opencv2/ml/ml.hpp>
//#include <opencv2/features2d/features2d.hpp>
//#include <opencv2/objdetect.hpp>
//#include <opencv2/gpu/gpu.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/xobjdetect/xobjdetect.hpp>
using namespace std;
using namespace cv;
//FeatureEvaluator
int main()
{
/************************************************************************************
参数设置
*************************************************************************************/
//some parameters:
int positive_num = 1000;
int negative_num = 9000;
vector<String> v_positive_img;
vector<String> v_negative_img;
//先考虑训练0
int test_char = 0;
//正例、负例
string all_class_path = "C:\Users\cong\Desktop\研一实战\项目\图像中时间数字识别\OCR\result\";
string img_txt;
for (int i = 0; i < 10; i++)
{
//数字转字符
stringstream ss;
ss << i;
string test_char_str = ss.str();
img_txt = all_class_path + "result" + test_char_str + ".txt";
string path;
ifstream finPos(img_txt);
if (test_char == i)
{
//vector<Mat> channels; //用来装一幅图的N个通道;还没初始化
getline(finPos, path); //应该把文件中的图片个数也记录下来,由于该次的数据集,0~9个数一样,因此,可以考虑先不这么做
int img_num = 0; //把path,第一行字符变成数字,还没有完成
for (int j = 0; j<positive_num && getline(finPos, path); j++)
{
v_positive_img.push_back(path);
//cout << path<<endl;
}
}
else
{
//vector<Mat> channels; //用来装一幅图的N个通道;还没初始化
getline(finPos, path); //应该把文件中的图片个数也记录下来,由于该次的数据集,0~9个数一样,因此,可以考虑先不这么做
int img_num = 0; //把path,第一行字符变成数字,还没有完成
for (int j = 0; j<negative_num && getline(finPos, path); j++)
{
v_negative_img.push_back(path);
//cout << path << endl;
}
}
}
//训练:随机森林
//上述中正负样本的个数是否需要调整?
cv::xobjdetect::ICFDetectorParams myICFDetctorParams;
cv::xobjdetect::ICFDetector myICFDetector;
myICFDetector.train(v_positive_img, v_negative_img, myICFDetctorParams);
//测试,尺度问题呢?
//parameters
//Mat img_test = imread("C:\Users\cong\Desktop\研一实战\项目\图像中时间数字识别\OCR\one\3.jpg");
//vector<Rect> myRect;
//float scaleFactor;
//Size minSize;
//Size maxSize;
//float threshold;
//int slidingStep;
//vector<float> values;
//myICFDetector.detect(img_test, myRect, scaleFactor, 10, 50, threshold, slidingStep, values);
/*
C++: void ICFDetector::detect(const Mat& image, vector<Rect>& objects, float scaleFactor, Size minSize, Size maxSize, float threshold, int slidingStep, std::vector<float>& values)
C++: detect(const Mat& img, std::vector<Rect>& objects, float minScaleFactor, float maxScaleFactor, float factorStep, float threshold, int slidingStep, std::vector<float>& values)
Parameters:
image – image for detection
objects – output array of bounding boxes
scaleFactor – scale between layers in detection pyramid
minSize – min size of objects in pixels
maxSize – max size of objects in pixels
minScaleFactor – min factor by which the image will be resized
maxScaleFactor – max factor by which the image will be resized
factorStep – scaling factor is incremented each pyramid layer according to this parameter
slidingStep – sliding window step
values – output vector with values of positive samples
*/
return 0;
}