From 98ea07798402b21bd0493623b3bc2e0d64b1e007 Mon Sep 17 00:00:00 2001 From: WenmuZhou Date: Mon, 1 Feb 2021 13:44:53 +0800 Subject: [PATCH] add det_db_use_dilate config --- deploy/lite/config.txt | 3 ++- deploy/lite/ocr_db_crnn.cc | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/deploy/lite/config.txt b/deploy/lite/config.txt index 670b2ff0..23f0171d 100644 --- a/deploy/lite/config.txt +++ b/deploy/lite/config.txt @@ -2,4 +2,5 @@ max_side_len 960 det_db_thresh 0.3 det_db_box_thresh 0.5 det_db_unclip_ratio 1.6 -use_direction_classify 0 \ No newline at end of file +det_db_use_dilate 0 +use_direction_classify 1 \ No newline at end of file diff --git a/deploy/lite/ocr_db_crnn.cc b/deploy/lite/ocr_db_crnn.cc index 200d3464..6cacfc82 100644 --- a/deploy/lite/ocr_db_crnn.cc +++ b/deploy/lite/ocr_db_crnn.cc @@ -229,6 +229,7 @@ RunDetModel(std::shared_ptr predictor, cv::Mat img, std::map Config) { // Read img int max_side_len = int(Config["max_side_len"]); + int det_db_use_dilate = int(Config["det_db_use_dilate"]); cv::Mat srcimg; img.copyTo(srcimg); @@ -275,10 +276,14 @@ RunDetModel(std::shared_ptr predictor, cv::Mat img, const double maxvalue = 255; cv::Mat bit_map; cv::threshold(cbuf_map, bit_map, threshold, maxvalue, cv::THRESH_BINARY); - cv::Mat dilation_map; - cv::Mat dila_ele = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(2, 2)); - cv::dilate(bit_map, dilation_map, dila_ele); - auto boxes = BoxesFromBitmap(pred_map, dilation_map, Config); + if (det_db_use_dilate == 1) { + cv::Mat dilation_map; + cv::Mat dila_ele = + cv::getStructuringElement(cv::MORPH_RECT, cv::Size(2, 2)); + cv::dilate(bit_map, dilation_map, dila_ele); + bit_map = dilation_map; + } + auto boxes = BoxesFromBitmap(pred_map, bit_map, Config); std::vector>> filter_boxes = FilterTagDetRes(boxes, ratio_hw[0], ratio_hw[1], srcimg); @@ -375,8 +380,7 @@ int main(int argc, char **argv) { auto charactor_dict = ReadDict(dict_path); charactor_dict.insert(charactor_dict.begin(), "#"); // blank char for ctc charactor_dict.push_back(" "); -std: - cout << charactor_dict[0] << " " << charactor_dict[1] << std::endl; + cv::Mat srcimg = cv::imread(img_path, cv::IMREAD_COLOR); auto boxes = RunDetModel(det_predictor, srcimg, Config); -- GitLab