from PIL import Image from pyzbar.pyzbar import decode, ZBarSymbol # 打开原始图片和替换图片 original_image = Image.open('D:\\cache\\Desktop\\your_image.jpg') replacement_image = Image.open('D:\\cache\\Desktop\\test.jpg') # 识别并解码二维码 decoded_objects = decode(original_image, symbols=[ZBarSymbol.QRCODE]) # 遍历解码出的每个二维码 for obj in decoded_objects: # 获取二维码的位置 (x, y, w, h) = obj.rect # 在原始图片中截取二维码区域 qrcode_region = original_image.crop((x, y, x + w, y + h)) # 将截取的二维码区域替换为替换图片 replacement_region = replacement_image.crop((0, 0, w, h)) original_image.paste(replacement_region, (x, y)) # 展示替换后的图片 original_image.save("D:\\cache\\Desktop\\test222.jpg") # original_image.show()
from PIL import Image from pyzbar.pyzbar import decode, ZBarSymbol import requests import io # 打开原始图片和替换图片 original_image = Image.open('D:\\cache\\Desktop\\your_image.jpg') # replacement_image = Image.open('D:\\cache\\Desktop\\test.jpg') response = requests.get('https://qhftdx.cn/resource/Certificate/images/avatar-1.jpg') replacement_image = Image.open(io.BytesIO(response.content)) # 识别并解码二维码 decoded_objects = decode(original_image, symbols=[ZBarSymbol.QRCODE]) # 遍历解码出的每个二维码 for obj in decoded_objects: # 获取二维码的位置 (x, y, w, h) = obj.rect # 在原始图片中截取二维码区域 qrcode_region = original_image.crop((x, y, x + w, y + h)) # 将截取的二维码区域替换为替换图片 replacement_region = replacement_image.crop((0, 0, w, h)) original_image.paste(replacement_region, (x, y)) # 展示替换后的图片 original_image.save("D:\\cache\\Desktop\\test222.jpg") # original_image.show()
上一篇:Jenkins部署方式
下一篇:大模型扫盲系列——初识大模型