yuv转bgr
【摘要】
import timefrom ctypes import * import cv2 import numpy as np def yuv2bgr(file_name, height, width, start_frame): fp = open(file_name, 'rb') fp.seek(0, 2) # 设置...
-
import time
-
from ctypes import *
-
-
import cv2
-
-
import numpy as np
-
-
-
def yuv2bgr(file_name, height, width, start_frame):
-
fp = open(file_name, 'rb')
-
fp.seek(0, 2) # 设置文件指针到文件流的尾部 + 偏移 0
-
fp_end = fp.tell() # 获取文件尾指针位置
-
-
frame_size = height * width * 3 // 2 # 一帧图像所含的像素个数
-
num_frame = fp_end // frame_size # 计算 YUV 文件包含图像数
-
print("This yuv file has {} frame imgs!".format(num_frame))
-
fp.seek(frame_size * start_frame, 0) # 设置文件指针到文件流的起始位置 + 偏移 frame_size * startframe
-
print("Extract imgs start frame is {}!".format(start_frame + 1))
-
-
start=time.time()
-
yyyy_uv = np.zeros(shape=frame_size, dtype='uint8', order='C')
-
for j in range(frame_size):
-
yyyy_uv[j] = ord(fp.read(1)) # 读取 YUV 数据,并转换为 unicode
-
-
img = yyyy_uv.reshape((height * 3 // 2, width)).astype('uint8') # NV12 的存储格式为:YYYY UV
文章来源: blog.csdn.net,作者:AI视觉网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/120779418
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)