0
|
1 #!/usr/bin/env python
|
|
2
|
|
3 import pymctf
|
|
4 import sys
|
|
5 import numpy
|
|
6 import time
|
|
7
|
|
8 # CIF
|
|
9 size = 352, 288
|
|
10 subsampling = 2, 2
|
|
11 chroma_size = size[0]//subsampling[0], size[1]//subsampling[1]
|
|
12
|
|
13 fname = 'foreman-cif.yuv'
|
|
14
|
|
15 f = open(fname, 'rb')
|
|
16 frame0 = f.read(size[0]*size[1] + 2*chroma_size[0]*chroma_size[1])
|
|
17 frame1 = f.read(size[0]*size[1] + 2*chroma_size[0]*chroma_size[1])
|
|
18 f.close()
|
|
19
|
|
20 if not frame0 or not frame1:
|
|
21 print >>sys.stderr, 'failed to read YUV input, exit.'
|
|
22 sys.exit(1)
|
|
23
|
|
24 frame0 = numpy.asarray(numpy.fromstring(frame0[:size[0]*size[1]], numpy.uint8), numpy.float).reshape((size[1], size[0]))
|
|
25 frame1 = numpy.asarray(numpy.fromstring(frame1[:size[0]*size[1]], numpy.uint8), numpy.float).reshape((size[1], size[0]))
|
|
26
|
|
27 sad, mvf = pymctf.motion_estimation(frame0, frame1, blocksize=8, searchrange=32, hlevel=1)
|
|
28
|
|
29 print time.clock()
|
|
30 print sad
|
|
31
|
|
32 sys.exit(0)
|