JNIEXPORT jbyteArray JNICALL Java_com_example_carplate_CarPlateDetection_ImageProc( JNIEnv *env, jclass obj, jstring imgpath, jstring svmpath, jstring annpath) { CPlateRecognize pr; // const string *img = (*env)->GetStringUTFChars(env, imgpath, 0); // const string *svm = (*env)->GetStringUTFChars(env, svmpath, 0); // const string *ann = (*env)->GetStringUTFChars(env, annpath, 0); char* img = jstring2str(env,imgpath); char* svm = jstring2str(env,svmpath); char* ann = jstring2str(env,annpath); Mat src = imread(img); pr.LoadSVM(svm); pr.LoadANN(ann); pr.setGaussianBlurSize(5); pr.setMorphSizeWidth(17); pr.setVerifyMin(3); pr.setVerifyMax(20); pr.setLiuDingSize(7); pr.setColorThreshold(150); vector < string > plateVec; int count = pr.plateRecognize(src, plateVec); string str = "0"; if (count == 0) { str = plateVec[0]; } char *result = new char[str.length() + 1]; strcpy(result, str.c_str()); jbyte *by = (jbyte*) result; jbyteArray jarray = env->NewByteArray(strlen(result)); env->SetByteArrayRegion(jarray, 0, strlen(result), by); return jarray; }
int test_plate_recognize() { cout << "test_plate_recognize" << endl; Mat src = imread("image/plate_locate.jpg"); //Mat src = imread("image/baidu_image/test6.jpg"); CPlateRecognize pr; pr.LoadANN("model/ann.xml"); pr.LoadSVM("model/svm.xml"); pr.setGaussianBlurSize(5); pr.setMorphSizeWidth(17); pr.setVerifyMin(3); pr.setVerifyMax(20); pr.setLiuDingSize(7); pr.setColorThreshold(150); vector<string> plateVec; int result = pr.plateRecognize(src, plateVec); if (result == 0) { int num = plateVec.size(); for (int j = 0; j < num; j++) { cout << "plateRecognize: " << plateVec[j] << endl; } } cout << "Enter 1 for coninue:"; int a = 0; cin >> a; return result; }
void CBATCHDlg::OnBnClickedButtonPlaterecognize2() { int i; CPlateRecognize pr; pr.LoadANN("model/ann.xml"); pr.LoadSVM("model/svm.xml"); //pr.setGaussianBlurSize(5); //pr.setMorphSizeWidth(17); //pr.setVerifyMin(3); //pr.setVerifyMax(20); //pr.setLiuDingSize(7); pr.setColorThreshold(150); stringstream ss(stringstream::in | stringstream::out); int num_char = 0; int num_plate = 0; for(vector<CString>::size_type v_i = 0; v_i < m_images.size(); ++v_i) { vector<string> plateVec; ss << m_images[v_i] << " Result: "; 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); Mat src = imread(str, 1); string str_cr; int result = pr.plateRecognize2(src, plateVec); int max_tmp; int num_tmp; if (result == 0) { num_tmp = 0; max_tmp = 0; for(i = 0; i < plateVec.size(); ++i) { num_tmp = 0; ss << " " << plateVec[i]; if(2 <= plateVec[i].size() && plateVec[i][0] == name[0]) ++num_tmp; for(int j = 2; j < plateVec[i].size() && j <= 8; ++j) { if(plateVec[i][j] == name[j]) ++num_tmp; } if(num_tmp > max_tmp) max_tmp = num_tmp; } if(max_tmp == 7) ++num_plate; num_char += max_tmp; ss << "\r\n"; } else { ss << "No Answer\r\n"; } } ss << "Char accuracy rate:" << (1.0 * num_char / (m_images.size() * 7)) << "\r\n"; ss << "Plate accuracy rate:" << (1.0 * num_plate / m_images.size()) << "\r\n"; m_res = ss.str().c_str(); UpdateData(FALSE); CString filePath = this->m_savepath + "\\plate_recognize.txt"; std::ofstream resfile(filePath); resfile << ss.str().c_str(); resfile.close(); }
void CBATCHDlg::OnBnClickedButtonPlaterecognize() { CPlateRecognize pr; pr.LoadANN("model/ann.xml"); pr.LoadSVM("model/svm.xml"); pr.setGaussianBlurSize(5); pr.setMorphSizeWidth(17); pr.setVerifyMin(3); pr.setVerifyMax(20); pr.setLiuDingSize(7); pr.setColorThreshold(150); string res_str = ""; int num_char = 0; for(vector<CString>::size_type v_i = 0; v_i < m_images.size(); ++v_i) { vector<string> plateVec; res_str += m_images[v_i]; res_str += " Result: "; 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); Mat src = imread(str, 1); string str_cr; int result = pr.plateRecognize(src, plateVec); if (result == 0) { for(int i = 0; i < plateVec.size(); ++i) { res_str += " "; res_str += plateVec[i]; for(int j = 2; j < plateVec[i].size() && j < 8; ++j) { if(plateVec[i][j] == name[j]) ++num_char; } } res_str += "\r\n"; } else { res_str += "No Answer\r\n"; } } res_str += "Char accuracy rate:"; res_str += (1.0 * num_char / (m_images.size() * 6)); res_str += "\r\n"; m_res = res_str.c_str(); UpdateData(FALSE); CString filePath = this->m_savepath + "\\plate_recognize.txt"; std::ofstream resfile(filePath); resfile << res_str.c_str(); resfile.close(); }