当前位置:网站首页>将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)
边栏推荐
猜你喜欢

(三)DDD上下文映射图——老师,我俩可是纯洁的男女关系!

redis分布式锁的实现

秒懂大模型 | 3步搞定AI写摘要

Distributed Computing Experiment 1 Load Balancing

技术实现 | 图像检索及其在高德的应用

8.2学习记录

inject() can only be used inside setup() or functional components.

Wang Shuang's Assembly Language Chapter 4: The First Program
![[STM32] STM32F103 series name and package, memory](/img/01/073f970c8c05ad24f976b26790ba61.png)
[STM32] STM32F103 series name and package, memory

尚医通【预约挂号系统】总结
随机推荐
通过GBase 8c Platform安装数据库集群时报错
阿里云的数据库系统怎么升级更新的www.zgysffm.com怎么加快访问速度?
【论文笔记】Delving into the Estimation Shift of Batch Normalization in a Network
25.时间序列预测实战
Quick tips for getting out of a single
redis分布式锁的实现
技术实现 | 图像检索及其在高德的应用
给Unity Behavior Designer(Unity行为树) 的Can See Object 画圆锥辅助图
华为设备配置VRRP与路由联动监视上行链路
如何设计一个注册中心
[STM32] STM32F103 series name and package, memory
Occupy, fill in later
【JS 逆向百例】某网站加速乐 Cookie 混淆逆向详解
binder通信实现
安装GBase 8c数据库集群时,报错误码:80000306,显示Dcs cluster not healthy。怎么处理错误呢?
powershell和cmd对比
经典二分法查找的进阶题目——LeetCode33 搜索旋转排序数组
微信消息从发送到接收,经历了什么?如何防止丢包
怎么写专利更容易通过?
线程和进程之间的区别