0% found this document useful (0 votes)
8 views3 pages

Message

Uploaded by

lokhandwalaanas1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Message

Uploaded by

lokhandwalaanas1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

std::string AccuraSDK::TunisiaMappingIntersection(cv::Mat &mat, int dob_top, const

nlohmann::json &arabicJson,
const nlohmann::json
&englishJson) {
int width = mat.cols;
int height = mat.rows;
double templateWidth = 700;
double templateHeight = 320;
int dob_bottom = height;
int dob_right = width;
int ybuffer = dob_bottom - dob_top;

int top_point = 0;
int bottom_point = (int) ((height*150.0)/templateHeight);//134
int top_point2 = (int) ((height*120.0)/templateHeight);//107
int bottom_point2 = (int) ((height*200.0)/templateHeight);//178
int right_point = (dob_right);
cv::cvtColor(mat, mat, cv::COLOR_BGR2RGB);
debugLog("points are dob_top:%d, ybuffer:%d, top_point:%d, bottom_point:%d,
top_point2:%d, bottom_point2:%d, right_point:%d", dob_top, ybuffer, top_point,
bottom_point, top_point2, bottom_point2, right_point);
cv::rectangle(mat, cv::Rect(0, top_point,width-1, bottom_point),
cv::Scalar(0,0,0));
cv::rectangle(mat, cv::Point(0, top_point2), cv::Point(width-1, bottom_point2),
cv::Scalar(255,0,0));
cv::rectangle(mat, cv::Point(0, dob_top), cv::Point(width-1, dob_top),
cv::Scalar(0,255,0));
std::vector<std::string> lineTexts;
std::vector<Recte> lineBoxes;
Recte lastAcceptedBox(-1,-1,-1,-1);
std::string surnamestr="",namestr="";
for (int i = 0; i < arabicJson.size(); ++i) {
auto lineBlock = arabicJson[i];
std::string lineText = lineBlock["text"];
Recte lineRect = Recte(lineBlock["block_l"].get<int>(),
lineBlock["block_t"].get<int>(),
lineBlock["block_r"].get<int>(),
lineBlock["block_b"].get<int>());
cv::rectangle(mat, cv::Point(lineRect.left, lineRect.top),
cv::Point(lineRect.right, lineRect.bottom),
cv::Scalar(0,0,255));

debugLog(" Rect and Text %lu: %s, %s",lineText.size(),


lineRect.toString().c_str() , lineText.c_str());
// if (lineRect.height() >= (height*0.13) && lineRect.height() <=
(height*0.40)
// && (lineRect.bottom + (height*0.032)) <= dob_top
// && (lastAcceptedBox.left == -1 || abs(lineRect.top -
lastAcceptedBox.bottom) < (height*0.015))) {
// lastAcceptedBox = lineRect;
// lineBoxes.emplace_back(lineRect);
// lineTexts.emplace_back(lineText);
// debugLog(" Accepted data : %s, %s", lineRect.toString().c_str() ,
lineText.c_str());
// }
double H = lineRect.height()*0.8;
double overlapHeight1 = min(lineRect.bottom, bottom_point) -
max(lineRect.top, top_point);
double overlapHeight2 = min(lineRect.bottom, bottom_point2) -
max(lineRect.top, top_point2);

if ((lineRect.top >= top_point && lineRect.bottom <= bottom_point) ||


overlapHeight1 >= H /*&& !o.arabicLastName*/) {
// if (surnamestr.empty() && lineText.length()<=3){
// continue;
// }
surnamestr = surnamestr + " " + lineText;
cv::rectangle(mat, cv::Point(lineRect.left, lineRect.top),
cv::Point(lineRect.right, lineRect.bottom),
cv::Scalar(26,200,184), 2);
debugLog(" Accepted data surname : %s, %s", surnamestr.c_str() ,
lineText.c_str());
continue;
}
if ((lineRect.top >= top_point2 && lineRect.bottom <= bottom_point2) ||
overlapHeight2 >= H /*&& !o.name*/) {
// if (namestr.empty() && lineText.length()<=3){
// continue;
// }
namestr = namestr + " " + lineText;
cv::rectangle(mat, cv::Point(lineRect.left, lineRect.top),
cv::Point(lineRect.right, lineRect.bottom),
cv::Scalar(211,170,27), 2);
debugLog(" Accepted data name : %s, %s", namestr.c_str() ,
lineText.c_str());
continue;
}
}
std::string replace_regex =
"[A-Za-z0-9!@#$%^&*()_+=\\-{}\\[\\]|\"':;>.<,?/~`]";
namestr = regex_replace(namestr, std::regex(replace_regex),"");
surnamestr = regex_replace(surnamestr, std::regex(replace_regex),"");
if (!regex_match(surnamestr, regex(emptyString)) && surnamestr.length() > 8){
o.arabicLastName = true;
debugLog("Last Name \"%s\"", surnamestr.c_str());
insertMapData(3, 1, "Last Name", surnamestr);
}
// else NullPointerError(0, "Last Name");
if (!regex_match(namestr, regex(emptyString)) && namestr.length() > 8){
o.name = true;
debugLog("First Name \"%s\"", namestr.c_str());
insertMapData(4, 1, "First Name", namestr);
}
// else NullPointerError(0, "First Name");
json jsonObject;
jsonObject["card_side"] = "FrontSide";
// jsonObject["card_code"] = matRefDataa.code_;
// jsonObject["isApi"] = matRefDataa.isApiCall_;
jsonObject["is_face"] = 1;
if (o.arabicLastName && o.name && !this->o.englishMonthFromArabic.empty()) {
Logger("step Fs end", true);
json mapDataResult;
for (int j = 0,m=0; j < o.mapDataResult.size(); ++j) {
auto firstJsonElement = o.mapDataResult[j];
if (!firstJsonElement.empty()) {
std::string key = firstJsonElement["key"].get<std::string>();
if ((key.find("Date of Birth") != std::string::npos ||
key.find("Date of Issue") != std::string::npos)) {
std::string data =
firstJsonElement["key_data"].get<std::string>();
std::string finalDate =
this->formattingArabicDate(data);//this->o.englishMonthFromArabic;
if (!finalDate.empty()){
firstJsonElement["key_data"] = finalDate;
debugLog("jsonDate:%s, FinalDate:%s",
firstJsonElement["key_data"].get<std::string>().c_str(), finalDate.c_str());
}
}
mapDataResult[m++] = firstJsonElement;
}
}
debugLog("jsonResponse %s", (nlohmann::to_string(mapDataResult)).c_str());
jsonObject["ocr_data"] = mapDataResult;
return createJsonResponse(1, "Success", jsonObject);
} else {
jsonObject["ocr_data"] = nullptr;
return createJsonResponse(0, "Failed", jsonObject);
}
}

You might also like