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

  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)
相关推荐
manduic1 天前
告别传统编码器痛点!麦歌恩MT6701,重构位置检测选型新逻辑
人工智能·重构·磁性角度传感器
ai大模型中转api测评1 天前
告别文字堆砌:Gemini 交互 API 赋能垂直领域,开发者如何重构用户认知?
人工智能·重构·交互·api
yongyoudayee1 天前
从“记录”到“执行”:CRM的第三次跃迁,销售易引领AI原生重构
重构·ai-native
jiayong231 天前
第 6 课:第二轮真实重构,拆出任务表格组件
前端·重构
APO Research1 天前
Chemical Fiber Oil Global Textile Chemical Market Trends 2026|化学纤维油产业趋势与工程逻辑重构
重构·产业趋势·纺织化学品·功能助剂·工业材料·精细化工
飞翔的SA1 天前
EmDash:WordPress 精神继承者,重构内容管理系统(CMS) 安全与现代架构
安全·重构·架构·cms
jiayong231 天前
第 5 课:第一次真实重构
重构
NINGMENGb1 天前
从“已爆发”到“将爆发”——Infoseek舆情系统重构预警的时间线
重构·舆情系统·舆情监测·舆情监测系统·舆情处置
科技小花2 天前
数据治理平台架构演进观察:AI原生设计如何重构企业数据管理范式
数据库·重构·架构·数据治理·ai-native·ai原生