|
@@ -24,14 +24,160 @@ jstring str2jstring(JNIEnv *env, const char *pat)
|
|
|
return env->NewStringUTF(pat);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+extern "C"
|
|
|
+JNIEXPORT jstring JNICALL
|
|
|
+Java_com_example_paperidentify_IdentifyNative_preIdentify__Ljava_lang_String_2ILjava_lang_StringBuffer_2Ljava_util_HashMap_2Ljava_lang_String_2(
|
|
|
+ JNIEnv *env, jclass clazz, jstring str_img_path, jint n_school_id, jobject str_card_id,
|
|
|
+ jobject papers_map, jstring str_ip) {
|
|
|
+// clock_t stratTime = clock();
|
|
|
+ const char * imgPath = env->GetStringUTFChars(str_img_path, 0);
|
|
|
+ const char * ipAddress = env->GetStringUTFChars(str_ip, 0);
|
|
|
+ int nSchoolId = n_school_id;
|
|
|
+ paperPreIdentify tIdentify(nSchoolId);
|
|
|
+ PAPERIDENTIFYSTATUS eStatus = tIdentify.scanPaper(imgPath, ipAddress);
|
|
|
+ env->ReleaseStringUTFChars(str_img_path, imgPath);
|
|
|
+ env->ReleaseStringUTFChars(str_ip, ipAddress);
|
|
|
+ std::string strRet = std::to_string(eStatus);
|
|
|
+
|
|
|
+ //将异常数据存入容器
|
|
|
+ std::map<PaperAbnormalType, std::vector<PaperPage>> resMap = tIdentify.getAbnPapers();
|
|
|
+ std::map<PaperAbnormalType, std::vector<PaperPage>>::iterator iter = resMap.begin();
|
|
|
+ for(; iter != resMap.end(); iter++)
|
|
|
+ {
|
|
|
+ int nKey = iter->first;
|
|
|
+ jclass integerClass = env->FindClass("java/lang/Integer");
|
|
|
+ jmethodID integerConstructorID = env->GetMethodID(integerClass, "<init>", "(I)V");
|
|
|
+ jobject key = env->NewObject(integerClass, integerConstructorID, nKey);
|
|
|
+ std::vector<PaperPage> paperVec = iter->second;
|
|
|
+ int nPaperSize = paperVec.size();
|
|
|
+ jclass mapClass = env->FindClass("java/util/HashMap");
|
|
|
+ jmethodID putMethodID =
|
|
|
+ env->GetMethodID(
|
|
|
+ mapClass,
|
|
|
+ "put",
|
|
|
+ "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;" );
|
|
|
+
|
|
|
+ jclass arrayListClass = env->FindClass("java/util/ArrayList");
|
|
|
+ jmethodID arrayListInit = env->GetMethodID(arrayListClass, "<init>", "()V");
|
|
|
+ jmethodID addToList = env->GetMethodID(
|
|
|
+ arrayListClass,
|
|
|
+ "add",
|
|
|
+ "(Ljava/lang/Object;)Z" );
|
|
|
+ jobject listObj = env->NewObject(arrayListClass, arrayListInit);
|
|
|
+ for(int i = 0; i < nPaperSize; i++)
|
|
|
+ {
|
|
|
+ PaperPage tPage = paperVec.at(i);
|
|
|
+ jstring firstPage = str2jstring(env, tPage.firstPage.c_str());
|
|
|
+ jstring secondPage = str2jstring(env, tPage.secondPage.c_str());
|
|
|
+ env->CallBooleanMethod(listObj, addToList, firstPage);
|
|
|
+ env->CallBooleanMethod(listObj, addToList, secondPage);
|
|
|
+ env->DeleteLocalRef(firstPage);
|
|
|
+ env->DeleteLocalRef(secondPage);
|
|
|
+ }
|
|
|
+ env->CallObjectMethod(papers_map, putMethodID, key, listObj);
|
|
|
+ //资源释放
|
|
|
+ env->DeleteLocalRef(integerClass);
|
|
|
+ env->DeleteLocalRef(key);
|
|
|
+ env->DeleteLocalRef(mapClass);
|
|
|
+ env->DeleteLocalRef(arrayListClass);
|
|
|
+ env->DeleteLocalRef(listObj);
|
|
|
+ }
|
|
|
+ std::string strCardId = tIdentify.getPaperCardId();
|
|
|
+ jstring strPaperId = str2jstring(env, strCardId.c_str());
|
|
|
+ jclass stringBufferClass = env->FindClass("java/lang/StringBuffer");
|
|
|
+ jmethodID appendMethodID =
|
|
|
+ env->GetMethodID(
|
|
|
+ stringBufferClass,
|
|
|
+ "append",
|
|
|
+ "(Ljava/lang/Object;)Ljava/lang/StringBuffer;" );
|
|
|
+ env->CallObjectMethod(str_card_id, appendMethodID, strPaperId);
|
|
|
+ env->DeleteLocalRef(strPaperId);
|
|
|
+ env->DeleteLocalRef(stringBufferClass);
|
|
|
+
|
|
|
+// clock_t endTime = clock();
|
|
|
+// double exAustTime = (endTime - stratTime) / CLOCKS_PER_SEC;
|
|
|
+ return str2jstring(env, strRet.c_str());
|
|
|
+}
|
|
|
+
|
|
|
+extern "C"
|
|
|
+JNIEXPORT jstring JNICALL
|
|
|
+Java_com_example_paperidentify_IdentifyNative_preIdentify__Ljava_lang_String_2ILjava_lang_StringBuffer_2Ljava_util_HashMap_2(
|
|
|
+ JNIEnv *env, jclass clazz, jstring str_img_path, jint n_school_id, jobject str_card_id,
|
|
|
+ jobject papers_map) {
|
|
|
+// clock_t stratTime = clock();
|
|
|
+ const char * imgPath = env->GetStringUTFChars(str_img_path, 0);
|
|
|
+ int nSchoolId = n_school_id;
|
|
|
+ paperPreIdentify tIdentify(nSchoolId);
|
|
|
+ PAPERIDENTIFYSTATUS eStatus = tIdentify.scanPaper(imgPath);
|
|
|
+ env->ReleaseStringUTFChars(str_img_path, imgPath);
|
|
|
+ std::string strRet = std::to_string(eStatus);
|
|
|
+
|
|
|
+ //将异常数据存入容器
|
|
|
+ std::map<PaperAbnormalType, std::vector<PaperPage>> resMap = tIdentify.getAbnPapers();
|
|
|
+ std::map<PaperAbnormalType, std::vector<PaperPage>>::iterator iter = resMap.begin();
|
|
|
+ for(; iter != resMap.end(); iter++)
|
|
|
+ {
|
|
|
+ int nKey = iter->first;
|
|
|
+ jclass integerClass = env->FindClass("java/lang/Integer");
|
|
|
+ jmethodID integerConstructorID = env->GetMethodID(integerClass, "<init>", "(I)V");
|
|
|
+ jobject key = env->NewObject(integerClass, integerConstructorID, nKey);
|
|
|
+ std::vector<PaperPage> paperVec = iter->second;
|
|
|
+ int nPaperSize = paperVec.size();
|
|
|
+ jclass mapClass = env->FindClass("java/util/HashMap");
|
|
|
+ jmethodID putMethodID =
|
|
|
+ env->GetMethodID(
|
|
|
+ mapClass,
|
|
|
+ "put",
|
|
|
+ "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;" );
|
|
|
+
|
|
|
+ jclass arrayListClass = env->FindClass("java/util/ArrayList");
|
|
|
+ jmethodID arrayListInit = env->GetMethodID(arrayListClass, "<init>", "()V");
|
|
|
+ jmethodID addToList = env->GetMethodID(
|
|
|
+ arrayListClass,
|
|
|
+ "add",
|
|
|
+ "(Ljava/lang/Object;)Z" );
|
|
|
+ jobject listObj = env->NewObject(arrayListClass, arrayListInit);
|
|
|
+ for(int i = 0; i < nPaperSize; i++)
|
|
|
+ {
|
|
|
+ PaperPage tPage = paperVec.at(i);
|
|
|
+ jstring firstPage = str2jstring(env, tPage.firstPage.c_str());
|
|
|
+ jstring secondPage = str2jstring(env, tPage.secondPage.c_str());
|
|
|
+ env->CallBooleanMethod(listObj, addToList, firstPage);
|
|
|
+ env->CallBooleanMethod(listObj, addToList, secondPage);
|
|
|
+ env->DeleteLocalRef(firstPage);
|
|
|
+ env->DeleteLocalRef(secondPage);
|
|
|
+ }
|
|
|
+ env->CallObjectMethod(papers_map, putMethodID, key, listObj);
|
|
|
+ //资源释放
|
|
|
+ env->DeleteLocalRef(integerClass);
|
|
|
+ env->DeleteLocalRef(key);
|
|
|
+ env->DeleteLocalRef(mapClass);
|
|
|
+ env->DeleteLocalRef(arrayListClass);
|
|
|
+ env->DeleteLocalRef(listObj);
|
|
|
+ }
|
|
|
+ std::string strCardId = tIdentify.getPaperCardId();
|
|
|
+ jstring strPaperId = str2jstring(env, strCardId.c_str());
|
|
|
+ jclass stringBufferClass = env->FindClass("java/lang/StringBuffer");
|
|
|
+ jmethodID appendMethodID =
|
|
|
+ env->GetMethodID(
|
|
|
+ stringBufferClass,
|
|
|
+ "append",
|
|
|
+ "(Ljava/lang/Object;)Ljava/lang/StringBuffer;" );
|
|
|
+ env->CallObjectMethod(str_card_id, appendMethodID, strPaperId);
|
|
|
+ env->DeleteLocalRef(strPaperId);
|
|
|
+ env->DeleteLocalRef(stringBufferClass);
|
|
|
+
|
|
|
+// clock_t endTime = clock();
|
|
|
+// double exAustTime = (endTime - stratTime) / CLOCKS_PER_SEC;
|
|
|
+ return str2jstring(env, strRet.c_str());
|
|
|
+}
|
|
|
+
|
|
|
extern "C"
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
-Java_com_example_paperidentify_IdentifyNative_preIdentifyByFileList(JNIEnv *env, jclass clazz,
|
|
|
- jobject img_list,
|
|
|
- jint n_school_id,
|
|
|
- jboolean b_use_test_env,
|
|
|
- jobject str_card_id,
|
|
|
- jobject papers_map) {
|
|
|
+Java_com_example_paperidentify_IdentifyNative_preIdentifyByFileList__Ljava_util_ArrayList_2ILjava_lang_StringBuffer_2Ljava_util_HashMap_2Ljava_lang_String_2(
|
|
|
+ JNIEnv *env, jclass clazz, jobject img_list, jint n_school_id, jobject str_card_id,
|
|
|
+ jobject papers_map, jstring str_ip) {
|
|
|
std::vector<std::string> paperVec;
|
|
|
std::string strRet;
|
|
|
|
|
@@ -50,9 +196,11 @@ Java_com_example_paperidentify_IdentifyNative_preIdentifyByFileList(JNIEnv *env,
|
|
|
env->DeleteLocalRef(listClass);
|
|
|
env->DeleteLocalRef(array);
|
|
|
|
|
|
+ const char * ipAddress = env->GetStringUTFChars(str_ip, 0);
|
|
|
int nSchoolId = n_school_id;
|
|
|
paperPreIdentify tIdentify(nSchoolId);
|
|
|
- PAPERIDENTIFYSTATUS eStatus = tIdentify.scanPaper(paperVec, b_use_test_env == JNI_TRUE);
|
|
|
+ PAPERIDENTIFYSTATUS eStatus = tIdentify.scanPaper(paperVec, ipAddress);
|
|
|
+ env->ReleaseStringUTFChars(str_ip, ipAddress);
|
|
|
strRet = std::to_string(eStatus);
|
|
|
//将异常数据存入容器
|
|
|
std::map<PaperAbnormalType, std::vector<PaperPage>> resMap = tIdentify.getAbnPapers();
|
|
@@ -116,18 +264,31 @@ Java_com_example_paperidentify_IdentifyNative_preIdentifyByFileList(JNIEnv *env,
|
|
|
|
|
|
extern "C"
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
-Java_com_example_paperidentify_IdentifyNative_preIdentify(JNIEnv *env, jclass clazz,
|
|
|
- jstring str_img_path, jint n_school_id,
|
|
|
- jboolean b_use_test_env,
|
|
|
- jobject str_card_id, jobject papers_map) {
|
|
|
- clock_t stratTime = clock();
|
|
|
- const char * imgPath = env->GetStringUTFChars(str_img_path, 0);
|
|
|
+Java_com_example_paperidentify_IdentifyNative_preIdentifyByFileList__Ljava_util_ArrayList_2ILjava_lang_StringBuffer_2Ljava_util_HashMap_2(
|
|
|
+ JNIEnv *env, jclass clazz, jobject img_list, jint n_school_id, jobject str_card_id,
|
|
|
+ jobject papers_map) {
|
|
|
+ std::vector<std::string> paperVec;
|
|
|
+ std::string strRet;
|
|
|
+
|
|
|
+ //https://stackoverflow.com/questions/24403340/jni-java-arraylist-conversion-to-c-stdstring
|
|
|
+ jclass listClass = env->FindClass("java/util/List");
|
|
|
+ jmethodID mToArray = env->GetMethodID(listClass, "toArray", "()[Ljava/lang/Object;");
|
|
|
+ if(mToArray == NULL)
|
|
|
+ return str2jstring(env, strRet.c_str());
|
|
|
+ jobjectArray array = (jobjectArray)env->CallObjectMethod(img_list, mToArray);
|
|
|
+ for(int i=0; i<env->GetArrayLength(array); i++) {
|
|
|
+ jstring strObj = (jstring)env->GetObjectArrayElement(array, i);
|
|
|
+ const char * chr = env->GetStringUTFChars(strObj, NULL);
|
|
|
+ paperVec.push_back(chr);
|
|
|
+ env->ReleaseStringUTFChars(strObj, chr);
|
|
|
+ }
|
|
|
+ env->DeleteLocalRef(listClass);
|
|
|
+ env->DeleteLocalRef(array);
|
|
|
+
|
|
|
int nSchoolId = n_school_id;
|
|
|
paperPreIdentify tIdentify(nSchoolId);
|
|
|
- PAPERIDENTIFYSTATUS eStatus = tIdentify.scanPaper(imgPath, b_use_test_env == JNI_TRUE);
|
|
|
- env->ReleaseStringUTFChars(str_img_path, imgPath);
|
|
|
- std::string strRet = std::to_string(eStatus);
|
|
|
-
|
|
|
+ PAPERIDENTIFYSTATUS eStatus = tIdentify.scanPaper(paperVec);
|
|
|
+ strRet = std::to_string(eStatus);
|
|
|
//将异常数据存入容器
|
|
|
std::map<PaperAbnormalType, std::vector<PaperPage>> resMap = tIdentify.getAbnPapers();
|
|
|
std::map<PaperAbnormalType, std::vector<PaperPage>>::iterator iter = resMap.begin();
|
|
@@ -182,8 +343,8 @@ Java_com_example_paperidentify_IdentifyNative_preIdentify(JNIEnv *env, jclass cl
|
|
|
env->CallObjectMethod(str_card_id, appendMethodID, strPaperId);
|
|
|
env->DeleteLocalRef(strPaperId);
|
|
|
env->DeleteLocalRef(stringBufferClass);
|
|
|
+ std::string strRes = "1 : " + std::to_string(resMap[(PaperAbnormalType)1].size()) + " 2 : " + std::to_string(resMap[(PaperAbnormalType)2].size()) + " 3 : " + std::to_string(resMap[(PaperAbnormalType)3].size());
|
|
|
+ __android_log_print(ANDROID_LOG_INFO, "ASDQWE", "%s \n", strRes.c_str());
|
|
|
|
|
|
- clock_t endTime = clock();
|
|
|
- double exAustTime = (endTime - stratTime) / CLOCKS_PER_SEC;
|
|
|
return str2jstring(env, strRet.c_str());
|
|
|
}
|