forked from YuhangSong/DHP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_yuv.py
executable file
·91 lines (83 loc) · 2.23 KB
/
read_yuv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 10 10:48:00 2013
@author: Chen Ming
"""
from numpy import *
screenLevels = 255.0
def yuv_import(filename,dims,numfrm,startfrm):
fp=open(filename,'rb')
blk_size = prod(dims) * 1
fp.seek(blk_size*startfrm,0)
Y=[]
# U=[]
# V=[]
# print dims[0]
# print dims[1]
# d00=dims[0]//2
# d01=dims[1]//2
# print d00
# print d01
Yt=zeros((dims[0],dims[1]),uint8,'C')
# Ut=zeros((d00,d01),uint8,'C')
# Vt=zeros((d00,d01),uint8,'C')
for i in range(numfrm):
for m in range(dims[0]):
for n in range(dims[1]):
#print m,n
Yt[m,n]=ord(fp.read(1))
# for m in range(d00):
# for n in range(d01):
# Ut[m,n]=ord(fp.read(1))
# for m in range(d00):
# for n in range(d01):
# Vt[m,n]=ord(fp.read(1))
Y=Y+[Yt]
# U=U+[Ut]
# V=V+[Vt]
fp.close()
return Y
# def yuv_import(filename,dims,numfrm,startfrm):
# fp=open(filename,'rb')
# blk_size = prod(dims) *3/2
# fp.seek(blk_size*startfrm,0)
# Y=[]
# # U=[]
# # V=[]
# # print dims[0]
# # print dims[1]
# d00=dims[0]//2
# d01=dims[1]//2
# # print d00
# # print d01
# Yt=zeros((dims[0],dims[1]),uint8,'C')
# # Ut=zeros((d00,d01),uint8,'C')
# # Vt=zeros((d00,d01),uint8,'C')
# for i in range(numfrm):
# for m in range(dims[0]):
# for n in range(dims[1]):
# #print m,n
# Yt[m,n]=ord(fp.read(1))
# # for m in range(d00):
# # for n in range(d01):
# # Ut[m,n]=ord(fp.read(1))
# # for m in range(d00):
# # for n in range(d01):
# # Vt[m,n]=ord(fp.read(1))
# Y=Y+[Yt]
# # U=U+[Ut]
# # V=V+[Vt]
# fp.close()
# return Y
# if __name__ == '__main__':
# data=yuv_import('E:\\new\\test\\ballroom\\ballroom_0.yuv',(480,640),1,0)
# #print data
# #im=array2image(array(data[0][0]))
# YY=data[0][0]
# print YY.shape
# for m in range(2):
# print m,': ', YY[m,:]
#
# im=Image.fromstring('L',(640,480),YY.tostring())
# im.show()
# im.save('f:\\a.jpg')