在本地计算机上设置JimFlow

2024-05-20 03:13:59 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我试着设置了几乎所有的东西,但是我遇到了一个关于JimFlowKlopfer的问题(这是一个python脚本,可以扫描QR码并输出JSON文件),因为我对python不太了解,我的google搜索也帮不了我,我现在问你:-)

当脚本试图扫描二维码时,我总是遇到这个错误:

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


list index out of range

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

如果有人能帮我或者给我一个问题的提示就好了:-)

格里茨


Tags: 文件脚本comjsonhttpgoogleworkqr
1条回答
网友
1楼 · 发布于 2024-05-20 03:13:59

我想当我把它贴在这里,它看起来更好:-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)

这就是扫描仪.py,我想它断了。我刚刚意识到我导入的东西(zbar,Image,ImageDraw)是红色下划线的,但是我安装了包,我应该把包放到项目中吗?或者我刚安装的时候就够了。你知道吗

相关问题 更多 >