当前位置:网站首页>将jpg图片转换成yuv420(NV12)数据文件
将jpg图片转换成yuv420(NV12)数据文件
2022-08-04 08:34:00 【鲁破特之泪】
代码功能:将文件夹下所有jpg文件转换成同名的yuv文件。
yuv文件是yuv420(NV12)格式的数据位,文件内容为yyyyyyyyy…uvuvuv…
import os
import cv2
from tqdm import tqdm
def bgr2yuv420bin(path_yuv, img_bgr):
yuv = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2YUV)
y = yuv[:, :, 0]
u = yuv[:, :, 1]
v = yuv[:, :, 2]
u = cv2.resize(u, (int(u.shape[1] / 2), int(u.shape[0] / 2)))
v = cv2.resize(v, (int(v.shape[1] / 2), int(v.shape[0] / 2)))
with open(path_yuv, 'wb') as f:
for row in range(y.shape[0]):
for col in range(y.shape[1]):
f.write(y[row, col])
for row in range(u.shape[0]):
for col in range(u.shape[1]):
f.write(u[row, col])
f.write(v[row, col])
path_jpg = r'/media/fang/Samsung USB/tsr/input_src/weight' # jpg图片路径 不要有中文
path_output = r'/media/fang/3441-913C/tsr/test' # 输出yuv文件路径
for root, dirs, files in os.walk(path_jpg):
for file in tqdm(files):
img = cv2.imread(root + '/' + file)
bgr2yuv420bin(path_output + '/' + file.replace('jpg', 'yuv'), img)
边栏推荐
- C# DirectoryInfo类
- The sorting algorithm including selection, bubble, and insertion
- 尚医通【预约挂号系统】总结
- 占位,稍后补上
- Distributed Computing Experiment 4 Random Signal Analysis System
- 小程序如何使用订阅消息(PHP代码+小程序js代码)
- 【NOI模拟赛】纸老虎博弈(博弈论SG函数,长链剖分)
- 图的基本概念
- 从零开始的tensorflow小白使用指北
- Yolov5 replaces the backbone network of "Megvii Lightweight Convolutional Neural Network ShuffleNetv2"
猜你喜欢
随机推荐
C Language Lectures from Scratch Part 6: Structure
Thread类的基本使用。
Quick tips for getting out of a single
(三)DDD上下文映射图——老师,我俩可是纯洁的男女关系!
【UE虚幻引擎】UE5实现动态导航样条线绘制
The sorting algorithm including selection, bubble, and insertion
【JS 逆向百例】某网站加速乐 Cookie 混淆逆向详解
csdn图片去水印 | 其他方法无效时的解决方案
设计信息录入界面,完成人员基本信息的录入工作,
Implementation of redis distributed lock
力扣 剑指 Offer 04. 二维数组中的查找
spark算子讲解
高等代数_证明_两个矩阵乘积为0,则两个矩阵的秩之和小于等于n
leetcode 22.7.31(1)两数之和 (2)整数除法
【虚幻引擎UE】UE5基于Gltf加载插件实现gltf格式骨骼动画在线/本地导入和切换
如何设计一个注册中心
Occupy, fill in later
小程序如何使用订阅消息(PHP代码+小程序js代码)
从零开始的tensorflow小白使用指北
【Attention】Dual Attention(DANet) & Fully Attention(FLA)