from pyzbar import pyzbar from PIL import Image import cv2 import os PATH = './qrssssssss_revenge' os.chdir(PATH) text = '' for i in os.listdir(): qrcode = cv2.imread(i) data = pyzbar.decode(qrcode) text += data[0].data.decode('utf-8') print(text)
from pyzbar import pyzbar from PIL import Image import cv2 import os PATH = './qrssssssss_revenge' block_size = 20 width,height = 660,660 def Errorlevel(images): #获取纠错级别 level_list = ['1111','1010','0101','0000'] #L M Q H L,M,Q,H = [],[],[],[] for img in images: level = '' m = Image.open(img) h = block_size * 8 + block_size // 2 # + block_size //2 是为了找方块中心区域识别 for i in range(0,block_size*2,block_size): w = i + block_size//2 rgb = m.getpixel((w,h)) if rgb == 255: level += "0" else: level += "1" w = block_size * 8 + block_size // 2 for i in range(0,block_size*2,block_size): h = height - (i + block_size//2) rgb = m.getpixel((w,h)) if rgb == 255: level += "0" else: level += "1" if level in level_list: eval('LMQH'[level_list.index(level)]).append(img) return [L,M,Q,H] os.chdir(PATH) image_names = [] text = '' for i in os.listdir(): image_names.append(i) for level in Errorlevel(image_names): text = '' for img in level: qrcode = cv2.imread(img) data = pyzbar.decode(qrcode) text += data[0].data.decode('utf-8') print(text)
from PIL import Image from pyzbar import pyzbar import os import cv2 PATH = './qrssssssss_revenge' #_revenge block_size = 20 width,height = 660,660 def Mask(image): #获取二维码的掩码 res = ['']*8 for k in image: img = Image.open(k) qrcode = cv2.imread(k) data = pyzbar.decode(qrcode) text = data[0].data.decode('utf-8') mask = '' h = block_size * 8 + block_size // 2 for i in range(0,block_size*3,block_size): w = block_size * 2 + i + block_size//2 rgb = img.getpixel((w,h)) if rgb == 255: mask += "0" else: mask += "1" #得到的二进制数据 与 101 异或得到原掩码 mask_ = int(mask,2) ^ 0b101 res[mask_] = text result = ''.join(res) print(k,mask,text) return result def Errorlevel(images): #获取纠错级别 level_list = ['1111','1010','0101','0000'] #L M Q H L,M,Q,H = [],[],[],[] for img in images: level = '' m = Image.open(img) h = block_size * 8 + block_size // 2 for i in range(0,block_size*2,block_size): w = i + block_size//2 rgb = m.getpixel((w,h)) if rgb == 255: level += "0" else: level += "1" w = block_size * 8 + block_size // 2 for i in range(0,block_size*2,block_size): h = height - (i + block_size//2) rgb = m.getpixel((w,h)) if rgb == 255: level += "0" else: level += "1" if level in level_list: eval('LMQH'[level_list.index(level)]).append(img) return [L,M,Q,H] def main(image_names): images = Errorlevel(image_names) #创建同一纠错列表 flag = '' for n in images: flag += Mask(n) #按照掩码排序 print(f'[+] {flag}') os.chdir(PATH) image_names = [] for i in os.listdir(): image_names.append(i) main(image_names)