|
@@ -52,7 +52,7 @@ size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
|
return size * nmemb;
|
|
return size * nmemb;
|
|
}
|
|
}
|
|
|
|
|
|
-string ZbarDecoder(Mat img)
|
|
|
|
|
|
+string ZbarDecoder(Mat img, int & nAnchorsToQrCode)
|
|
{
|
|
{
|
|
string result;
|
|
string result;
|
|
ImageScanner scanner;
|
|
ImageScanner scanner;
|
|
@@ -66,7 +66,10 @@ string ZbarDecoder(Mat img)
|
|
// extract results
|
|
// extract results
|
|
Image::SymbolIterator symbol = image.symbol_begin();
|
|
Image::SymbolIterator symbol = image.symbol_begin();
|
|
if (symbol != image.symbol_end())
|
|
if (symbol != image.symbol_end())
|
|
|
|
+ {
|
|
|
|
+ nAnchorsToQrCode = symbol->get_location_y(0);
|
|
result = symbol->get_data();
|
|
result = symbol->get_data();
|
|
|
|
+ }
|
|
image.set_data(NULL, 0);
|
|
image.set_data(NULL, 0);
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
@@ -75,6 +78,7 @@ paperPreIdentify::paperPreIdentify(int nSchoolId)
|
|
{
|
|
{
|
|
m_nSchoolId = nSchoolId;
|
|
m_nSchoolId = nSchoolId;
|
|
m_sCardId = "";
|
|
m_sCardId = "";
|
|
|
|
+ m_nAnchorsToQrCode = 0;
|
|
}
|
|
}
|
|
|
|
|
|
paperPreIdentify::~paperPreIdentify()
|
|
paperPreIdentify::~paperPreIdentify()
|
|
@@ -118,20 +122,23 @@ string paperPreIdentify::readQrCode(PaperPage sPage)
|
|
{
|
|
{
|
|
string strPath = i == 0 ? sPage.firstPage : sPage.secondPage;
|
|
string strPath = i == 0 ? sPage.firstPage : sPage.secondPage;
|
|
Mat tImg = imread(strPath);
|
|
Mat tImg = imread(strPath);
|
|
- Mat roiMat = tImg(Rect(0, 0, tImg.cols / 4, tImg.rows / 6));
|
|
|
|
|
|
+ Mat roiMat = tImg(Rect(0, 0, tImg.cols / 4, tImg.rows / 5));
|
|
Mat imgGray;
|
|
Mat imgGray;
|
|
cvtColor(roiMat, imgGray, CV_BGR2GRAY); // 灰度化
|
|
cvtColor(roiMat, imgGray, CV_BGR2GRAY); // 灰度化
|
|
- QRCodeDetector tDetector;
|
|
|
|
|
|
+// QRCodeDetector tDetector;
|
|
// strRet = tDetector.detectAndDecode(roiMat);
|
|
// strRet = tDetector.detectAndDecode(roiMat);
|
|
- strRet = ZbarDecoder(imgGray);
|
|
|
|
|
|
+ m_nAnchorsToQrCode = 0;
|
|
|
|
+ strRet = ZbarDecoder(imgGray, m_nAnchorsToQrCode);
|
|
if (strRet.length() > 0)
|
|
if (strRet.length() > 0)
|
|
break;
|
|
break;
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- roiMat = tImg(Rect(tImg.cols * 3 / 4, tImg.rows * 5 / 6, tImg.cols / 4, tImg.rows / 6));
|
|
|
|
|
|
+ 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);
|
|
// strRet = tDetector.detectAndDecode(roiMat);
|
|
//opencv容易出现识别出二维码但是decode返回空的问题,改用ZBar库识别二维码
|
|
//opencv容易出现识别出二维码但是decode返回空的问题,改用ZBar库识别二维码
|
|
- strRet = ZbarDecoder(imgGray);
|
|
|
|
|
|
+ strRet = ZbarDecoder(imgGray, m_nAnchorsToQrCode);
|
|
|
|
+ m_nAnchorsToQrCode += tImg.rows * 4 / 5;
|
|
if (strRet.length() > 0)
|
|
if (strRet.length() > 0)
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -210,7 +217,10 @@ bool paperPreIdentify::getCardTemplate(string strCardId, bool bUseTestIp)
|
|
m_SchemeParam.dImgHeight= root["data"]["pages"][0]["imge"]["height"].asInt();
|
|
m_SchemeParam.dImgHeight= root["data"]["pages"][0]["imge"]["height"].asInt();
|
|
int nAchorsWidth = root["data"]["pages"][0]["location"][0]["width"].asInt();
|
|
int nAchorsWidth = root["data"]["pages"][0]["location"][0]["width"].asInt();
|
|
int nAchorsHeight = root["data"]["pages"][0]["location"][0]["height"].asInt();
|
|
int nAchorsHeight = root["data"]["pages"][0]["location"][0]["height"].asInt();
|
|
|
|
+ int nQrCodeY = root["data"]["pages"][0]["QrCode"]["y"].asInt();
|
|
|
|
+
|
|
m_SchemeParam.dAnchorsHeight = nAchorsHeight;
|
|
m_SchemeParam.dAnchorsHeight = nAchorsHeight;
|
|
|
|
+ m_SchemeParam.nAnchorsToQrcodeDis = nQrCodeY;
|
|
for (int i = 0; i < 4; i++)
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
{
|
|
if (i < 2) {
|
|
if (i < 2) {
|
|
@@ -235,13 +245,18 @@ bool paperPreIdentify::findTopAnchors(Mat tMat)
|
|
{
|
|
{
|
|
//根据图片像素比例调整定位点检查区域高度
|
|
//根据图片像素比例调整定位点检查区域高度
|
|
double dLocPointHeight = m_SchemeParam.dAnchorsHeight;
|
|
double dLocPointHeight = m_SchemeParam.dAnchorsHeight;
|
|
- m_SchemeParam.nAnchorsTopRange = dLocPointHeight * 6 * tMat.rows / m_SchemeParam.dImgHeight;
|
|
|
|
- m_SchemeParam.nAnchorsBottomRange = dLocPointHeight * 7 * tMat.rows / m_SchemeParam.dImgHeight;
|
|
|
|
|
|
+ int nDelta = tMat.rows / m_SchemeParam.dImgHeight;
|
|
|
|
+ m_SchemeParam.nAnchorsTopRange = dLocPointHeight * 6 * nDelta;
|
|
|
|
+ m_SchemeParam.nAnchorsBottomRange = dLocPointHeight * 7 * nDelta;
|
|
|
|
+ if(m_nAnchorsToQrCode > tMat.rows / 2)
|
|
|
|
+ m_SchemeParam.nAnchorsBottomRange = m_nAnchorsToQrCode + (m_SchemeParam.nAnchorsToQrcodeDis - dLocPointHeight) * nDelta - 5;
|
|
|
|
+ else if(m_nAnchorsToQrCode > 0 && m_nAnchorsToQrCode < tMat.rows / 2)
|
|
|
|
+ m_SchemeParam.nAnchorsTopRange = m_nAnchorsToQrCode - (m_SchemeParam.nAnchorsToQrcodeDis - dLocPointHeight) * nDelta + 5;
|
|
int range = m_SchemeParam.nAnchorsTopRange;
|
|
int range = m_SchemeParam.nAnchorsTopRange;
|
|
//LOGFMTI("MyFindDingWeiDian 1 range=%d", range);
|
|
//LOGFMTI("MyFindDingWeiDian 1 range=%d", range);
|
|
CvRect roi[4] = {//上下左右 roi
|
|
CvRect roi[4] = {//上下左右 roi
|
|
cvRect(0, 0, tMat.cols, min(range, tMat.rows)),
|
|
cvRect(0, 0, tMat.cols, min(range, tMat.rows)),
|
|
- cvRect(0, tMat.rows - min(range, tMat.rows) - 1, tMat.cols, min(range, tMat.rows)),
|
|
|
|
|
|
+ cvRect(0, min(tMat.rows - min(range, tMat.rows), m_SchemeParam.nAnchorsBottomRange) - 1, tMat.cols, min(range, tMat.rows)),
|
|
cvRect(0, 0, min(range, tMat.cols), tMat.rows),
|
|
cvRect(0, 0, min(range, tMat.cols), tMat.rows),
|
|
cvRect(tMat.cols - min(range, tMat.cols) - 1, 0, min(range, tMat.cols), tMat.rows)
|
|
cvRect(tMat.cols - min(range, tMat.cols) - 1, 0, min(range, tMat.cols), tMat.rows)
|
|
};
|
|
};
|