0

我正在尝试设置 JimFlow(http://jimflow.jimdo.com/)。

我设法设置了几乎所有东西,但是我遇到了 JimFlowKlopfer 的问题(它是一个 python 脚本,可以扫描 QR 码并输出一个 JSON 文件),因为我对 Python 不太了解,而且我的谷歌搜索对我没有帮助,我现在问你:-)

当脚本尝试扫描 QR 码时,我总是收到此错误:

python -m jimflowklopfer.__main__ ~/Dokumente/projekte/work/qrCodes/ ~/Dokumente/projekte/work/output


list index out of range

在这种情况下,我不知道“索引超出范围”是什么意思。

如果有人可以帮助我或给我一个提示问题可能是什么,那就太好了:-)

问候

4

1 回答 1

0

我想当我把它贴在这里时,它看起来更好:-P

import zbar
import Image
import ImageDraw
import kanban

class Scanner(object):
    def __init__(self, imagepath):
        self.image = Image.open(imagepath).convert('L')
        self.width, self.height = self.image.size
        self.informations = []
        # create a reader
        self.scanner = zbar.ImageScanner()
        # configure the scanner
        self.scanner.set_config(0, zbar.Config.ENABLE, 0)
        self.scanner.set_config(zbar.Symbol.QRCODE, zbar.Config.ENABLE, 1)

def image_optimize(self):
    doubled_size = (self.image.size[0] * 2, self.image.size[1] * 2)
    self.image = self.image.resize(doubled_size, Image.ANTIALIAS)
    self.width, self.height = self.image.size

def scan(self):
    self.image_optimize()
    pieces_size = int(self.get_qr_code_size() * 2)
    step_size = int(pieces_size / 4)
    self.scan_image(self.image,0,0)
    y_start = 0

    iy = 0
    while y_start < self.height:
        y_start = iy * step_size
        y_end = y_start + pieces_size
        iy += 1
        ix = 0
        x_start = 0
        while x_start < self.width:
            x_start = ix * step_size
            x_end = x_start + pieces_size
            crop_to = (x_start, y_start, x_end, y_end)
            img_crop = self.image.crop(crop_to)
            self.scan_image(img_crop, x_start, y_start)
            ix += 1

    return self.informations

def get_qr_code_size(self):
    zbar_img = zbar.Image(self.width, self.height, 'Y800', self.image.tostring())php

    qr_sizes = []

    print(qr_sizes)
    # scan the image for barcodes
    self.scanner.scan(zbar_img)
    for symbol in zbar_img:
        qr_width = symbol.location[3][0] - symbol.location[0][0]
        qr_height = symbol.location[1][1] - symbol.location[0][1]
        qr_sizes.append(qr_width)
        qr_sizes.append(qr_height)
    if len(qr_sizes) == 0:
        raise IOError('Klopfer says: no qr code scanned')

    return sum(qr_sizes, 0.0) / len(qr_sizes)

def scan_image(self, img_scan, x_start, y_start):
    crop_width, crop_height = img_scan.size
    zbar_img = zbar.Image(crop_width, crop_height, 'Y800', img_scan.tostring())

    # scan the image for barcodes
    self.scanner.scan(zbar_img)

    # Create a draw object
    draw = ImageDraw.Draw(self.image)
    draw_crop = ImageDraw.Draw(img_scan)

    for symbol in zbar_img:
        top_left = (symbol.location[0][0] + x_start, symbol.location[0][1] + y_start)
        bottom_left = (symbol.location[1][0] + x_start, symbol.location[1][1] + y_start)
        bottom_right = (symbol.location[2][0] + x_start, symbol.location[2][1] + y_start)
        top_right = (symbol.location[3][0] + x_start, symbol.location[3][1] + y_start)
        self.informations.append(kanban.Information(symbol.data, (top_left, bottom_left, bottom_right, top_right)))
        draw.rectangle([(top_left), (bottom_right)], fill="black")
        draw_crop.rectangle([symbol.location[0], symbol.location[2]], fill="black")
    if len(zbar_img.symbols) > 0:
        self.scan_image(img_scan, x_start, y_start)

这是scanner.py,我认为它坏了。我刚刚意识到我导入的东西(zbar、Image、ImageDraw)是红色下划线的,但是我安装了包,我应该把包放到项目中吗?或者我只是安装它们就足够了。

于 2015-12-14T13:01:37.147 回答