Example: 04-Barcodes/find_barcodes.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 条形码检测示例
#
# 本示例展示如何利用OpenMV Cam M7轻松实现条形码检测
# (注意:M4相机不支持条形码检测功能)。

import sensor
import image
import time
import math

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)  # 高分辨率!
sensor.set_windowing((640, 80))  # V分辨率设为80可减少工作量(40则速度翻倍)。
sensor.skip_frames(time=2000)
sensor.set_auto_gain(False)  # 必须关闭此功能以防止图像褪色...
sensor.set_auto_whitebal(False)  # 必须关闭此功能以防止图像褪色...
clock = time.clock()

# 条码检测可在OpenMV Cam的完整640x480分辨率下运行
# OV7725 camera module. Barcode detection will also work in RGB565 mode but at
# a lower resolution. That said, barcode detection requires a higher resolution
# to work well so it should always be run at 640x480 in grayscale...


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 = sensor.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 ""