您可能在谈论这样的事情。当我完全成功 OCR 时,我将分享我的经验 :)
cv::vector<cv::Mat> produceThresholds(const cv::Mat img_gray) {
const int THRESHOLD_COUNT = 4;
// Mat img_equalized = equalizeBrightness(img_gray);
cv::vector<cv::Mat> thresholds;
for (int i = 0; i < THRESHOLD_COUNT; i++)
thresholds.push_back(cv::Mat(img_gray.size(), CV_8U));
int i = 0;
// Adaptive
// adaptiveThreshold(img_gray, thresholds[i++], 255, ADAPTIVE_THRESH_MEAN_C,
// THRESH_BINARY_INV , 7, 3);
// adaptiveThreshold(img_gray, thresholds[i++], 255, ADAPTIVE_THRESH_MEAN_C,
// THRESH_BINARY_INV , 13, 3);
// adaptiveThreshold(img_gray, thresholds[i++], 255, ADAPTIVE_THRESH_MEAN_C,
// THRESH_BINARY_INV , 17, 3);
// Wolf
int k = 0, win = 18;
// NiblackSauvolaWolfJolion (img_gray, thresholds[i++], WOLFJOLION, win, win,
// 0.05 + (k * 0.35));
// bitwise_not(thresholds[i-1], thresholds[i-1]);
NiblackSauvolaWolfJolion(img_gray, thresholds[i++], WOLFJOLION, win, win,
0.05 + (k * 0.35));
//bitwise_not(thresholds[i - 1], thresholds[i - 1]);
k = 1;
win = 22;
NiblackSauvolaWolfJolion(img_gray, thresholds[i++], WOLFJOLION, win, win,
0.05 + (k * 0.35));
//bitwise_not(thresholds[i - 1], thresholds[i - 1]);
// NiblackSauvolaWolfJolion (img_gray, thresholds[i++], WOLFJOLION, win, win,
// 0.05 + (k * 0.35));
// bitwise_not(thresholds[i-1], thresholds[i-1]);
// Sauvola
k = 1;
NiblackSauvolaWolfJolion(img_gray, thresholds[i++], SAUVOLA, 12, 12,
0.18 * k);
bitwise_not(thresholds[i - 1], thresholds[i - 1]);
k = 2;
NiblackSauvolaWolfJolion(img_gray, thresholds[i++], SAUVOLA, 12, 12,
0.18 * k);
//bitwise_not(thresholds[i - 1], thresholds[i - 1]);
return thresholds;
// threshold(img_equalized, img_threshold, 100, 255, THRESH_BINARY);
}