我正在尝试使用 OpenCV 和 Tesseract 从图像中提取文本。我已经设法检测文本区域并使用边界框来分隔它们。但现在我找不到如何将边界框传递给 Tesseract。
for(int idx = 0; idx >= 0; idx = hierarchy[idx][0])
{
Rect rect = boundingRect(contours[idx]);
Mat maskROI(mask, rect);
maskROI = Scalar(0, 0, 0);
// fill the contour
drawContours(mask, contours, idx, Scalar(255, 255, 255), CV_FILLED);
// ratio of non-zero pixels in the filled region
double r = (double)countNonZero(maskROI)/(rect.width*rect.height);
if (r > .45 /* assume at least 45% of the area is filled if it contains text */
&&
(rect.height > 8 && rect.width > 8) …Run Code Online (Sandbox Code Playgroud)