4

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):

enter image description here

So am I doing something wrong here? What is the correct way to calculate the bounding box of the barcode?

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • The documentation link in your post says, “this is currently not a polygon, but the scan locations where the symbol was decoded”. Looking at [one of their example images](https://sourceforge.net/p/zbar/screenshot/234713.jpg), it looks similar to your case – it seems it's not a boundary at all, but rather a collection of points related to the extraction algorithm. It seems you’re out of luck… – mindriot May 20 '16 at 20:25
  • @mindriot Since the bounty is going to expire can you post it as an answer? That way I can award you the bounty, your answer is valid, even if I am out of luck. – sashoalm May 24 '16 at 19:03
  • Since I didn't really manage to provide a _solution_, don't worry about the bounty. – mindriot May 24 '16 at 21:43

1 Answers1

3

The documentation link in your post says, “this is currently not a polygon, but the scan locations where the symbol was decoded”. Looking at one of their example images, it looks similar to your case – it seems it's not a boundary at all, but rather a collection of points related to the location at which the extraction algorithm determined that a symbol was successfully decoded. From the documentation it seems you’re out of luck, as there is no other functionality to obtain geometric data.

While your SO question did not result in any useful answers, you may want to try the support links on their website.

mindriot
  • 5,413
  • 1
  • 25
  • 34