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

  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)
相关推荐
一水鉴天1 天前
整体设计 设计文档修订与重构修改稿 (豆包助手)20260321
人工智能·重构
进击的雷神1 天前
展位号后缀清理、详情页JS数据提取、重试机制控制、地址字段重构——美国NPE展爬虫四大技术难关攻克纪实
javascript·爬虫·python·重构
胡少侠72 天前
LangGraph 多步推理:State + Node + 条件路由,手写 StateGraph
ai·重构·langchain·agent·rag·langgraph
liukuang1102 天前
阿里Q3财报:全栈AI驱动下的价值重构
人工智能·重构
孤影过客2 天前
X86架构黎明:从0xFFFFFFF0开始的内存空间重构与寻址深潜
单片机·重构·架构
胡少侠72 天前
LangChain 重构 RAG:LCEL 管道语法 + 多轮对话记忆
ai·重构·langchain·agent·rag
科技新芯2 天前
当AI龙虾接管购物车,Bidnex用CPS重构数字广告的信任基石
人工智能·重构
sg_knight2 天前
设计模式实战:策略模式(Strategy)
java·开发语言·python·设计模式·重构·架构·策略模式
无忧智库2 天前
碳索未来:数字碳中和综合治理平台的底层逻辑、架构演进与价值重构(WORD)
重构·架构