|
@@ -5,6 +5,10 @@
|
|
|
#include <iostream>
|
|
|
#include <fstream>
|
|
|
|
|
|
+#if QQM_ADD
|
|
|
+#include "cvUtil.h"
|
|
|
+#endif
|
|
|
+
|
|
|
using namespace std;
|
|
|
using namespace cv;
|
|
|
|
|
@@ -368,6 +372,410 @@ std::string JsonToString(const Json::Value & root)
|
|
|
return stream.str();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+int dataCollectionPaperPhysics(int cols, int index, int fontSize, int lineGrayPix, bool engShow,
|
|
|
+ std::vector<tuple<string, string>>& vecLines, CString dir, std::string& strPngPath, std::string tips) {
|
|
|
+ /* 这里要做一些栏数 和 vecLines的对应值确认 */
|
|
|
+ if (2 == cols && 14 * 2 == vecLines.size())
|
|
|
+ ; // ok
|
|
|
+ if (3 == cols && 14 * 3 == vecLines.size())
|
|
|
+ ; // ok
|
|
|
+ if (4 == cols && 14 * 4 == vecLines.size())
|
|
|
+ ; // ok
|
|
|
+
|
|
|
+ // 生成画布图像
|
|
|
+ cv::Mat img(cv::Size(1654, 2344), CV_8UC3, cv::Scalar(255, 255, 255));
|
|
|
+ int ptw = 80; int pth = 40;
|
|
|
+ cv::Size fSize(0, 0);
|
|
|
+ int leftPos = 100, rightPos = 1450;
|
|
|
+ int topPos = 90;
|
|
|
+ int fontW = rightPos - leftPos + ptw;
|
|
|
+ vector<cv::Rect> vecPts = {
|
|
|
+ cv::Rect(100,90,ptw,pth),
|
|
|
+ cv::Rect(580,90,ptw,pth),
|
|
|
+ cv::Rect(1450,90,ptw,pth),
|
|
|
+ cv::Rect(100,2176,ptw,pth),
|
|
|
+ cv::Rect(1450,2176,ptw,pth),
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ // 画定位点
|
|
|
+ for (size_t i = 0; i < vecPts.size(); i++)
|
|
|
+ {
|
|
|
+ rectangle(img, vecPts[i], cv::Scalar(0, 0, 0), -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 画示例框
|
|
|
+ topPos += pth; topPos += 30;
|
|
|
+ rectangle(img, cv::Rect(leftPos, topPos, fontW, 200), cv::Scalar(0, 0, 0), 2, 8, 0);
|
|
|
+
|
|
|
+ // 画页码框
|
|
|
+ cv::Rect boxPageNumber(leftPos + fontW - 300, topPos, 300, 200);
|
|
|
+ rectangle(img, boxPageNumber, cv::Scalar(0, 0, 0), 2, 8, 0);
|
|
|
+
|
|
|
+ // 生成二进制码流
|
|
|
+ /* 二进制码流的坐标在下面函数里面实现,需要用书写获取 */
|
|
|
+ vector<cv::Rect> vecBoxPages;
|
|
|
+ createBinString(img, index, ptw, pth, cv::Point(boxPageNumber.x, boxPageNumber.y), vecBoxPages);
|
|
|
+ string strPageNumInfo = "关联ID: " + to_string(index);
|
|
|
+ putTextZH(img, fSize, strPageNumInfo.c_str(), cv::Point(boxPageNumber.x + 100, boxPageNumber.y + 50 * 2 + 20 + 15 + 15 + 15), Scalar(0), 20, "宋体");
|
|
|
+
|
|
|
+ // 生成page.json
|
|
|
+ //generatePageJson(vecPts, vecBoxPages);
|
|
|
+
|
|
|
+ // 画警示信息
|
|
|
+ string strMesInfo = "1、请在对应的区域内临摹左侧电路图,每个方框内一个!\
|
|
|
+ \n\n2、可以使用铅笔和黑色笔绘图。☆\
|
|
|
+ \n\n3、如果本框内有绘画错误,进行了涂抹修改等操作,请将左上方的填涂框用任意笔进行填涂!☆☆\n";
|
|
|
+ if (tips.length() > 0)
|
|
|
+ {
|
|
|
+ strMesInfo = tips;
|
|
|
+ }
|
|
|
+ putTextZH(img, fSize, strMesInfo.c_str(), cv::Point(leftPos + 20, topPos + 20), Scalar(0), 25, "宋体");
|
|
|
+ int lineTop1 = topPos + 20 + fSize.height + 20;
|
|
|
+ cv::line(img, cv::Point(leftPos, lineTop1), cv::Point(rightPos + ptw - 300, topPos + 20 + fSize.height + 20), Scalar(0), 2, 8, 0);
|
|
|
+
|
|
|
+ // 正确示例
|
|
|
+ string strEgInfo = "注\n意\n事\n项";
|
|
|
+ putTextZH(img, fSize, strEgInfo.c_str(), cv::Point(leftPos + 20, topPos + 20 + fSize.height + 20 + 3), Scalar(0), 20, "宋体");
|
|
|
+ cv::line(img, cv::Point(leftPos + 20 + fSize.width + 10, lineTop1), cv::Point(leftPos + 20 + fSize.width + 10, topPos + 200), Scalar(0, 0, 0), 2, 8, 0);
|
|
|
+
|
|
|
+ // 填涂示例
|
|
|
+ string strtt = "尽量保持手绘内容与示例图相对位置一致!即保持整体相对居中!";
|
|
|
+ cv::Point ptEgInfo(leftPos + 70, topPos + 20 + fSize.height + 20 + 30);
|
|
|
+ putTextZH(img, fSize, strtt.c_str(), ptEgInfo, Scalar(0), 20, "宋体");
|
|
|
+
|
|
|
+ //cv::Rect rcttbox(ptEgInfo.x + 100, ptEgInfo.y - 5, 30, 30);
|
|
|
+ //rectangle(img, rcttbox, cv::Scalar(0), -1);
|
|
|
+ //rcttbox.x += 1;
|
|
|
+ //rcttbox.y += 1;
|
|
|
+ //rcttbox.width -= 2;
|
|
|
+ //rcttbox.height -= 2;
|
|
|
+ //rectangle(img, rcttbox, cv::Scalar(100, 100, 100), -1);
|
|
|
+
|
|
|
+
|
|
|
+ // 贴图区域
|
|
|
+ /* 暂不实现 */
|
|
|
+
|
|
|
+ topPos += 200;
|
|
|
+
|
|
|
+
|
|
|
+ ///////////////////////////////////////// 主干区域: y 起始坐标:360/////////////////////////////////////////////
|
|
|
+ Json::Value root(Json::arrayValue);
|
|
|
+
|
|
|
+ // +指定像素
|
|
|
+ auto yhPadding = [&](cv::Rect & rcBox,int pd) {
|
|
|
+ rcBox.x += pd;
|
|
|
+ rcBox.y += pd;
|
|
|
+ rcBox.width -= (pd * 2);
|
|
|
+ rcBox.height -= (pd * 2);
|
|
|
+ };
|
|
|
+
|
|
|
+ // json valule
|
|
|
+ auto addValueToJson = [&](Json::Value & root, cv::Rect rcbox, cv::Rect rcNum, cv::Rect rcQues, cv::Rect rcAns,
|
|
|
+ int iQNum, std::string strTgInfo, std::string strSolution) {
|
|
|
+ //生成识别信息
|
|
|
+ Json::Value ttbox;
|
|
|
+ ttbox["x"] = rcbox.x;
|
|
|
+ ttbox["y"] = rcbox.y;
|
|
|
+ ttbox["width"] = rcbox.width;
|
|
|
+ ttbox["height"] = rcbox.height;
|
|
|
+
|
|
|
+ Json::Value queNum;
|
|
|
+ queNum["x"] = rcNum.x;
|
|
|
+ queNum["y"] = rcNum.y;
|
|
|
+ queNum["width"] = rcNum.width;
|
|
|
+ queNum["height"] = rcNum.height;
|
|
|
+
|
|
|
+ Json::Value queInfo;
|
|
|
+ queInfo["x"] = rcQues.x;
|
|
|
+ queInfo["y"] = rcQues.y;
|
|
|
+ queInfo["width"] = rcQues.width;
|
|
|
+ queInfo["height"] = rcQues.height;
|
|
|
+ queInfo["info"] = strTgInfo.c_str();
|
|
|
+ queInfo["solution"] = strSolution.c_str();
|
|
|
+
|
|
|
+ Json::Value ansInfo;
|
|
|
+ ansInfo["x"] = rcAns.x;
|
|
|
+ ansInfo["y"] = rcAns.y;
|
|
|
+ ansInfo["width"] = rcAns.width;
|
|
|
+ ansInfo["height"] = rcAns.height;
|
|
|
+
|
|
|
+ Json::Value item;
|
|
|
+ item["id"] = iQNum;
|
|
|
+ item["ttbox"] = ttbox;
|
|
|
+ item["queNum"] = queNum;
|
|
|
+ item["queInfo"] = queInfo;
|
|
|
+ item["ansInfo"] = ansInfo;
|
|
|
+
|
|
|
+ root.append(item);
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+#if QQM_ADD
|
|
|
+ topPos += 50; // 间隔预留
|
|
|
+ int pd = 3;
|
|
|
+ cv::Size exampleSize(512+ pd *2, 512+ pd *2); // 示例图size
|
|
|
+ int exdis = 20; // 示例图之间水平方向间隔
|
|
|
+ int eydis = 50; //
|
|
|
+ int bigDrawBoxNum = 2;
|
|
|
+ int smlDrawBoxNum = 2 * 4;
|
|
|
+ int iQNum = 1;
|
|
|
+ /*
|
|
|
+ ---------------------------------------------
|
|
|
+ | | | |
|
|
|
+ |示例大图1 |绘画区域1 |绘画区域2 |
|
|
|
+ | | | |
|
|
|
+ ---------------------------------------------
|
|
|
+ | | | |
|
|
|
+ |示例大图2 |... | |
|
|
|
+ | | | |
|
|
|
+ ---------------------------------------------
|
|
|
+ | |1 |2 |1 |2 |
|
|
|
+ |示例小图3 |-----------|-----------|
|
|
|
+ | |3 |4 |3 |4 |
|
|
|
+ ----------------------------------------------
|
|
|
+ */
|
|
|
+ int eleft = max(0, (img.cols - (exampleSize.width + 20) * max_line) / 2);
|
|
|
+ for (auto ex = 0; ex < max_line; ex++) {
|
|
|
+ //int _left = eleft + (exampleSize.width + 20)*ex;
|
|
|
+ // 基础信息准备
|
|
|
+ int _left = eleft;
|
|
|
+ int _top = topPos + (exampleSize.height + eydis)*ex;
|
|
|
+ cv::Rect box(_left, _top, exampleSize.width, exampleSize.height);
|
|
|
+ rectangle(img, box, cv::Scalar(0), 2, 8, 0);
|
|
|
+ string strTgInfo = std::get<0>(vecLines[ex]);
|
|
|
+ string strSolution = std::get<1>(vecLines[ex]);
|
|
|
+ int _type = atoi(strSolution.c_str()); // 1 big 0 small
|
|
|
+
|
|
|
+ // 示例图贴图
|
|
|
+ cv::Mat _img = cv::imread(strTgInfo, cv::IMREAD_ANYCOLOR);
|
|
|
+ CV_Assert(!_img.empty());
|
|
|
+ cv::Mat _rsImg;
|
|
|
+ if (_type)
|
|
|
+ _rsImg = paddingResize(_img, exampleSize.width, exampleSize.height);
|
|
|
+ else {
|
|
|
+ cv::Mat _rsImg4 = paddingNoResize(_img, exampleSize.width/2, exampleSize.height/2);
|
|
|
+ _rsImg = cv::Mat(exampleSize, _img.type(), cv::Scalar(255, 255, 255));
|
|
|
+ _rsImg = splitAndInsertImages(_rsImg4, _rsImg);
|
|
|
+ cv::line(_rsImg, cv::Point(0, exampleSize.height / 2), cv::Point(exampleSize.width - 1, exampleSize.height / 2), cv::Scalar(0), 1, 8, 0);
|
|
|
+ cv::line(_rsImg, cv::Point(exampleSize.width / 2, 0), cv::Point(exampleSize.width / 2, exampleSize.height - 1), cv::Scalar(0), 1, 8, 0);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ cv::Mat _bin;
|
|
|
+ cv::cvtColor(_rsImg, _bin, cv::COLOR_BGR2GRAY);
|
|
|
+ cv::threshold(_bin, _bin, 200, 255, THRESH_BINARY);
|
|
|
+ cv::cvtColor(_bin, _rsImg, cv::COLOR_GRAY2BGR);
|
|
|
+ _rsImg.copyTo(img(box));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 绘图区域
|
|
|
+ int ttW = 20; int ttH = 20; // 填涂框
|
|
|
+ int __left = _left + box.width + exdis;
|
|
|
+ int __top = _top;
|
|
|
+ int __w = exampleSize.width * 2 + exdis;
|
|
|
+ int __h = exampleSize.height;
|
|
|
+ if (_type) {
|
|
|
+ for (auto n = 0; n < bigDrawBoxNum; n++) {
|
|
|
+ cv::Rect __box(__left+n*(exampleSize.width+exdis), __top, exampleSize.width, exampleSize.height);
|
|
|
+ cv::rectangle(img, __box, cv::Scalar(0), 2, 8, 0);
|
|
|
+ // 填涂框子
|
|
|
+ cv::Rect __ttBox(__box.x, __box.y - ttH, ttW, ttH);
|
|
|
+ cv::rectangle(img, __ttBox, cv::Scalar(0), 1, 8, 0);
|
|
|
+ cv::Rect __thBox(__ttBox);
|
|
|
+ cv::Rect __qBox(__ttBox);
|
|
|
+ yhPadding(__box, pd);
|
|
|
+ addValueToJson(root, __ttBox, __ttBox, __ttBox, __box, iQNum++, strTgInfo, strSolution);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ int __col = 4; int __row = 2;
|
|
|
+ int ___disx = 20;
|
|
|
+ int ___disy = 20;
|
|
|
+ int ___w = (__w - ___disx * (__col - 1)) / __col;
|
|
|
+ int ___h = (__h - ___disy * (__row - 1)) / __row;
|
|
|
+ for (auto row = 0; row < __row; row++) {
|
|
|
+ int ___top = __top + row*(___h + ___disy);
|
|
|
+ for (auto col = 0; col < __col; col++) {
|
|
|
+ int ___left = __left + col * (___w + ___disx);
|
|
|
+ cv::Rect ___box(___left, ___top, ___w, ___h);
|
|
|
+ cv::rectangle(img, ___box, cv::Scalar(0), 2, 8, 0);
|
|
|
+ // 填涂框子
|
|
|
+ cv::Rect __ttBox(___box.x, ___box.y - ttH, ttW, ttH);
|
|
|
+ cv::rectangle(img, __ttBox, cv::Scalar(0), 1, 8, 0);
|
|
|
+ cv::Rect __thBox(__ttBox);
|
|
|
+ cv::Rect __qBox(__ttBox);
|
|
|
+ yhPadding(___box, pd);
|
|
|
+ addValueToJson(root, __ttBox, __ttBox, __ttBox, ___box, iQNum++, strTgInfo, strSolution);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // fuick
|
|
|
+ int x = 0;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+#else
|
|
|
+ // 文字区域
|
|
|
+ static int maxLineNum = 14; // 最大行数14
|
|
|
+ static int ttBoxWidth = 30; // 填涂框的边长
|
|
|
+ static int tiSl = 10; // 题号和题干间的距离
|
|
|
+ static int lineDis = 20; // 两行之间的距离
|
|
|
+ int colWidth = fontW / cols; // 单栏的宽度
|
|
|
+ fSize.width = 0; fSize.height = 0;
|
|
|
+
|
|
|
+ //RNG rng;
|
|
|
+ for (int col = 0; col < cols; col++)
|
|
|
+ { // 逐栏画题
|
|
|
+ int colTopPos = topPos;
|
|
|
+ int colLeftPos = leftPos + col * colWidth;
|
|
|
+ for (size_t i = 0; i < maxLineNum; i++)
|
|
|
+ {
|
|
|
+ size_t vecIndex = i + col * maxLineNum;
|
|
|
+ if (vecIndex >= vecLines.size())
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ colTopPos += lineDis;
|
|
|
+ int lineLen = ttBoxWidth + tiSl;
|
|
|
+ // 画填涂框 30*30 大小
|
|
|
+ cv::Rect rcbox(colLeftPos, colTopPos, ttBoxWidth, ttBoxWidth);
|
|
|
+ rectangle(img, rcbox, cv::Scalar(0), 1, 8, 0);
|
|
|
+
|
|
|
+ int iQNum = i + 1 + col * maxLineNum;
|
|
|
+ string strStinfo = to_string(iQNum); strStinfo += ".";
|
|
|
+ cv::Point ptNum(colLeftPos + ttBoxWidth + tiSl, colTopPos);
|
|
|
+ putTextZH(img, fSize, strStinfo.c_str(), ptNum, Scalar(0, 0, 0), fontSize, "宋体"); // 跟填涂框保持10px距离
|
|
|
+ lineLen += fSize.width;
|
|
|
+ cv::Rect rcNum(ptNum.x, ptNum.y, fSize.width, fSize.height);
|
|
|
+
|
|
|
+ strStinfo.clear();
|
|
|
+ string strTgInfo = std::get<0>(vecLines[vecIndex]);
|
|
|
+ string strSolution = std::get<1>(vecLines[vecIndex]);
|
|
|
+ if (!engShow)
|
|
|
+ ; /* 移除词性 */
|
|
|
+ //char szTemp[2048];
|
|
|
+ //memset(szTemp, 0, sizeof(char)*(2048));
|
|
|
+ //UTF82ANSI(strTgInfo.c_str(), strTgInfo.length(), szTemp, 2048);
|
|
|
+ //strTgInfo = szTemp;
|
|
|
+ cv::Point ptQues(colLeftPos + ttBoxWidth + tiSl + fSize.width, colTopPos);
|
|
|
+ putTextZH(img, fSize, strTgInfo.c_str(), ptQues, Scalar(0, 0, 0), fontSize, "宋体"); // 跟填涂框保持10px距离
|
|
|
+ lineLen += fSize.width;
|
|
|
+ cv::Rect rcQues(ptQues.x, ptQues.y, fSize.width, fSize.height);
|
|
|
+ cv::Rect rcAns(colLeftPos + 30, colTopPos + fSize.height, colWidth - ttBoxWidth, 1);
|
|
|
+
|
|
|
+ colTopPos = colTopPos + fSize.height * 3.5; //两行之间两倍的距离用于书写
|
|
|
+ //lineGrayPix = rng.operator ()(220);
|
|
|
+ line(img, cv::Point(colLeftPos + 30, colTopPos), cv::Point(colLeftPos + colWidth - 1, colTopPos), Scalar(lineGrayPix, lineGrayPix, lineGrayPix), 1, 8, 0);
|
|
|
+ rcAns.height = colTopPos - rcAns.y + lineDis;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //生成识别信息
|
|
|
+ Json::Value ttbox;
|
|
|
+ ttbox["x"] = rcbox.x;
|
|
|
+ ttbox["y"] = rcbox.y;
|
|
|
+ ttbox["width"] = rcbox.width;
|
|
|
+ ttbox["height"] = rcbox.height;
|
|
|
+ #if QQM_ADD
|
|
|
+ cv::rectangle(img, rcbox, cv::Scalar(0, 0, 244), 1, 8, 0);
|
|
|
+ #endif // QQM_ADD
|
|
|
+
|
|
|
+
|
|
|
+ Json::Value queNum;
|
|
|
+ queNum["x"] = rcNum.x;
|
|
|
+ queNum["y"] = rcNum.y;
|
|
|
+ queNum["width"] = rcNum.width;
|
|
|
+ queNum["height"] = rcNum.height;
|
|
|
+ #if QQM_ADD
|
|
|
+ cv::rectangle(img, rcNum, cv::Scalar(0, 255, 244), 1, 8, 0);
|
|
|
+ #endif // QQM_ADD
|
|
|
+
|
|
|
+ Json::Value queInfo;
|
|
|
+ queInfo["x"] = rcQues.x;
|
|
|
+ queInfo["y"] = rcQues.y;
|
|
|
+ queInfo["width"] = rcQues.width;
|
|
|
+ queInfo["height"] = rcQues.height;
|
|
|
+ queInfo["info"] = strTgInfo.c_str();
|
|
|
+ queInfo["solution"] = strSolution.c_str();
|
|
|
+ #if QQM_ADD
|
|
|
+ cv::rectangle(img, rcQues, cv::Scalar(215, 0, 244), 1, 8, 0);
|
|
|
+ #endif // QQM_ADD
|
|
|
+
|
|
|
+ Json::Value ansInfo;
|
|
|
+ ansInfo["x"] = rcAns.x;
|
|
|
+ ansInfo["y"] = rcAns.y;
|
|
|
+ ansInfo["width"] = rcAns.width;
|
|
|
+ ansInfo["height"] = rcAns.height;
|
|
|
+ #if QQM_ADD
|
|
|
+ cv::rectangle(img, rcAns, cv::Scalar(225, 120, 244), 1, 8, 0);
|
|
|
+ #endif // QQM_ADD
|
|
|
+
|
|
|
+ Json::Value item;
|
|
|
+ item["id"] = iQNum;
|
|
|
+ item["ttbox"] = ttbox;
|
|
|
+ item["queNum"] = queNum;
|
|
|
+ item["queInfo"] = queInfo;
|
|
|
+ item["ansInfo"] = ansInfo;
|
|
|
+
|
|
|
+ root.append(item);
|
|
|
+
|
|
|
+ // test
|
|
|
+ /*rectangle(img, rcbox, cv::Scalar(0, 0, 200), 1, 8, 0);
|
|
|
+ rectangle(img, rcNum, cv::Scalar(0, 200, 0), 1, 8, 0);
|
|
|
+ rectangle(img, rcQues, cv::Scalar(100, 0, 0), 1, 8, 0);
|
|
|
+ rectangle(img, rcAns, cv::Scalar(200, 0, 0), 1, 8, 0);*/
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+#endif // QQM_ADD
|
|
|
+
|
|
|
+
|
|
|
+ std::string strJson = JsonToString(root);
|
|
|
+
|
|
|
+ CString strTemplatePath;
|
|
|
+ strTemplatePath.Format(L"%s/json/%d.json", dir, index);
|
|
|
+ CFile zip;
|
|
|
+ zip.Open(strTemplatePath, CFile::modeCreate | CFile::modeWrite);
|
|
|
+ zip.Write((void*)strJson.c_str(), strJson.length());
|
|
|
+ zip.Close();
|
|
|
+
|
|
|
+ wchar_t tempPath[MAX_PATH];
|
|
|
+ DWORD dwSize = MAX_PATH;
|
|
|
+ GetTempPath(dwSize, tempPath);//获取临时文件夹路径
|
|
|
+ static int tmp_index = 1;
|
|
|
+ wchar_t szPath[MAX_PATH];
|
|
|
+ _stprintf(szPath, L"%stmp_%d.png", tempPath, tmp_index);
|
|
|
+ tmp_index++;
|
|
|
+ if (tmp_index > 10)
|
|
|
+ {
|
|
|
+ tmp_index = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ strPngPath = TstringToGB2312(szPath);
|
|
|
+ cv::imwrite(strPngPath, img);
|
|
|
+
|
|
|
+
|
|
|
+ /*cv::namedWindow("fuck", 1);
|
|
|
+ cv::imshow("fuck", img);
|
|
|
+ cv::waitKey(0);*/
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
int dataCollectionPaper(int cols, int index, int fontSize, int lineGrayPix, bool engShow, std::vector<tuple<string, string>>& vecLines, CString dir, std::string& strPngPath, std::string tips) {
|
|
|
/* 这里要做一些栏数 和 vecLines的对应值确认 */
|
|
|
if (2 == cols && 14 * 2 == vecLines.size())
|
|
@@ -445,7 +853,7 @@ int dataCollectionPaper(int cols, int index, int fontSize, int lineGrayPix, bool
|
|
|
rcttbox.width -= 2;
|
|
|
rcttbox.height -= 2;
|
|
|
rectangle(img, rcttbox, cv::Scalar(100, 100, 100), -1);
|
|
|
-
|
|
|
+
|
|
|
// 贴图区域
|
|
|
/* 暂不实现 */
|
|
|
|
|
@@ -498,12 +906,13 @@ int dataCollectionPaper(int cols, int index, int fontSize, int lineGrayPix, bool
|
|
|
lineLen += fSize.width;
|
|
|
cv::Rect rcQues(ptQues.x, ptQues.y, fSize.width, fSize.height);
|
|
|
cv::Rect rcAns(colLeftPos + 30, colTopPos + fSize.height, colWidth - ttBoxWidth, 1);
|
|
|
-
|
|
|
+
|
|
|
colTopPos = colTopPos + fSize.height * 3.5; //两行之间两倍的距离用于书写
|
|
|
//lineGrayPix = rng.operator ()(220);
|
|
|
line(img, cv::Point(colLeftPos + 30, colTopPos), cv::Point(colLeftPos + colWidth - 1, colTopPos), Scalar(lineGrayPix, lineGrayPix, lineGrayPix), 1, 8, 0);
|
|
|
rcAns.height = colTopPos - rcAns.y + lineDis;
|
|
|
|
|
|
+
|
|
|
//生成识别信息
|
|
|
Json::Value ttbox;
|
|
|
ttbox["x"] = rcbox.x;
|
|
@@ -511,12 +920,15 @@ int dataCollectionPaper(int cols, int index, int fontSize, int lineGrayPix, bool
|
|
|
ttbox["width"] = rcbox.width;
|
|
|
ttbox["height"] = rcbox.height;
|
|
|
|
|
|
+
|
|
|
Json::Value queNum;
|
|
|
queNum["x"] = rcNum.x;
|
|
|
queNum["y"] = rcNum.y;
|
|
|
queNum["width"] = rcNum.width;
|
|
|
queNum["height"] = rcNum.height;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
Json::Value queInfo;
|
|
|
queInfo["x"] = rcQues.x;
|
|
|
queInfo["y"] = rcQues.y;
|
|
@@ -525,19 +937,21 @@ int dataCollectionPaper(int cols, int index, int fontSize, int lineGrayPix, bool
|
|
|
queInfo["info"] = strTgInfo.c_str();
|
|
|
queInfo["solution"] = strSolution.c_str();
|
|
|
|
|
|
+
|
|
|
Json::Value ansInfo;
|
|
|
ansInfo["x"] = rcAns.x;
|
|
|
ansInfo["y"] = rcAns.y;
|
|
|
ansInfo["width"] = rcAns.width;
|
|
|
ansInfo["height"] = rcAns.height;
|
|
|
|
|
|
+
|
|
|
Json::Value item;
|
|
|
item["id"] = iQNum;
|
|
|
item["ttbox"] = ttbox;
|
|
|
item["queNum"] = queNum;
|
|
|
item["queInfo"] = queInfo;
|
|
|
item["ansInfo"] = ansInfo;
|
|
|
-
|
|
|
+
|
|
|
root.append(item);
|
|
|
|
|
|
// test
|
|
@@ -548,8 +962,8 @@ int dataCollectionPaper(int cols, int index, int fontSize, int lineGrayPix, bool
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- std::string strJson = JsonToString(root);
|
|
|
-
|
|
|
+ std::string strJson = JsonToString(root);
|
|
|
+
|
|
|
CString strTemplatePath;
|
|
|
strTemplatePath.Format(L"%s/json/%d.json", dir, index);
|
|
|
CFile zip;
|
|
@@ -568,11 +982,11 @@ int dataCollectionPaper(int cols, int index, int fontSize, int lineGrayPix, bool
|
|
|
{
|
|
|
tmp_index = 1;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
strPngPath = TstringToGB2312(szPath);
|
|
|
cv::imwrite(strPngPath, img);
|
|
|
|
|
|
-
|
|
|
+
|
|
|
/*cv::namedWindow("fuck", 1);
|
|
|
cv::imshow("fuck", img);
|
|
|
cv::waitKey(0);*/
|
|
@@ -581,7 +995,7 @@ int dataCollectionPaper(int cols, int index, int fontSize, int lineGrayPix, bool
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
return 0;
|
|
|
}
|