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

  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)
相关推荐
jinanwuhuaguo20 小时前
OpenClaw算力共生体——从Token奴隶到异构计算联邦的经济基础重构(第二十五篇)
大数据·人工智能·重构·安全架构·openclaw
XD74297163620 小时前
科技早报|2026年5月1日:GitHub 为 30 倍规模重构平台
科技·重构·github·科技新闻·开发者工具·科技早报
龙孚信息21 小时前
2026 年企业级 DXP 迁移⽅法论:某跨国⻋企中国站点从 Adobe AEM 到 BMS DXP 的重构实战
adobe·重构
科研前沿1 天前
像素即坐标・室外无边界:2026 最新无感定位技术,驱动数字孪生实景可控—— 镜像视界技术白皮书
大数据·人工智能·算法·重构·空间计算
侠客工坊1 天前
移动端 RPA 的架构重构:基于侠客工坊多模态视觉大模型的自动化调度系统压测复盘
人工智能·智能手机·重构·架构·rpa·数字员工·侠客工坊
x-cmd2 天前
[260429] x-cmd v0.9.1:一键开启 DeepSeek-V4-Pro Max 模式 + 1M 上下文;顺手重构了 uuid 模块
windows·重构·uuid·claude·curl·x-cmd·deepseek-v4-pro
2501_927283582 天前
荣联汇智立体仓库:为智慧工厂搭建高效“骨骼”与“中枢”
大数据·运维·人工智能·重构·自动化·制造
昨夜见军贴06162 天前
供应链合规正在“前移审查”:AI报告审核与IACheck如何重构供应商资质的精准校验逻辑
人工智能·重构
ting94520002 天前
Plurai 深度解析:用 “氛围训练” 重构 AI 智能体可靠性,从原型到生产的全链路解决方案
人工智能·ubuntu·重构
CHENKONG_CK2 天前
RFID 重构半导体晶圆盒智能搬运
人工智能·重构·自动化·制造·rfid·rfid