二维码图像超分辨率重构-数据集下载及预处理

  1. 数据集下载
    参考 https://www.kaggle.com/datasets/coledie/qr-codes/data
python 复制代码
import os
import cv2
import numpy as np
import qrcode

FOLDER = 'qr_dataset'

if not os.path.isdir(FOLDER):
    os.mkdir(FOLDER)

for data in np.random.choice(np.arange(1000, 10000), size=2500, replace=False):
    for version in [1, 2, 3, 4]:
        qr = qrcode.QRCode(
            version=version,
            error_correction=qrcode.constants.ERROR_CORRECT_M,
            box_size=10,
            border=4
        )
        qr.add_data(data)
        qr.make(fit=True)

        img = qr.make_image(fill_color='black', back_color='white')
        img = np.float32(np.asarray(img)) * 255
        img = np.dstack((img, img, img))

        cv2.imwrite(os.path.join(FOLDER, f"{data}-v{version}.png"), img)
  1. 数据集增强处理

sing-srgan-for-qr-code-enhancement 用到的增强操作如下:

c 复制代码
datagen = ImageDataGenerator(        
        rotation_range = 40,
        shear_range = 0.2,
        zoom_range = 0.2,
        horizontal_flip = True,
        brightness_range = (0.5, 1.5))

可结合上面操作,设计增强操作,比如

python 复制代码
            # 1. 旋转
            angle = np.random.uniform(-15, 15)
            degraded = rotate_image(degraded, angle)
            
            # 2. 失焦模糊
            blur_radius = np.random.uniform(2.0, 5.0)
            degraded = cv2.GaussianBlur(degraded, (0, 0), sigmaX=blur_radius, sigmaY=blur_radius)
            
            # 3. 运动模糊
            if np.random.rand() > 0.5:
                ksize = np.random.choice([9, 15, 21])
                degraded = apply_motion_blur(degraded, kernel_size=ksize)
            
            # 4. 下采样
            scale = np.random.uniform(0.15, 0.4)
            h, w = degraded.shape
            small = cv2.resize(degraded, (int(w * scale), int(h * scale)), interpolation=cv2.INTER_AREA)
            degraded = cv2.resize(small, (w, h), interpolation=cv2.INTER_LINEAR)
            
            # 5. JPEG 压缩
            encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), np.random.randint(10, 40)]
            _, encimg = cv2.imencode('.jpg', degraded, encode_param)
            degraded = cv2.imdecode(encimg, 0)
            
            # 6. 噪声
            noise = np.random.normal(0, np.random.uniform(10, 30), degraded.shape)
            degraded = np.clip(degraded + noise, 0, 255).astype(np.uint8)
相关推荐
GEO行业研究员4 天前
AI是否正在重构个体在健康相关场景中的决策路径——基于系统建模与决策链条结构分析的讨论
人工智能·算法·重构·geo优化·医疗geo·医疗geo优化
微学AI4 天前
从云端到指尖:重构 AI 终端生态与实体交互新范式
人工智能·重构·交互
带你看月亮4 天前
第 2 章:重构的原则
重构·模块测试·极限编程
科技云报道5 天前
2025,AI Agent时代的主动防御:安全防御体系的重构之年
人工智能·安全·重构
创客匠人老蒋5 天前
创客匠人:2026知识付费“生死局”,AI智能体如何重构“交付”价值?
大数据·人工智能·重构
xiaoginshuo5 天前
2026 RPA 价值重构:AI 时代从需求到生态深度解读
人工智能·重构·rpa
南_山无梅落5 天前
从传统Web到API驱动:使用Django REST Framework重构智能合同审查系统
重构·django·vue·drf
没有bug.的程序员5 天前
订单系统重构史诗:从单体巨兽到微服务矩阵的演进、数据一致性内核与分布式事务
java·微服务·矩阵·重构·分布式事务·数据一致性·订单系统
death_ray5 天前
第 2 章:重构的原则
重构·阅读
The Open Group5 天前
开放流程自动化™标准:不是“更好的控制系统”,而是一次工业自动化协作方式的重构
运维·重构·自动化