OpenCV将JPEG中的progressive类型转换成baseline类型

本文介绍了如何使用OpenCV库将JPEG图像从渐进式编码转换为基线式编码。渐进式JPEG先显示模糊的低质量图像,随着下载逐步提高清晰度,而基线JPEG采用逐行显示的方式。文中提供了具体的Python代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

《OpenCV系列教程》
项目位置:OpenCV-Sample
代码位置:31-CovertJPEGProgressiveToBaseline.py

Baseline:

Baseline JPEG 是图片创建使用的加压算法,用于逐行显示。

在这里插入图片描述

Progressive:

Progressive JPEG以这样的方式显示图像:它整体显示模糊/低质量的照片,然后随着图像的下载变得更清晰。
在这里插入图片描述

代码如下:

import cv2
import os
import string
from PIL import Image

file_dir = './res/'

def progressive_to_baseline(path, file):
    tmpfile = 'tmp' + file
    print(tmpfile)
    img = cv2.imread(path + file)

    cv2.imwrite(path + tmpfile, img)
    os.remove(path + file)
    os.rename(path + tmpfile, path + file)

for file in os.listdir(file_dir):
    #ret = os.system('identify -verbose ' + file_dir + file + ' | grep Interlace')
    ret = os.popen('file ' + file_dir + file)
    lines = ret.readlines()
    if 'progressive,' in str(lines):
        print(file_dir + file)
        progressive_to_baseline(file_dir, file)

最好使用identify -verbose但是这个效率太低了。所以换成了file

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值