test - 副本.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. #include "StdAfx.h"
  2. #include "BatchService.h"
  3. #include "scan_common.h"
  4. #include "..\EvaluationUtil\HttpClient.h"
  5. #include "..\Schema\schema_struct.h"
  6. #include "SchemaLoader.h"
  7. #include "basic_struct_result.h"
  8. #include "..\Identifier\schema_struct.h"
  9. #include "ServerConfig.h"
  10. //#include "Log4cplusInitalizer.h"
  11. #include "TemplateManager.h"
  12. #include "resource.h"
  13. #include "IdentifyService.h"
  14. #include "ResultUploader.h"
  15. #include <direct.h>
  16. #include <time.h>
  17. #include "OnlineCardIdentifyService.h"
  18. #include <fstream>
  19. #include "../Identifier/OnLineCardSchemaStruct.h"
  20. #include "..\ZLibWrapMemLib\UnZipFile.h"
  21. #include "..\ZLibWrapMemLib\MemZipFile.h"
  22. #include "..\ZLibWrapLib\ZLibWrapLib.h"
  23. #include "OnlineCardStudentMatcher.h"
  24. #include "ResultUploader.h"
  25. #include <future>
  26. #include "../Identifier/PageIdentify.h"
  27. int m_nSubjectID = 0;
  28. CString GetExePath();
  29. CString AnsiToUnicode(const std::string& str);
  30. std::string UnicodeToAnsi(const CString& str);
  31. using namespace schema;
  32. using namespace OnLineCard;
  33. OnLineCard::PaperTemplate* m_onlineCardTemplate = new OnLineCard::PaperTemplate;
  34. bool ParseTemplateFromJsonAll(const std::string&fileName)//全学科在线答题卡
  35. {
  36. extern bool g_isAllSubject;//是否是全学科
  37. g_isAllSubject = 1;
  38. //1 单选 2 小题单选 3 多选 4 小题多选 5 单空 6 多空 7 小题多空 8 解答 9 小题解答 10 英语作文 11 语文作文 12 判断题
  39. //0选择 1解答 2选作 3填空 4编组 5不定项 8不定项
  40. map<string, int> type_map;//新旧题型对应
  41. type_map["1"] = 0; type_map["2"] = 0; type_map["3"] = 5; type_map["4"] = 5; type_map["5"] = 3; type_map["6"] = 3;
  42. type_map["7"] = 3; type_map["8"] = 1; type_map["9"] = 1; type_map["12"] = 0; /*type_map["10"] = 1; type_map["11"] = 1; */
  43. CUnZipFile uzip(CString(fileName.c_str()));
  44. std::map<CString, std::vector<unsigned char>> map1;
  45. while (uzip.HasMoreEntry()){
  46. CString fileNam;
  47. uzip.GetNextEntry(fileNam);
  48. char buffer[1024 * 8];
  49. int len;
  50. std::vector<unsigned char>& data = map1[fileNam];
  51. data.reserve(1024 * 128);
  52. while ((len = uzip.Read(buffer, 1024 * 8)) > 0){
  53. if (data.capacity() < data.size() + len){
  54. int c = data.capacity() + 1024 * 128;
  55. data.reserve(c);
  56. }
  57. int oldSize = data.size();
  58. data.resize(oldSize + len);
  59. char * dst = (char *)data.data() + oldSize;
  60. memcpy(dst, buffer, len);
  61. }
  62. }
  63. uzip.Close();
  64. auto schemabytes = map1.find(_T("json.txt"));
  65. if (schemabytes == map1.end()){
  66. return SCH_LOAD_ERR_MISSINGFORMAT;
  67. }
  68. std::vector<unsigned char>& data = schemabytes->second;
  69. auto strJson = std::string((char *)data.data(), data.size());
  70. if (!m_onlineCardTemplate) return false;
  71. m_onlineCardTemplate->pages.clear();
  72. auto pfGetPos = [](const rapidjson::Value&value)->std::tuple<bool, Pos>{
  73. bool bRet = false;
  74. double x = 0.0, y = 0.0, w = 0.0, h = 0.0;
  75. auto itX = value.FindMember("x");
  76. if (itX != value.MemberEnd() && (itX->value.IsInt() || itX->value.IsDouble())){
  77. x = itX->value.GetDouble();
  78. }
  79. auto itY = value.FindMember("y");
  80. if (itY != value.MemberEnd() && (itY->value.IsInt() || itY->value.IsDouble())){
  81. y = itY->value.GetDouble();
  82. }
  83. auto itW = value.FindMember("width");
  84. if (itW != value.MemberEnd() && (itW->value.IsInt() || itW->value.IsDouble())){
  85. w = itW->value.GetDouble();
  86. }
  87. auto itH = value.FindMember("height");
  88. if (itH != value.MemberEnd() && (itH->value.IsInt() || itH->value.IsDouble())){
  89. h = itH->value.GetDouble();
  90. bRet = true;
  91. }
  92. return std::tie(bRet, Pos{ x, y, w, h });
  93. };
  94. rapidjson::Document doc;
  95. doc.Parse(strJson.c_str());
  96. if (doc.HasParseError()) return false;
  97. m_onlineCardTemplate->subject_id = m_nSubjectID;
  98. m_onlineCardTemplate->_version = "3.1.0";
  99. // 检测版本号
  100. auto it_version = doc.FindMember("online_card_version");
  101. if (it_version != doc.MemberEnd() && it_version->value.IsString()){
  102. m_onlineCardTemplate->_version = it_version->value.GetString();
  103. }
  104. LOGFMTI("在线答题卡版本号:%s", m_onlineCardTemplate->_version.c_str());
  105. {
  106. // 总页数
  107. auto itTotalPage = doc.FindMember("totalPage");
  108. if (itTotalPage != doc.MemberEnd() && itTotalPage->value.IsInt()){
  109. m_onlineCardTemplate->totalPage = itTotalPage->value.GetInt();
  110. }
  111. // 是否使用二维码
  112. auto itUseQrCode = doc.FindMember("useQrCode");
  113. if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsBool()){
  114. m_onlineCardTemplate->useQrCode = itUseQrCode->value.GetBool();
  115. }
  116. if (itUseQrCode != doc.MemberEnd() && itUseQrCode->value.IsInt()){
  117. m_onlineCardTemplate->useQrCode = (itUseQrCode->value.GetInt() != 0);
  118. }
  119. // 学校状态
  120. auto itSchoolStatus = doc.FindMember("school_card_status");
  121. if (itSchoolStatus != doc.MemberEnd() && itSchoolStatus->value.IsInt()){
  122. m_onlineCardTemplate->schoolCardStatus = itSchoolStatus->value.GetInt();
  123. }
  124. int n_duo_xuanti_index = 0;
  125. std::string temp_all_id = "";
  126. // 页
  127. auto itPages = doc.FindMember("pages");
  128. if (itPages != doc.MemberEnd() && itPages->value.IsArray()/* && itPages->value.Size() == m_onlineCardTemplate->totalPage*/){
  129. for (auto itPage = itPages->value.Begin(); itPage != itPages->value.End(); ++itPage){
  130. if (!itPage->IsObject()) return false;
  131. PageTemplate page;
  132. // 页号
  133. auto itPageNo = itPage->FindMember("pageNo");
  134. if (itPageNo != itPage->MemberEnd() && itPageNo->value.IsInt()){
  135. page.pageNo = itPageNo->value.GetInt();
  136. }
  137. else {
  138. return false;
  139. }
  140. // 定位点
  141. auto itLocations = itPage->FindMember("location");
  142. if (itLocations != itPage->MemberEnd() && itLocations->value.IsArray()){
  143. for (auto it = itLocations->value.Begin(); it != itLocations->value.End(); ++it){
  144. Location lc;
  145. auto itType = it->FindMember("type");
  146. if (itType != it->MemberEnd() && itType->value.IsInt()){
  147. lc.type = itType->value.GetInt();
  148. }
  149. auto tm = pfGetPos(*it);
  150. if (std::get<0>(tm)){
  151. lc.pos = std::get<1>(tm);
  152. }
  153. page.location.push_back(lc);
  154. }
  155. }
  156. if (page.pageNo == 1){
  157. if (!m_onlineCardTemplate->useQrCode){
  158. // 条形码
  159. auto itBar = itPage->FindMember("studentcode_bar");
  160. if (itBar != itPage->MemberEnd() && itBar->value.IsObject()){
  161. auto itObj = itBar->value.FindMember("object");
  162. if (itObj != itBar->value.MemberEnd() && itObj->value.IsObject()){
  163. auto t = pfGetPos(itObj->value);
  164. page.studentcode_bar = std::get<1>(t);
  165. }
  166. }
  167. // 填涂考号
  168. auto itFill = itPage->FindMember("studentcode_fill");
  169. if (itFill != itPage->MemberEnd() && itFill->value.IsObject()){
  170. auto itObj = itFill->value.FindMember("object");
  171. if (itObj != itFill->value.MemberEnd() && itObj->value.IsArray()){
  172. for (auto itRow = itObj->value.Begin(); itRow != itObj->value.End(); ++itRow){
  173. auto itGroup = itRow->FindMember("group");
  174. if (itGroup != itRow->MemberEnd() && itGroup->value.IsArray()){
  175. std::vector<Opt> _vctOpt;
  176. for (auto itCol = itGroup->value.Begin(); itCol != itGroup->value.End(); ++itCol){
  177. Opt opt;
  178. auto itOptName = itCol->FindMember("optName");
  179. if (itOptName != itCol->MemberEnd() && itOptName->value.IsInt())
  180. opt.optName = std::to_string(itOptName->value.GetInt());
  181. auto t = pfGetPos(*itCol);
  182. if (std::get<0>(t))
  183. opt.pos = std::get<1>(t);
  184. _vctOpt.push_back(opt);
  185. }
  186. page.studentcode_fill.push_back(_vctOpt);
  187. }
  188. }
  189. }
  190. }
  191. }
  192. // 缺考标记
  193. auto itAbsent = itPage->FindMember("absent");
  194. if (itAbsent != itPage->MemberEnd() && itAbsent->value.IsObject()){
  195. auto t = pfGetPos(itAbsent->value);
  196. if (std::get<0>(t)){
  197. page.absent = std::get<1>(t);
  198. }
  199. }
  200. // 二维码
  201. auto itQrCode = itPage->FindMember("QrCode");
  202. if (itQrCode != itPage->MemberEnd() && itQrCode->value.IsObject()){
  203. auto t = pfGetPos(itQrCode->value);
  204. if (std::get<0>(t)){
  205. page.QrCode = std::get<1>(t);
  206. }
  207. }
  208. } // end if page.pageNo == 0
  209. // 长宽
  210. auto itImge = itPage->FindMember("imge");
  211. if (itImge != itPage->MemberEnd()){
  212. auto t = std::get<1>(pfGetPos(itImge->value));
  213. page.w = t.w;
  214. page.h = t.h;
  215. }
  216. else{
  217. return false;
  218. }
  219. // 题目
  220. auto itQuestion = itPage->FindMember("questions");
  221. if (itQuestion != itPage->MemberEnd() && itQuestion->value.IsArray())
  222. {
  223. for (auto it = itQuestion->value.Begin(); it != itQuestion->value.End(); ++it)
  224. {
  225. question q;
  226. // 题目类型
  227. auto itType = it->FindMember("type");
  228. string qType = "1";
  229. if (itType != it->MemberEnd() && itType->value.IsString())
  230. {
  231. qType = itType->value.GetString();
  232. if (type_map.find(qType) != type_map.end())
  233. {
  234. q.type = type_map[qType];
  235. }
  236. }
  237. else if (itType != it->MemberEnd() && itType->value.IsInt())
  238. {
  239. qType = to_string(itType->value.GetInt());
  240. if (type_map.find(qType) != type_map.end())
  241. {
  242. q.type = type_map[qType];
  243. }
  244. }
  245. else
  246. {
  247. return false;
  248. }
  249. q.marktype = 0;
  250. // 题目类型
  251. auto itMarktype = it->FindMember("marktype");
  252. if (itMarktype != it->MemberEnd() && itMarktype->value.IsInt()){
  253. q.marktype = itMarktype->value.GetInt();
  254. }
  255. if (qType == "10")//英文作文
  256. {
  257. q.marktype = 10;
  258. q.type = 1;
  259. }
  260. else if (qType == "11")//语文作文
  261. {
  262. q.marktype = 4;
  263. q.type = 1;
  264. }
  265. else if (qType == "12")//判断
  266. {
  267. q.type = 0;
  268. }
  269. // 分数
  270. auto itScore = it->FindMember("score");
  271. if (itScore != it->MemberEnd() && itScore->value.IsObject()){
  272. auto itFull = itScore->value.FindMember("full");
  273. if (itFull != itScore->value.MemberEnd() && (itFull->value.IsDouble() || itFull->value.IsInt()))
  274. q.score = itFull->value.GetDouble();
  275. else if (itFull != itScore->value.MemberEnd() && itFull->value.IsString())
  276. q.score = atof(itFull->value.GetString());
  277. }
  278. // 题目编号 2选做题
  279. auto itId = it->FindMember((q.type == 2 || q.type == 4) ? "editorId" : "id");
  280. if (itId != it->MemberEnd() && itId->value.IsString()){
  281. q.id = itId->value.GetString();
  282. }
  283. if (itId != it->MemberEnd() && itId->value.IsInt()){
  284. q.id = std::to_string(itId->value.GetInt());
  285. }
  286. if (q.type == 2 || q.type == 4){
  287. auto itAllID = it->FindMember("id");
  288. if (itAllID != it->MemberEnd() && itAllID->value.IsString()){
  289. q.all_id = itAllID->value.GetString();
  290. }
  291. }
  292. auto itSmallQtNo = it->FindMember("smallQtNo");
  293. if (itSmallQtNo != it->MemberEnd() && !(itSmallQtNo->value.IsNull()))
  294. {
  295. q.smallQtNo = itSmallQtNo->value.GetInt();
  296. }
  297. else
  298. {
  299. q.smallQtNo = -1;
  300. }
  301. auto itNickID = it->FindMember("name");
  302. if (itNickID != it->MemberEnd() && !(itNickID->value.IsNull()) && itNickID->value.IsString())
  303. {
  304. //m_mapKeguantiNickName[q.id] = itNickID->value.GetString();
  305. }
  306. // 打分区域
  307. auto itScoreBox = it->FindMember("scorebox");
  308. if (itScoreBox != it->MemberEnd() && itScoreBox->value.IsObject()){
  309. // 打分框类型
  310. auto itType = itScoreBox->value.FindMember("type");
  311. if (itType != itScoreBox->value.MemberEnd() && itType->value.IsString()){
  312. q.scoreBox.type = std::stoi(itType->value.GetString());
  313. }
  314. else if (itType != itScoreBox->value.MemberEnd() && itType->value.IsInt()){
  315. q.scoreBox.type = itType->value.GetInt();
  316. }
  317. else{
  318. return false;
  319. }
  320. if (q.smallQtNo != -1)
  321. {
  322. // 小问最大分值
  323. auto itmaxScore = itScoreBox->value.FindMember("maxscore");
  324. if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsString()){
  325. q.scoreBox.maxsorce = std::stod(itmaxScore->value.GetString());
  326. }
  327. else if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsDouble()){
  328. q.scoreBox.maxsorce = itScoreBox->value.GetDouble();
  329. }
  330. else if (itmaxScore != itScoreBox->value.MemberEnd() && itmaxScore->value.IsInt()){
  331. q.scoreBox.maxsorce = itmaxScore->value.GetInt();
  332. }
  333. else{
  334. q.scoreBox.maxsorce = 0.0;
  335. }
  336. }
  337. else
  338. {
  339. q.scoreBox.maxsorce = 0.0;
  340. }
  341. // 分数上限
  342. auto itLimit = itScoreBox->value.FindMember("limit");
  343. if (itLimit != itScoreBox->value.MemberEnd() && itLimit->value.IsString())
  344. q.scoreBox.limit = std::stoi(itLimit->value.GetString());
  345. if (itLimit != itScoreBox->value.MemberEnd() && itLimit->value.IsInt())
  346. q.scoreBox.limit = itLimit->value.GetInt();
  347. // 最后一个格子是否为小数 1是 2否
  348. auto itPoint = itScoreBox->value.FindMember("point");
  349. if (itPoint != itScoreBox->value.MemberEnd()){
  350. if (itPoint->value.IsInt()){
  351. q.scoreBox.bPoint = (itPoint->value.GetInt() == 1);
  352. }
  353. else if (itPoint->value.IsString()){
  354. std::string str = itPoint->value.GetString();
  355. q.scoreBox.bPoint = (str == "1");
  356. }
  357. }
  358. // 填空题带打分
  359. if (q.scoreBox.type == 3){
  360. auto itScore = itScoreBox->value.FindMember("Score");
  361. if (itScore != itScoreBox->value.MemberEnd() && itScore->value.IsArray()){
  362. for (auto it = itScore->value.Begin(); it != itScore->value.End(); ++it){
  363. if (it->IsString()){
  364. std::string str = it->GetString();
  365. if (!str.empty())
  366. q.scoreBox.vctScore.push_back(std::stoi(str));
  367. }
  368. }
  369. }
  370. }
  371. // 打分位置
  372. auto t = pfGetPos(itScoreBox->value);
  373. if (std::get<0>(t))
  374. q.scoreBox.pos = std::get<1>(t);
  375. }
  376. // 几选几
  377. if (q.type == 2 || q.type == 4){ // 选做题
  378. rapidjson::Value::ConstMemberIterator itSel = it->FindMember("select");
  379. if (itSel != it->MemberEnd() && itSel->value.IsInt()){
  380. q.selItem = itSel->value.GetInt();
  381. }
  382. rapidjson::Value::ConstMemberIterator itTotal = it->FindMember("total");
  383. if (itTotal != it->MemberEnd() && itTotal->value.IsInt()){
  384. q.selTotal = itTotal->value.GetInt();
  385. }
  386. }
  387. // 剪裁区域
  388. if (q.type == 1 || q.type == 3 || q.type == 2 || q.type == 4){ // 1 解答题 2 选做题 3 填空题
  389. auto itCut = it->FindMember("cut");
  390. if (itCut != it->MemberEnd() && itCut->value.IsObject()){
  391. auto itLink = itCut->value.FindMember("linkparm");
  392. if (itLink != itCut->value.MemberEnd() && itLink->value.IsInt())
  393. q.cut.linkparm = itLink->value.GetInt();
  394. if (itLink != itCut->value.MemberEnd() && itLink->value.IsString())
  395. q.cut.linkparm = std::stoi(itLink->value.GetString());
  396. auto t = pfGetPos(itCut->value);
  397. if (std::get<0>(t))
  398. q.cut.pos = std::get<1>(t);
  399. if (q.type == 3 && m_onlineCardTemplate->subject_id == 8)
  400. {
  401. TCHAR FilePath[MAX_PATH];
  402. GetModuleFileName(NULL, FilePath, MAX_PATH);
  403. (_tcsrchr(FilePath, '\\'))[1] = 0;
  404. lstrcat(FilePath, _T("config.ini"));
  405. int english = GetPrivateProfileInt(_T("USER"), _T("english_height"), 30, FilePath);//英语填空题高度加大比例
  406. if (english > 0 && english <= 30)
  407. {
  408. q.cut.pos.h = q.cut.pos.h* (1.0 + english / 100.0);
  409. }
  410. }
  411. }
  412. if (q.type == 2){
  413. if (temp_all_id != q.all_id)
  414. {
  415. temp_all_id = q.all_id;
  416. n_duo_xuanti_index = 0;
  417. }
  418. if (q.cut.linkparm < 2){
  419. std::vector<std::string> split_qr;
  420. split(q.all_id, (std::string)",", &split_qr);
  421. if (n_duo_xuanti_index < split_qr.size())
  422. q.id = split_qr[n_duo_xuanti_index++];
  423. }
  424. else
  425. {
  426. std::vector<std::string> split_qr;
  427. split(q.all_id, (std::string)",", &split_qr);
  428. if (n_duo_xuanti_index - 1 >= 0 && n_duo_xuanti_index - 1 < split_qr.size())
  429. q.id = split_qr[n_duo_xuanti_index - 1];
  430. }
  431. }
  432. else if (q.type == 4)
  433. {
  434. if (temp_all_id != q.all_id)
  435. {
  436. temp_all_id = q.all_id;
  437. n_duo_xuanti_index = 0;
  438. }
  439. if (q.cut.linkparm < 1){
  440. std::vector<std::string> split_qr;
  441. split(q.all_id, (std::string)",", &split_qr);
  442. if (n_duo_xuanti_index < split_qr.size())
  443. q.id = split_qr[n_duo_xuanti_index++];
  444. }
  445. else
  446. {
  447. std::vector<std::string> split_qr;
  448. split(q.all_id, (std::string)",", &split_qr);
  449. if (n_duo_xuanti_index - 1 >= 0 && n_duo_xuanti_index - 1 < split_qr.size())
  450. q.id = split_qr[n_duo_xuanti_index - 1];
  451. }
  452. }
  453. }
  454. // 选项 单选题 多选题
  455. if (q.type == 0 || q.type == 8 || q.type == 5){
  456. auto itOpts = it->FindMember("opt");
  457. if (itOpts != it->MemberEnd() && itOpts->value.IsArray()){
  458. for (auto itOpt = itOpts->value.Begin(); itOpt != itOpts->value.End(); ++itOpt){
  459. Opt opt;
  460. auto t = pfGetPos(*itOpt);
  461. if (std::get<0>(t))
  462. opt.pos = std::get<1>(t);
  463. auto itOptName = itOpt->FindMember("optName");
  464. if (itOptName != itOpt->MemberEnd() && itOptName->value.IsString())
  465. opt.optName = itOptName->value.GetString();
  466. q.opt.push_back(opt);
  467. }
  468. }
  469. }
  470. else if (q.type == 2 || q.type == 4){ // 选作
  471. auto itSelectqts = it->FindMember("selectqts");
  472. if (itSelectqts != it->MemberEnd() && itSelectqts->value.IsArray() && itSelectqts->value.Size() > 0){
  473. for (auto itOpt = itSelectqts->value.Begin(); itOpt != itSelectqts->value.End(); ++itOpt){
  474. Opt opt;
  475. auto t = pfGetPos(*itOpt);
  476. if (std::get<0>(t))
  477. opt.pos = std::get<1>(t);
  478. auto itOptName = itOpt->FindMember("optName");
  479. if (itOptName != itOpt->MemberEnd() && itOptName->value.IsString())
  480. opt.optName = itOptName->value.GetString();
  481. q.opt.push_back(opt);
  482. }
  483. }
  484. }
  485. page.vctQuestions.push_back(q);
  486. }
  487. }
  488. m_onlineCardTemplate->pages.insert(std::make_pair(page.pageNo, page));
  489. }
  490. }
  491. else{
  492. return false;
  493. }
  494. }
  495. m_onlineCardTemplate->open_save_debug_img = false;
  496. m_onlineCardTemplate->dingweidian_range_top = 300; //上定位点范围
  497. m_onlineCardTemplate->dingweidian_rang_buttom = 300;// 下定位点范围
  498. m_onlineCardTemplate->dingweidian_w_max_rate = 1.0;
  499. m_onlineCardTemplate->dingweidian_h_max_rate = 1.0;
  500. m_onlineCardTemplate->dingweidian_w_min_rate = 0.7;
  501. m_onlineCardTemplate->dingweidian_h_min_rate = 0.7;
  502. //CString _ini_file = GetExePath() + _T("\\config.ini");
  503. //TCHAR sz_offset_file_name[MAX_PATH] = { 0 };
  504. //GetPrivateProfileString(_T("USER"), _T("offset_file"), _T(""), sz_offset_file_name, sizeof(sz_offset_file_name) / sizeof(TCHAR), _ini_file);
  505. //ParseTemplateOffset(UnicodeToAnsi(GetExePath() + _T("\\") + sz_offset_file_name), m_onlineCardTemplate);
  506. return true;
  507. }
  508. void main()
  509. {
  510. ParseTemplateFromJsonAll("D:\\thirdNanCang\\Win32\\Debug\\1111.zip");
  511. PageIdentify identify;
  512. CvMemStorage* storage = cvCreateMemStorage(0);
  513. identify.SetTemplate(m_onlineCardTemplate);
  514. IplImage *src = cvLoadImage("D:/1测试/1在线南昌全题型/新建文件夹/202112100116_0001.jpg");
  515. IplImage *src2 = cvLoadImage("D:/1测试/1在线南昌全题型/新建文件夹/202112100116_0002.jpg");
  516. IplImage * dst = NULL;
  517. IplImage * dst2 = NULL;
  518. SchemaPage* pschemaPage1 = NULL;
  519. SchemaPage* pschemaPage2 = NULL;
  520. std::string path = "D:/1DRAW.jpg";
  521. //LOGI("Identify_impl 1");
  522. bool ret = identify.createSchema(src, &dst, &pschemaPage1, path.c_str(), true, "m_strQrClass", 0);
  523. ret = identify.createSchema(src2, &dst2, &pschemaPage2, path.c_str(), true, "m_strQrClass", 0);
  524. //LOGI("Identify_impl 2");
  525. OMR_RESULT *m_result_buffer = new OMR_RESULT;
  526. identify.out_result = m_result_buffer;
  527. identify.omr_result = (identify::result::OMR_RESULT*)identify.out_result;
  528. SchemaPage& schemaPage = *pschemaPage1;
  529. identify.omr_result->card_qrFlag = schemaPage.qrFlag;
  530. identify.omr_result->is_same_exam_id = schemaPage.is_same_exam_id;
  531. identify.omr_result->is_front_page = schemaPage.is_front_page;
  532. identify.omr_result->is_use_qr_code = schemaPage.is_use_qr_code;
  533. identify.omr_result->examid_by_qr_code = schemaPage.examid_by_qr_code;
  534. identify.omr_result->strMagicClassId = schemaPage.paper_id;
  535. identify.omr_result->strMagicStudentId = schemaPage.student_code;
  536. /************************读取学生学号*********************************************/
  537. ret = identify.ReadStudentID(schemaPage, dst);
  538. if (ret != identify::result::IDF_SUCCESS) {
  539. if (dst != NULL)cvReleaseImage(&dst);
  540. if (pschemaPage1 != NULL)delete pschemaPage1;
  541. return ;
  542. }
  543. //LOGI("Identify_impl 3");
  544. /************************查找题目定位点,准备定位数据*********************************************/
  545. ret = identify.FindQuestionLocatePoints(schemaPage, dst);
  546. if (ret != identify::result::IDF_SUCCESS) {
  547. if (dst != NULL)cvReleaseImage(&dst);
  548. cvReleaseMemStorage(&storage);
  549. if (pschemaPage1 != NULL)delete pschemaPage1;
  550. return ;
  551. }
  552. /************************客观题()*********************************************/
  553. ret = identify.ReadKeGuanTi(schemaPage, dst);
  554. if (ret != identify::result::IDF_SUCCESS) {
  555. if (dst != NULL)cvReleaseImage(&dst);
  556. cvReleaseMemStorage(&storage);
  557. if (pschemaPage1 != NULL)delete pschemaPage1;
  558. return ;
  559. }
  560. //LOGI("Identify_impl 4");
  561. /************************阅卷读取*************************************************/
  562. ret = identify.ReadQuestionScore(schemaPage, dst, storage);
  563. if (ret != identify::result::IDF_SUCCESS) {
  564. if (dst != NULL)cvReleaseImage(&dst);
  565. cvReleaseMemStorage(&storage);
  566. if (pschemaPage1 != NULL)delete pschemaPage1;
  567. return ;
  568. }
  569. //LOGI("Identify_impl 6");
  570. /************************根据给定区域切割图片*********************************************/
  571. ret = identify.ClipImg(schemaPage, dst);
  572. if (ret != identify::result::IDF_SUCCESS) {
  573. if (dst != NULL)cvReleaseImage(&dst);
  574. cvReleaseMemStorage(&storage);
  575. if (pschemaPage1 != NULL)delete pschemaPage1;
  576. return ;
  577. }
  578. //LOGI("Identify_impl 7");
  579. /************************读取缺考标记*********************************************/
  580. identify.omr_result->quekaoFlag = identify.ReadQuekaoFlag(schemaPage, dst);
  581. identify.omr_result->card_index = schemaPage.index;
  582. /*
  583. if (1){
  584. DrawSchema(dst, pschemaPage);
  585. cvSaveImage(path.c_str(), dst);
  586. }
  587. */
  588. if (dst != NULL)cvReleaseImage(&dst);
  589. if (dst2 != NULL)cvReleaseImage(&dst2);
  590. cvReleaseMemStorage(&storage);
  591. if (pschemaPage1 != NULL)delete pschemaPage1;
  592. return ;
  593. }