Переглянути джерело

Merge branch 'master' of http://gitz.zhixinhuixue.net:18880/zxhx-client-tool/pdfproject

maoyehu 2 роки тому
батько
коміт
39038b3bc7

+ 101 - 0
MFCApplication1/CvxText.cpp

@@ -695,5 +695,106 @@ int cutPaper(int pageNum, std::string strJsonPath, std::string strPaperPath, std
 		return ret ? 0 : 1;
 	}
 
+	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;
 }

+ 4 - 0
MFCApplication1/CvxText.h

@@ -4,6 +4,8 @@
 
 #include <string>
 #include <opencv2/opencv.hpp>
+#include "lib_common_depence.h"
+
 using namespace std;
 #define font_family "ËÎÌå"
 #define font_size   30
@@ -60,4 +62,6 @@ int dataCollectionPaper(int cols, int index, int fontSize, int lineGrayPix, bool
 *********************************************************/
 int cutPaper(int pageNum, std::string strJsonPath, std::string strPaperPath, std::string strSavePath);
 
+
+int PareseModeJson(preinfo::templatesInfo&  temeplatInfo);
 #endif // PUTTEXT_H_

+ 3 - 1
MFCApplication1/MFCApplication1Dlg.cpp

@@ -159,6 +159,7 @@ int IdentifyCallback(result::spinfo& pinfo, void* param)
 	return 0;
 }
 
+
 HANDLE _threadScan = NULL;
 DWORD WINAPI ScanThread(void *param)
 {
@@ -172,6 +173,7 @@ DWORD WINAPI ScanThread(void *param)
 	{
 		_mkdir(strTempDir.c_str());
 	}
+	PareseModeJson(temeplatInfo);
 	int nRet = api_processing_images("",
 		strTempDir.c_str(),
 		temeplatInfo,
@@ -183,7 +185,7 @@ DWORD WINAPI ScanThread(void *param)
 		IdentifyCallback,
 		NULL);
 	////启动算法扫描功能
-	if (nRet != 0)
+	if (nRet != RT_OK)
 	{
 		// 扫描异常
 		CString strErrorMsg = L"";