How can I get the bounding box for a given rectangle in ZBar?
Currently I calculate it from the location polygon using this code:
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);
}
This works well for some barcodes, but I have one particular image, where ZBar correctly recognizes the barcode text - it's "CHECK" - but returns 10 points as the location polygon that are all lying on the right corner of the barcode.
Here's how it looks visualized (I drew the points as circles):
So am I doing something wrong here? What is the correct way to calculate the bounding box of the barcode?