资源简介
我自己写的,不好别骂。
代码片段和文件信息
import cv2
import numpy as np
# 块大小
Block_Size = 8
# 保存上一个块的DC系数
DC_y = 0
DC_cr = 0
DC_cb = 0
# zig zag方向
right = 0
down = 1
right_up = 2
left_down = 3
# 亮度量化表
Luminance_Quantization_Table = [
[16 11 10 16 24 40 51 61]
[12 12 14 19 26 58 60 55]
[14 13 16 24 40 57 69 56]
[14 17 22 29 51 87 80 62]
[18 22 37 56 68 109 103 77]
[24 35 55 64 81 104 113 92]
[49 64 78 87 103 121 120 101]
[72 92 95 98 112 100 103 99]
]
# 色度量化表
Chrominance_Quantization_Table = [
[17 18 24 47 99 99 99 99]
[18 21 26 66 99 99 99 99]
[24 26 56 99 99 99 99 99]
[47 66 99 99 99 99 99 99]
[99 99 99 99 99 99 99 99]
[99 99 99 99 99 99 99 99]
[99 99 99 99 99 99 99 99]
[99 99 99 99 99 99 99 99]
]
def quantize(block: np.ndarray flag: int = 0):
res = np.zeros((Block_Size Block_Size) np.float32)
if flag:
# 色度量化
for row in range(Block_Size):
for col in range(Block_Size):
res[row][col] = int(block[row][col] / Chrominance_Quantization_Table[row][col] + 0.5)
else:
# 亮度量化
for row in range(Block_Size):
for col in range(Block_Size):
res[row][col] = int(block[row][col] / Luminance_Quantization_Table[row][col] + 0.5)
return res
def inverse_quantize(block: np.ndarray flag: int = 0):
res = np.zeros((Block_Size Block_Size) np.float32)
if flag:
# 色度量化
for row in range(Block_Size):
for col in range(Block_Size):
res[row][col] = int(block[row][col] * Chrominance_Quantization_Table[row][col] + 0.5)
else:
# 亮度量化
for row in range(Block_Size):
for col in range(Block_Size):
res[row][col] = int(block[row][col] * Luminance_Quantization_Table[row][col] + 0.5)
return res
def encode(block: np.ndarray flag: int):
“““
对块进行DC差分编码和AC行程编码
:param block:
:return: 两个编码结果
“““
global DC_y DC_cr DC_cb
res_code = []
# DC差分编码
if flag == 0:
res_code.append(block[0][0] - DC_y)
DC_y = block[0][0]
elif flag == 1:
res_code.append(block[0][0] - DC_cr)
DC_cr = block[0][0]
elif flag == 2:
res_code.append(block[0][0] - DC_cb)
DC_cb = block[0][0]
# AC行程编码
zero_count = 0
# zig zag遍历
row = 0
col = 1
act = left_down
while row != Block_Size and col != Block_Size:
# 对当前数字进行处理
if block[row][col]:
res_code.append((zero_count block[row][col]))
zero_count = 0
else:
zero_count += 1
if zero_count == 16:
res_code.append((15 0))
zero_count = 0
else:
if row == Block_Size - 1 and col == Block_Size - 1:
res_code.append((zero_count - 1 0))
# 迭代
if act == right:
相关资源
- 树莓派利用python、opencv、PyALPR识别车
- 人脸识别UI Pythone+pyq5+opencv 多线程模式
- 基于Python的双路视频传输及双显示系
- python调用opencv实现人脸识别的简单D
- 树莓派小车物体追踪
- OpenCV动作识别
- 基于OpenCV的python颜色提取
- 火焰检测代码python
- python,Opencv实现的车牌识别定位及分
- python+opencv实现初步手势识别源码(本
- opencv实时识别指定物体
- OpenCV 3.x with Python By Example 2nd .txt
- 基于Python-opencv的车牌识别
- 基于OpenCV SIFT的指纹识别算法 python实
- Python+OpenCV实现Selective Search算法
- python opencv 图片去噪
- Python+OpenCV实现行人检测含配置说明
- python+opencv识别出物体颜色红白黑蓝绿
- opencv_python-3.4.3.18-cp37-cp37m-linux_armv7l
- 基于OpenCV的人脸识别-python3.zip
- pyinstaller打包OpenCV错误解决
- Python OpenCV 图像使用-
- Python OpenCV 类型转换-
- Python给照片换底色(基于opencv模块)
- OPENCV视频头调用
- 基于opencv和tkinter的图像处理GUI-源代码
- Python OpenCV 图像轮廓-.zip
- Python OpenCV 形态学操作-.zip
- Python OpenCV 傅里叶变换-.zip
- Python OpenCV 图像运算-.zip
评论
共有 条评论