Browse Source

【bug修复】(黄根)增加图像腐蚀逻辑,以解决二维码图片泛白而无法被识别出来的问题
【工作量】6h
【评审人】

huanggen 1 year ago
parent
commit
72a0fda04c
1 changed files with 5 additions and 2 deletions
  1. 5 2
      app/src/main/cpp/paperPreIdentify.cpp

+ 5 - 2
app/src/main/cpp/paperPreIdentify.cpp

@@ -125,8 +125,11 @@ string paperPreIdentify::readQrCode(PaperPage sPage)
         Mat roiMat = tImg(Rect(0, 0, tImg.cols / 4, tImg.rows / 5));
         Mat imgGray;
         cvtColor(roiMat, imgGray, CV_BGR2GRAY);  // 灰度化
+        erode(imgGray, imgGray, Mat());     //图片腐蚀,缩小高亮(白色)区域
+//        imwrite("/storage/emulated/0/Pictures/AAA.jpg", imgGray);
+//        //OpenCV自带的QRCode识别方法
 //        QRCodeDetector tDetector;
-//        strRet = tDetector.detectAndDecode(roiMat);
+//        string strRet1 = tDetector.detectAndDecode(imgGray);
         m_nAnchorsToQrCode = 0;
         strRet = ZbarDecoder(imgGray, m_nAnchorsToQrCode);
         if (strRet.length() > 0)
@@ -135,7 +138,7 @@ string paperPreIdentify::readQrCode(PaperPage sPage)
         {
             roiMat = tImg(Rect(tImg.cols * 3 / 4, tImg.rows * 4 / 5, tImg.cols / 4, tImg.rows / 5));
             cvtColor(roiMat, imgGray, CV_BGR2GRAY);
-//            strRet = tDetector.detectAndDecode(roiMat);
+            erode(imgGray, imgGray, Mat());     //图片腐蚀,缩小高亮(白色)区域
             //opencv容易出现识别出二维码但是decode返回空的问题,改用ZBar库识别二维码
             strRet = ZbarDecoder(imgGray, m_nAnchorsToQrCode);
             m_nAnchorsToQrCode += tImg.rows * 4 / 5;