void CBATCHDlg::OnBnClickedButtonIdentify() { CCharsIdentify plate; string res_str = ""; for(vector<CString>::size_type v_i = 0; v_i < m_images.size(); ++v_i) { res_str += m_images[v_i]; res_str += " Result: "; string str = m_images[v_i].GetBuffer(0); Mat src = imread(str, 0); string str_cr = plate.charsIdentify(src, true); if ("" != str_cr) { res_str += str_cr; res_str += "\r\n"; } else { res_str += "No Answer\r\n"; } } m_res = res_str.c_str(); UpdateData(FALSE); CString filePath = this->m_savepath + "\\identify_chinese.txt"; std::ofstream resfile(filePath); resfile << res_str.c_str(); resfile.close(); }
void CBATCHDlg::OnBnClickedButtonRecogniseothers() { CCharsIdentify plate; string res_str = ""; int num_char = 0; for(vector<CString>::size_type v_i = 0; v_i < m_images.size(); ++v_i) { res_str += m_images[v_i]; res_str += " Result: "; 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); Mat src = imread(str, 0); Mat src_resize; src_resize.create(20, 20, 16); resize(src, src_resize, src_resize.size(), 0, 0, INTER_CUBIC); string str_cr = plate.charsIdentify(src_resize, false); if ("" != str_cr) { res_str += str_cr; res_str += "\r\n"; if(name[0] == str_cr[0]) ++num_char; } else { res_str += "No Answer\r\n"; } } res_str += "Char accuracy rate:"; char buffer[50]; sprintf(buffer,"%f\0",1.0 * num_char / m_images.size()); res_str += buffer; res_str += "\r\n"; m_res = res_str.c_str(); UpdateData(FALSE); CString filePath = this->m_savepath + "\\identify_others.txt"; std::ofstream resfile(filePath); resfile << res_str.c_str(); resfile.close(); }
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; }