void CBATCHDlg::OnBnClickedButtonSegment() { _mkdir(m_savepath + "\\chinese"); _mkdir(m_savepath + "\\others"); CCharsSegment plate; for(vector<CString>::size_type v_i = 0; v_i < m_images.size(); ++v_i) { vector<Mat> resultVec; string str = m_images[v_i].GetBuffer(0); Mat src = imread(str, 1); int result = plate.charsSegment(src, resultVec); if (0 == result) { for (int j = 0; j < resultVec.size(); j++) { Mat resultMat = resultVec[j]; stringstream ss(stringstream::in | stringstream::out); if(0 == j) ss << m_savepath << "\\chinese\\" << v_i << "_segment" << j << ".jpg"; else ss << m_savepath << "\\others\\" << v_i << "_segment" << j << ".jpg"; imwrite(ss.str(), resultMat); } } } }
int test_chars_segment(const char*path) { cout << "test_chars_segment" << endl; char* chCurPath = getcwd(NULL, 0); vector<cv::Mat> matVec; vector<cv::Mat> resultVec; CPlateLocate plate; vector<string> fileVec; cv::Mat src; fileVec = BrowseFilenamesOneLayer(path, "*.jpg"); _chdir(chCurPath); cout << fileVec.size() << endl; int result; for (int i = 0; i < fileVec.size(); i++) { string fileName = fileVec[i]; string realName,realPath; int pos; pos = fileName.find_last_of("/"); realName = fileName.substr(pos + 1); ostringstream os; os << "resources/image/general_test_prLast3/" << realName ; realPath = os.str(); cv::Mat src = imread(fileName); vector<Mat> resultVec; CCharsSegment plate; //"general_test_prLast3" result = plate.charsSegment(src, resultVec); if (result == 0) { size_t num = resultVec.size(); if (num != 7) { cout << "Not PR: " << fileName << endl; continue; } _mkdir(realPath.c_str()); for (size_t j = 0; j < num; j++) { cv::Mat resultMat = resultVec[j]; char a[10]; itoa(j, a, 10); imwrite(realPath+"/" + a + ".jpg", resultMat); //imshow("plate_detect", resultMat.getPlateMat()); //waitKey(0); } //destroyWindow("plate_detect"); } } return result; }
int test_chars_identify() { cout << "test_chars_identify" << endl; Mat src = imread("image/chars_identify.jpg"); vector<Mat> resultVec; CCharsSegment cs; CCharsIdentify ci; string plateIdentify = ""; int result = cs.charsSegment(src, resultVec); if (result == 0) { int num = resultVec.size(); for (int j = 0; j < num; j++) { Mat resultMat = resultVec[j]; bool isChinses = false; bool isSpec = false; //默认首个字符块是中文字符 if (j == 0) isChinses = true; if (j == 1) isSpec = true; string charcater = ci.charsIdentify(resultMat, isChinses, isSpec); plateIdentify = plateIdentify + charcater; } } const string plateLicense = "苏E771H6"; cout << "plateLicense: " << plateLicense << endl; cout << "plateIdentify: " << plateIdentify << endl; if (plateLicense != plateIdentify) { cout << "Identify Not Correct!" << endl; return -1; } cout << "Identify Correct!" << endl; return result; }
int test_chars_segment() { cout << "test_chars_segment" << endl; Mat src = imread(img_chars_segment); vector<CPlate> resultVec; CPlateDetect pd; CCharsSegment cs; pd.setPDLifemode(true); int result = pd.plateDetectDeep(src, resultVec); if (result == 0) { int num = resultVec.size(); for (int j = 0; j < num; j++) { CPlate plate = resultVec[j]; imshow("plate_detect", plate.getPlateMat()); waitKey(0); vector<Mat> resultChars; int result_cs = cs.charsSegment(plate.getPlateMat(), resultChars); if (result_cs == 0) { int num_cs = resultChars.size(); for (int p = 0; p < num_cs; p++) { Mat resultChar = resultChars[p]; imshow("chars_segment", resultChar); waitKey(0); } destroyWindow("chars_segment"); } } destroyWindow("plate_detect"); } return result; }
int test_chars_segment() { cout << "test_chars_segment" << endl; Mat src = imread("image/chars_segment.jpg"); vector<Mat> resultVec; CCharsSegment plate; int result = plate.charsSegment(src, resultVec); if (result == 0) { int num = resultVec.size(); for (int j = 0; j < num; j++) { Mat resultMat = resultVec[j]; imshow("chars_segment", resultMat); waitKey(0); } } return result; }
void CBATCHDlg::OnBnClickedButtonSegment2() { string str_idx_sf[] = { "¼½","Ô¥","ÔÆ","ÁÉ","ºÚ", "Ïæ","Íî","³","ÐÂ","ËÕ","Õã","¸Ó","¶õ", "¹ð","¸Ê","½ú","ÃÉ","ÉÂ","¼ª","Ãö", "¹ó","ÔÁ","Çà","²Ø","´¨","Äþ","Çí", "Óå","¾©","½ò","»¦"}; string str_sf[] = { "zh_ji", /*¼½*/ "zh_yu", /*Ô¥*/ "zh_yun",/*ÔÆ*/ "zh_liao",/*ÁÉ*/ "zh_hei",/*ºÚ*/ "zh_xiang",/*Ïæ*/ "zh_wan",/*Íî*/ "zh_lu",/*³*/ "zh_xin",/*ÐÂ*/ "zh_su",/*ËÕ*/ "zh_zhe",/*Õã*/ "zh_gan",/*¸Ó*/ "zh_e",/*¶õ*/ "zh_gui",/*¹ð*/ "zh_gan2",/*¸Ê*/ "zh_sx",/*½ú*/ "zh_meng",/*ÃÉ*/ "zh_shan",/*ÉÂ*/ "zh_jl",/*¼ª*/ "zh_min",/*Ãö*/ "zh_gui2",/*¹ó*/ "zh_yue",/*ÔÁ*/ "zh_qing",/*Çà*/ "zh_zan",/*²Ø*/ "zh_cuan",/*´¨*/ "zh_ning",/*Äþ*/ "zh_qiong",/*Çí*/ "zh_yu2",/*Óå*/ "zh_jing",/*¾©*/ "zh_jin",/*½ò*/ "zh_hu"/*»¦*/ }; _mkdir(m_savepath + "\\charsChinese"); _mkdir(m_savepath + "\\chars2"); _mkdir(m_savepath + "\\allchars"); _mkdir(m_savepath + "\\allchinese"); int i; for(i = 0; i < 10; ++i) _mkdir(m_savepath + "\\chars2\\" + (char)(i + '0')); for(i = (int)'A'; i <= (int)'Z'; ++i) _mkdir(m_savepath + "\\chars2\\" + (char)i); for(i = 0; i < 31; ++i) _mkdir(m_savepath + "\\charsChinese\\" + str_sf[i].c_str()); CCharsSegment plate; for(vector<CString>::size_type v_i = 0; v_i < m_images.size(); ++v_i) { vector<Mat> resultVec; string str = m_images[v_i].GetBuffer(0); int index1 = str.find_last_of("\\"); int index2 = str.find_last_of("."); string name = str.substr(index1 + 1,index2 - index1 - 1); CString cstr = str.c_str(); Mat src = imread(str, 1); int result = plate.charsSegment2(src, resultVec); if (0 == result) { for (int j = 0; j < resultVec.size(); j++) { time_t rawtime; time ( &rawtime ); Mat resultMat = resultVec[j]; stringstream ss(stringstream::in | stringstream::out); stringstream ss2(stringstream::in | stringstream::out); if(0 == j) { string sf = name.substr(0, 2); for(i = 0; i < 31; ++i) { if(sf == str_idx_sf[i]) break; } ss << m_savepath << "\\charsChinese\\" << str_sf[i] << "\\" << str_sf[i] << "_" << v_i <<"_" << rawtime <<".jpg"; ss2 << m_savepath << "\\allchinese\\" << str_sf[i] << "_" << v_i <<"_" << rawtime <<".jpg"; } else { ss << m_savepath << "\\chars2\\" << name[j + 1] << "\\" << name[j + 1] << "_" << v_i << "_" << j << "_" << rawtime <<".jpg"; ss2 << m_savepath << "\\allchars\\" << name[j + 1] << "_" << v_i << "_" << j << "_" << rawtime <<".jpg"; } imwrite(ss.str(), resultMat); imwrite(ss2.str(), resultMat); } } } MessageBox("Finish."); }