|
@@ -694,5 +694,106 @@ int cutPaper(int pageNum, std::string strJsonPath, std::string strPaperPath, std
|
|
|
cv::imwrite(szJpgPath, cut);
|
|
|
}
|
|
|
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int PareseModeJson(preinfo::templatesInfo& temeplatInfo)
|
|
|
+{
|
|
|
+ ifstream in("./page.json", ios::binary);
|
|
|
+ if (!in.is_open())
|
|
|
+ {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ int uuid = 100000; /// 每个框子的一个独立ID 不会有重复的
|
|
|
+ Json::Features features;
|
|
|
+ Json::Reader reader(features);
|
|
|
+ Json::Value root;
|
|
|
+ if (!reader.parse(in, root))
|
|
|
+ {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!root.isObject())
|
|
|
+ {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ //1.获取模板大小信息
|
|
|
+ preinfo::PaperTemplateInfo page;
|
|
|
+ Json::Value imageSize = root["imageSize"];
|
|
|
+ page.height = imageSize["height"].asInt();
|
|
|
+ page.width = imageSize["width"].asInt();
|
|
|
+
|
|
|
+ //2.获取定位点信息
|
|
|
+ Json::Value loction = root["location"];
|
|
|
+ auto funGetPos = [&](Json::Value item) {
|
|
|
+ preinfo::PaperRect<double> pb;
|
|
|
+ int x = item["x"].asInt();
|
|
|
+ int y = item["y"].asInt();
|
|
|
+ int h = item["height"].asInt();
|
|
|
+ int w = item["width"].asInt();
|
|
|
+ pb.centerx = x + w / 2.0;
|
|
|
+ pb.centery = y + h / 2.0;
|
|
|
+ pb.width = w;
|
|
|
+ pb.height = h;
|
|
|
+ return pb;
|
|
|
+ };
|
|
|
+ double offsetx = page.width; double offsety = page.height;
|
|
|
+ for (int i = 0; i < loction.size(); i++)
|
|
|
+ {
|
|
|
+ Json::Value row = loction[i];
|
|
|
+ preinfo::LocationPoint lc;
|
|
|
+ lc.id = uuid++;
|
|
|
+ auto tm = funGetPos(row);
|
|
|
+ lc.centerx = tm.centerx;
|
|
|
+ lc.centery = tm.centery;
|
|
|
+ lc.width = tm.width;
|
|
|
+ lc.height = tm.height;
|
|
|
+ if (offsetx > lc.centerx) offsetx = lc.getX();
|
|
|
+ if (offsety > lc.centery) offsety = lc.getY();
|
|
|
+ page.vecLocaltionPoints.push_back(lc);
|
|
|
+
|
|
|
+ }
|
|
|
+ //3.获取客观题信息
|
|
|
+ Json::Value pagenumber = root["pagenumber"];
|
|
|
+ for (int i = 0; i < pagenumber.size(); i++)
|
|
|
+ {
|
|
|
+ Json::Value item = pagenumber[i];
|
|
|
+ string strId = item["id"].asString();
|
|
|
+ preinfo::_QuestionChoice _qstc;
|
|
|
+ _qstc.id = uuid++;
|
|
|
+ _qstc.vecTiHao.push_back(atoi(strId.c_str()));
|
|
|
+ double dBoundBox[4] = { 100000,100000,0,0 };
|
|
|
+ _qstc.type = preinfo::BOX_QUESTION_CHOICE_M;
|
|
|
+ auto itOpts = item["opt"];
|
|
|
+ _qstc.number = itOpts.size();
|
|
|
+ std::vector<preinfo::TtItem> _vctOpt;
|
|
|
+ for (int i = 0; i < itOpts.size(); i++)
|
|
|
+ {
|
|
|
+ preinfo::TtItem opt;
|
|
|
+ auto tm = funGetPos(itOpts[i]);
|
|
|
+ opt.centerx = tm.centerx;
|
|
|
+ opt.centery = tm.centery;
|
|
|
+ opt.width = tm.width;
|
|
|
+ opt.height = tm.height;
|
|
|
+ _qstc.itemSize.width = opt.width;
|
|
|
+ _qstc.itemSize.height = opt.height;
|
|
|
+ dBoundBox[0] = dBoundBox[0] > opt.getX() ? opt.getX() : dBoundBox[0];
|
|
|
+ dBoundBox[1] = dBoundBox[1] > opt.getY() ? opt.getY() : dBoundBox[1];
|
|
|
+ dBoundBox[2] = dBoundBox[2] < (opt.centerx + opt.width / 2.0) ? (opt.centerx + opt.width / 2.0) : dBoundBox[2];
|
|
|
+ dBoundBox[3] = dBoundBox[3] < (opt.centery + opt.height / 2.0) ? (opt.centery + opt.height / 2.0) : dBoundBox[3];
|
|
|
+
|
|
|
+ auto subItem = itOpts[i];
|
|
|
+ opt.optName = subItem["optName"].asString();
|
|
|
+ _vctOpt.push_back(opt);
|
|
|
+ }
|
|
|
+ _qstc.width = (dBoundBox[2] - dBoundBox[0]);
|
|
|
+ _qstc.height = (dBoundBox[3] - dBoundBox[1]);
|
|
|
+ _qstc.centerx = dBoundBox[0] + _qstc.width / 2.0;
|
|
|
+ _qstc.centery = dBoundBox[1] + _qstc.height / 2.0;
|
|
|
+
|
|
|
+ _qstc.groups = _vctOpt;
|
|
|
+ page._vecQtChoices.push_back(_qstc);
|
|
|
+ }
|
|
|
return 0;
|
|
|
}
|