2015-12-14 45 views
0

我試圖設置JimFlow(http://jimflow.jimdo.com/)。在本地機器上設置JimFlow

我設法幾乎設置了所有東西,但即時通訊面臨與JimFlowKlopfer(這是一個python腳本,掃描QR碼和輸出JSON文件)的問題,因爲我不太瞭解Python和我的谷歌搜索沒有幫助我IM現在問你:-)

我總是讓當腳本試圖掃描QR碼這個錯誤:我不知道什麼是「索引超出範圍」是指在這種情況下

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


list index out of range 

將是很好,如果有人能幫助我或者給我一個提示什麼問題可以:-)

格爾茨

+0

向我們展示了代碼失敗的部分(請參閱stacktrace) – maazza

回答

0

我認爲,當IM張貼在這裏,它看起來更好:-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)是紅色的下劃線,但我安裝了軟件包,我應該把軟件包放到項目中嗎?或者當我安裝它們時就足夠了。

相關問題