Beispiel #1
0
    def check_degree():
        if request.method == 'GET':
            return render_template('index.html', js_folder=url_for('static', filename='js'),
                                   img_folder=url_for('static', filename='img'),
                                   css_folder=url_for('static', filename='css'),
                                   verif=1)
        horizon = Horizon()
        try:
            # In this part we try to get the hash of the transaction in order to fetch it from horizon. The hash is easier to get from text,
            # that's why it's the first test.
            if 'txhash' in request.form and request.form.get('txhash'):
                tx = horizon.transaction(request.form.get('txhash'))
            elif 'txqr' in request.files:
                # If a qrcode is submitted, we have to save it to decode it, which causes security issues.
                qr = request.files.get('txqr')
                # if user does not select file, browser also
                # submit an empty part without filename
                if qr.filename == '':
                    raise Exception("Vous devez spécifier au moins un hash OU un qrcode")
                else:
                    if app.allowed_filename(qr.filename):
                        fname = secure_filename(qr.filename)
                        fpath = os.path.join(os.getcwd(), 'static', fname)
                        qr.save(fpath)
                        data = qreader.read(fpath)
                        os.remove(fpath) # We don't need it anymore
                        tx = horizon.transaction(data)
                    else:
                        raise Exception("Merci de ne passer que des images générées par ce site")
            else:
                raise Exception("Vous devez spécifier au moins un hash OU un qrcode")

            # Hashing infos from the form to check the hash with the one in the transaction's memo
            name = request.form.get('name')
            birthdate = request.form.get('birthdate')
            year = request.form.get('year')
            h = hash128((name+birthdate+year).encode())
            if h == tx.get('memo'):
                return render_template('index.html', js_folder=url_for('static', filename='js'),
                                       img_folder=url_for('static', filename='img'),
                                       css_folder=url_for('static', filename='css'),
                                       verif=1, verif_passed=1, id=tx.get('source_account'),
                                       name=name, birthdate=birthdate, year=year)
            else:
                return render_template('index.html', js_folder=url_for('static', filename='js'),
                                       img_folder=url_for('static', filename='img'),
                                       css_folder=url_for('static', filename='css'),
                                       verif=1, veriferror="Les informations saisies ne correspondent pas avec l'exemplaire du diplôme décerné")
        except Exception as e:
            return render_template('index.html', js_folder=url_for('static', filename='js'),
                                   img_folder=url_for('static', filename='img'),
                                   css_folder=url_for('static', filename='css'),
                                   verif=1, veriferror=e)
Beispiel #2
0
def qrDecode(img):
    # 读取灰度值
    # 不知道为什么直接使用 cvtColor 转换成灰度图,会多了很多杂点,导致后面二值化后无法分析
    _, _, im_gray = cv2.split(img)
    # im_gray = cv2.cvtColor(out_tmp.astype('uint8'), cv2.COLOR_BGR2GRAY) # 这个方法出来的图片背景很多白色杂点,而二维码本身变成了灰色的
    # 二值化
    _, out_tmp = cv2.threshold(im_gray, 100, 255, cv2.THRESH_BINARY)
    # cv2.imwrite(os.path.join("tmp", "tmp_{0}_{1}.jpg".format(i, j)), out_tmp, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
    # cv2.imshow("threshold", out_tmp)
    # cv2.waitKey(0)
    # 填充二维码中间黑色区域
    kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (25, 25))
    closed = cv2.morphologyEx(out_tmp, cv2.MORPH_CLOSE, kernel)
    # 抹去二维码周边可能存在的小白点
    closed = cv2.erode(closed, None, iterations=4)
    closed = cv2.dilate(closed, None, iterations=4)
    # 不知道是不是前面没有使用cvtColor转换灰度图的原因,后面直接调用findContours会报错,所以这里先将图片合并成一个 BGR的图片,然后再转换成灰度度并再次二值化
    closed = cv2.merge([closed, closed, closed])
    gray = cv2.cvtColor(closed.astype('uint8'), cv2.COLOR_BGR2GRAY)
    _, closed = cv2.threshold(gray, 10, 255, cv2.THRESH_BINARY)
    # 查找轮廓
    _, cnts, _ = cv2.findContours(closed, cv2.RETR_EXTERNAL,
                                  cv2.CHAIN_APPROX_SIMPLE)
    tmp = sorted(cnts, key=cv2.contourArea, reverse=True)
    if len(tmp) == 0:
        return None
    c = tmp[0]
    # 计算包含轮廓的最小矩形面积(对于没有旋转过的图片,其实不需要这一步)
    rect = cv2.minAreaRect(c)
    box = np.int0(cv2.boxPoints(rect))
    Xs = [i[0] for i in box]
    Ys = [i[1] for i in box]
    x1 = min(Xs)
    x2 = max(Xs)
    y1 = min(Ys)
    y2 = max(Ys)
    crop_height = y2 - y1
    crop_width = x2 - x1
    # 裁剪为只包含二维码的图片
    cropImg = out_tmp[y1:y1 + crop_height, x1:x1 + crop_width]
    # 转换为 qreader 可以识别的 pil image
    cropImg = Image.fromarray(cropImg.astype('uint8'))
    # 尝试识别图中的二维码
    try:
        qr_data = qreader.read(cropImg)
        if qr_data:
            # print(data)
            return qr_data
    except:
        return None
## Ref: https://github.com/ewino/qreader

####################################################################################
## IMAGW --> WEBSITE
####################################################################################

picPath = 'C:\\Users\\Aaron.Zheng\\Desktop\\Reading PDF\\BackUpSpace\\Self-Learning\\ProgramCode\\Python\\InstallsPackage\\QRPic.jpg'

## KEY: open img from path
from PIL import Image
import qreader

img2 = Image.open(picPath)
##img2.show()

data = qreader.read(img2)

### Can NOT work



Beispiel #4
0
for i in range(0, 8):
    for j in range(0, 8):

        im_size = im.size

        left = j * 290
        top = i * 290
        width = 290
        height = 290

        box = (left, top, left + width, top + height)

        area = im.crop(box)
        #area.show()

        number = qreader.read(area)
        array.append(number)
        #print str(part) + ": " + str(number)
        #sum += number
        #print area.size
        #area.save("./parts/"+str(part)+".png", "PNG")
        #area.close()
        #part+=1

#print array
#print len(array)
resultat = 0
for element in array:
    resultat += element

#print resultat
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

__author__ = 'ipetrash'

# pip install git+https://github.com/ewino/qreader.git

# SOURCE: https://github.com/tomerfiliba/reedsolomon/blob/master/reedsolo.py
# pip install reedsolo
import qreader

# FROM FILE
data = qreader.read('../qrcode__generate/qr_code_1.png')
print(data)  # Hello World!

# FROM URL
url = 'https://upload.wikimedia.org/wikipedia/commons/8/8f/Qr-2.png'
from urllib.request import urlopen

data = qreader.read(urlopen(url))
print(data)  # "Version 2"

url = 'https://upload.wikimedia.org/wikipedia/commons/e/eb/QR-%D0%BA%D0%BE%D0%B4.png'
data = qreader.read(urlopen(url))
print(data)  # http://ru.wikipedia.org/wiki/QR_Code

# FROM URL as bytes in file-like object
import requests

rs = requests.get(url)
image_data = rs.content
ImportError: No module named request
>>> for i in 's':
	url = 'https://upload.wikimedia.org/wikipedia/commons/8/8f/Qr-2.png'
	data = qreader.read(urllib.urlopen(url))
	print(data)  # prints "Version 2"

	

Traceback (most recent call last):
  File "<pyshell#4>", line 3, in <module>
    data = qreader.read(urllib.urlopen(url))
NameError: name 'qreader' is not defined
>>> import qreader
>>> for i in 's':
	url = 'https://upload.wikimedia.org/wikipedia/commons/8/8f/Qr-2.png'
	data = qreader.read(urllib.urlopen(url))
	print(data)  # prints "Version 2"

	

Traceback (most recent call last):
  File "<pyshell#7>", line 3, in <module>
    data = qreader.read(urllib.urlopen(url))
  File "C:\Python2764\lib\site-packages\qreader\api.py", line 34, in read
    raise TypeError('parameter should be a PIL image object, a file-like object, or a path to an image file')
TypeError: parameter should be a PIL image object, a file-like object, or a path to an image file
>>> import qrcode
>>> help (qrcode)
Help on package qrcode:

NAME
Beispiel #7
0
import qreader
from urllib.request import urlopen
'''
url = 'https://upload.wikimedia.org/wikipedia/commons/8/8f/Qr-2.png'
data = qreader.read(urlopen(url))
print(data)  # prints "Version 2"
'''
'''
url = 'https://img.geocaching.com/cache/large/fcc5a99c-6efb-4d68-bd5b-e4381641f952.gif'
data = qreader.read(urlopen(url))
print(data)  # prints "Version 2"

url = 'https://img.geocaching.com/cache/large/55a3b95b-fb55-4d21-acba-86004256e321.gif'
data = qreader.read(urlopen(url))
print(data)  # prints "Version 2"
'''
'''
import qrtools
from qrtools import qrtools
#qr = qrtools.qrtools.QR()
qr = qrtools.qrtools.QR()
qr.decode("qr_n.gif")
print(qr.data)
'''

# data = qreader.read('qr-2.png')
data = qreader.read('qr_n.gif')
# data = qreader.read('qr_e.gif')
print(data)