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

  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)
相关推荐
言無咎5 小时前
从人工失误到AI精准:财务机器人如何重构企业财务数据体系
人工智能·重构·机器人
福客AI智能客服6 小时前
专业服务深耕:电商智能客服与AI客服机器人重构日用品行业服务价值
人工智能·重构·机器人
weilaikeqi11112 天前
骏丰科技主动健康达人秀登上北京卫视,大健康行业迎需求重构
人工智能·科技·重构
软件供应链安全指南3 天前
Forrester发布《2025年应用安全状况报告》,复杂性下的防御体系重构
安全·重构
cocodameyou1323 天前
从能量阻滞到流动:解码“被动学习”背后的家庭动能重构逻辑
笔记·学习·其他·百度·微信·重构·课程设计
listhi5203 天前
压缩感知信号重构的块稀疏贝叶斯学习(BSBL)算法:原理、实现与应用
学习·算法·重构
徐礼昭|商派软件市场负责人3 天前
AI 重构网购体验:从 “将就” 到 “讲究” 的消费者进化史|徐礼昭
大数据·人工智能·重构·智能客服·零售·智能搜索·ai推荐
代码游侠3 天前
嵌入式开发代码实践——串口通信(UART)开发
c语言·开发语言·笔记·单片机·嵌入式硬件·重构
Promise微笑4 天前
Geo优化排名因素深度专访:两大核心与四轮驱动的信任重构
人工智能·重构