find_barcodes.py

# Dieses Werk ist unter der MIT-Lizenz lizenziert.
# Copyright (c) 2013-2023 OpenMV LLC. Alle Rechte vorbehalten.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Barcode-Beispiel
#
# Dieses Beispiel zeigt, wie einfach es ist, Barcodes zu erkennen, und zwar mit der
# OpenMV Cam M7. Die Barcode-Erkennung funktioniert nicht mit der M4-Kamera.

import csi
import image
import time
import math

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.GRAYSCALE)
csi0.framesize(csi.VGA)  # Hohe Auflösung!
csi0.window((640, 80))  # V-Auflösung von 80 == weniger Arbeit (40 für die doppelte Geschwindigkeit).
csi0.snapshot(time=2000)
csi0.auto_gain(False)  # muss dies deaktiviert werden, um ein Überbelichten des Bildes zu vermeiden ...
csi0.auto_whitebal(False)  # muss dies deaktiviert werden, um ein Überbelichten des Bildes zu vermeiden ...

clock = time.clock()

# Die Barcode-Erkennung kann mit der vollen Auflösung von 640x480 Ihrer OpenMV Cam laufen,
# dem OV7725-Kameramodul. Die Barcode-Erkennung funktioniert auch im RGB565-Modus, jedoch bei
# einer geringeren Auflösung. Allerdings benötigt die Barcode-Erkennung eine höhere Auflösung,
# um gut zu funktionieren, daher sollte sie immer mit 640x480 in Graustufen ausgeführt werden ...


def barcode_name(code):
    if code.type == image.EAN2:
        return "EAN2"
    if code.type == image.EAN5:
        return "EAN5"
    if code.type == image.EAN8:
        return "EAN8"
    if code.type == image.UPCE:
        return "UPCE"
    if code.type == image.ISBN10:
        return "ISBN10"
    if code.type == image.UPCA:
        return "UPCA"
    if code.type == image.EAN13:
        return "EAN13"
    if code.type == image.ISBN13:
        return "ISBN13"
    if code.type == image.I25:
        return "I25"
    if code.type == image.DATABAR:
        return "DATABAR"
    if code.type == image.DATABAR_EXP:
        return "DATABAR_EXP"
    if code.type == image.CODABAR:
        return "CODABAR"
    if code.type == image.CODE39:
        return "CODE39"
    if code.type == image.PDF417:
        return "PDF417"
    if code.type == image.CODE93:
        return "CODE93"
    if code.type == image.CODE128:
        return "CODE128"


while True:
    clock.tick()
    img = csi0.snapshot()
    codes = img.find_barcodes()
    for code in codes:
        img.draw_rectangle(code.rect)
        print_args = (
            barcode_name(code),
            code.payload,
            (180 * code.rotation) / math.pi,
            code.quality,
            clock.fps(),
        )
        print(
            'Barcode %s, Payload "%s", rotation %f (degrees), quality %d, FPS %f'
            % print_args
        )
    if not codes:
        print("FPS %f" % clock.fps())

results matching ""

    No results matching ""