@@ -0,0 +1,1761 @@
+#!/usr/bin/env python%0A# -*- coning: utf-8 -*-%0A########################%0A#File Name:t.py%0A#Author:WmTiger%0A#Mail:bfstiger@gmail.com%0A#Created Time:2016-09-29 20:17:58%0A########################%0A%0Aimport zbar%0Afrom PIL import Image%0A%0Adef deleteDuplicate(data):%0A    news_ids = %5B%5D%0A    dataLen = len(data)%0A    for i in range(0, dataLen):%0A        if data%5Bi%5D not in news_ids:%0A            news_ids.append(data%5Bi%5D)%0A    #print news_ids%0A    return news_ids%0A%0Adef readQR(box, sc, im, name):%0A    lfim = im.crop(box)%0A    lfim.save(name+%22im.jpg%22)%0A    iw,ih = lfim.size%0A    lfraw = lfim.tostring()%0A    lfzim = zbar.Image(iw,ih,'Y800',lfraw)%0A    sc.scan(lfzim)%0A    data = %5B%5D%0A    for sb in lfzim:%0A        data.append(sb.data)%0A    del(lfzim)%0A    return deleteDuplicate(data)%0A%0Adef scanLeft(sc, im, type):%0A    w,h = im.size%0A    if type == 0:%0A        box = (0,0,w/2,h)%0A    elif type == 1:%0A        box = (0,0,w/5*2,h)%0A    return readQR(box, sc, im, 'left')%0A%0Adef scanMiddle(sc, im, type):%0A    w,h = im.size%0A    if type == 1:%0A        box = (w/3,0,w/3*2,h)%0A    return readQR(box, sc, im, 'middle')%0A%0Adef scanRight(sc, im, type):%0A    w,h = im.size%0A    if type == 0:%0A        box = (w/2,0,w,h)%0A    elif type == 1:%0A        box = (w/5*3,0,w,h)%0A    return readQR(box, sc, im, 'right')%0A%0Adef scanImg(type, url = 'test.jpg'):%0A    sc = zbar.ImageScanner()%0A    sc.parse_config(%22enable%22)%0A    with Image.open(url) as im:%0A        data=%5B%5D%0A        if type == 0:%0A            data.append(scanLeft(sc, im, type)%5B0%5D)%0A            data.append(scanRight(sc, im, type)%5B0%5D)%0A        elif type == 1:%0A            data.append(scanLeft(sc, im, type)%5B0%5D)%0A            data.append(scanMiddle(sc, im, type)%5B0%5D)%0A            data.append(scanRight(sc, im, type)%5B0%5D)%0A        return data%0A%0Aif __name__ == '__main__':%0A    print scanImg(0)%0A

add scan