使用 ZBar 获取条形码的边界框
Get the barcode's bounding box with ZBar
如何获取 ZBar 中给定矩形的边界框?
目前我使用以下代码从 location polygon 计算它:
for(Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol) {
int pointsCount = symbol->get_location_size();
for (int ii = 0; ii < pointsCount; ++ii) {
int x = symbol->get_location_x(ii);
int y = symbol->get_location_y(ii);
if (!ii) {
r.left = r.right = x;
r.top = r.bottom = y;
}
r.left = std::min(r.left, x);
r.right = std::max(r.right, x);
r.top = std::min(r.top, y);
r.bottom = std::max(r.bottom, y);
}
printf("rect(%d,%d,%d,%d), ", r.left, r.top, r.right, r.bottom);
}
这适用于某些条形码,但我有一张特定图像,其中 ZBar 正确识别条形码文本 - 它是 "CHECK" - 但 returns 10 点作为位置多边形 都在条形码的右上角。
这是它的可视化效果(我将点画成圆圈):
那我是不是做错了什么?计算条形码边界框的正确方法是什么?
您 post 中的文档 link 说,“这目前不是多边形,而是符号被解码的扫描位置”。查看 one of their example images,它看起来与您的情况相似——它似乎根本不是边界,而是与提取算法确定符号已成功解码的位置相关的点集合。从文档看来你运气不好,因为没有其他功能可以获取几何数据。
虽然您的 SO 问题没有得到任何有用的答案,但您可能想在他们的网站上尝试 support links。
如何获取 ZBar 中给定矩形的边界框?
目前我使用以下代码从 location polygon 计算它:
for(Image::SymbolIterator symbol = image.symbol_begin(); symbol != image.symbol_end(); ++symbol) {
int pointsCount = symbol->get_location_size();
for (int ii = 0; ii < pointsCount; ++ii) {
int x = symbol->get_location_x(ii);
int y = symbol->get_location_y(ii);
if (!ii) {
r.left = r.right = x;
r.top = r.bottom = y;
}
r.left = std::min(r.left, x);
r.right = std::max(r.right, x);
r.top = std::min(r.top, y);
r.bottom = std::max(r.bottom, y);
}
printf("rect(%d,%d,%d,%d), ", r.left, r.top, r.right, r.bottom);
}
这适用于某些条形码,但我有一张特定图像,其中 ZBar 正确识别条形码文本 - 它是 "CHECK" - 但 returns 10 点作为位置多边形 都在条形码的右上角。
这是它的可视化效果(我将点画成圆圈):
那我是不是做错了什么?计算条形码边界框的正确方法是什么?
您 post 中的文档 link 说,“这目前不是多边形,而是符号被解码的扫描位置”。查看 one of their example images,它看起来与您的情况相似——它似乎根本不是边界,而是与提取算法确定符号已成功解码的位置相关的点集合。从文档看来你运气不好,因为没有其他功能可以获取几何数据。
虽然您的 SO 问题没有得到任何有用的答案,但您可能想在他们的网站上尝试 support links。