File: bounding_box_and_polygon.py

package info (click to toggle)
pyzbar 0.1.9-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 284 kB
  • sloc: python: 889; sh: 20; makefile: 16
file content (24 lines) | stat: -rwxr-xr-x 572 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
"""Writes bounding_box_and_polygon.png that illustrates
"""
from PIL import Image, ImageDraw

from pyzbar.pyzbar import decode


image = Image.open('pyzbar/tests/qrcode_rotated.png').convert('RGB')
draw = ImageDraw.Draw(image)
for barcode in decode(image):
    rect = barcode.rect
    draw.rectangle(
        (
            (rect.left, rect.top),
            (rect.left + rect.width, rect.top + rect.height)
        ),
        outline='#0080ff'
    )

    draw.polygon(barcode.polygon, outline='#e945ff')


image.save('bounding_box_and_polygon.png')