admin
2023-02-09 125db633619a0b4c7bd1d498ea2bf1cefa4f73d3
ConsoleApplication/LimitUpCapture.cpp
@@ -13,6 +13,7 @@
bool LimitUpCapture::kill;
CallbackFun_Limit_Up LimitUpCapture::data_callback;
MatOcrFun  LimitUpCapture::ocr_fun;
std::list<cv::Point> LimitUpCapture::pointList;
@@ -45,7 +46,7 @@
         clock_t start = clock();
         try {
            list<LimitUpData> codes = captureLimitUpCodes();
            cout << "耗时:" << clock() - start << "  数量:" << codes.size() << endl;
            //cout << "耗时:" << clock() - start << "  数量:" << codes.size() << endl;
            data_callback(codes, context);
            codes.clear();
         }
@@ -62,8 +63,9 @@
bool LimitUpCapture::pause;
void LimitUpCapture::init(CallbackFun_Limit_Up callback, void* contex) {
void LimitUpCapture::init(CallbackFun_Limit_Up callback, MatOcrFun matMcrFun, void* contex) {
   data_callback = callback;
   ocr_fun = matMcrFun;
   context = contex;
   running = false;
   kill = false;
@@ -136,63 +138,19 @@
      throw string("未获取到内容窗口的菜单句柄");
   //查找菜单的位置
   cv::Mat grayImg = ImgUtil::grayImage(CaptureUtil::capture(menuWin));
   int full_start = -1;
   int full_end = -1;
   int start_row = -1;
   int end_row = -1;
   int count = 0;
   pointList.clear();
   for (int r = grayImg.rows - 1;r>=0;r --) {
      if (ImgDivider::isRowFull(grayImg,r,0, grayImg.cols-1,2,33,48)) {
         if (full_start < 0)
         {
            full_start = r;
            full_end = r;
         }
         else {
            full_end = r;
         }
         if (start_row > 0 && end_row > 0 && (start_row - end_row) > 5) {
            count++;
            printf("%d-%d\n", start_row, end_row);
            full_start = r;
            full_end = r;
            string path = "C:\\Users\\Administrator\\Desktop\\ocr\\menu\\";
            path.append("menu_").append(to_string(count)).append(".jpg");
            //cv::imwrite(path, cv::Mat(grayImg,cv::Rect(0,end_row,grayImg.cols,start_row-end_row)));
            pointList.push_back(cv::Point(  ( 0 + grayImg.cols)/2, (start_row + end_row)/2));
            if (pointList.size() >= 2) {
               break;
            }
            start_row = -1;
            end_row = -1;
   list<OCRResult> ocrResultList = ocr_fun("今日", grayImg);
   if (ocrResultList.size() > 0) {
      for (list<OCRResult>::iterator ele = ocrResultList.begin(); ele != ocrResultList.end(); ele++) {
         OCRResult result = *ele;
         pointList.push_back(cv::Point((result.rect.left+result.rect.right)/2, (result.rect.top + result.rect.bottom) / 2));
         ImgUtil::markMat(grayImg, cv::Rect(result.rect.left, result.rect.top, result.rect.right - result.rect.left +1, result.rect.bottom - result.rect.top + 1), 255, 1);
         }
      }
      else {
         if (full_start >= 0)
         {
            if (start_row < 0)
            {
               start_row = r;
               end_row = r;
            }
            else {
               end_row = r;
            }
         }
      }
   }
   //cv::imwrite("C:\\Users\\Administrator\\Desktop\\ocr\\menu.jpg", );
   //保存临时图片
   //cv::imwrite("C:\\Users\\Administrator\\Desktop\\ocr\\menu.jpg", grayImg);
}
bool LimitUpCapture::isRunning() {