forked from federicocorrao/Nao-Computer-Vision-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod_videodevice_images_to_avi_2.py
More file actions
88 lines (68 loc) · 2.3 KB
/
mod_videodevice_images_to_avi_2.py
File metadata and controls
88 lines (68 loc) · 2.3 KB
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
# -*- coding: cp1252 -*-
import os, time
from naoqi import ALProxy
import Image # from PIL
import multiprocessing
def recordVideo(duration, fps, ip = '127.0.0.1', port = 9559):
vd = ALProxy("ALVideoDevice", ip, port)
camindex = vd.getActiveCamera()
# todo param
resolution = 2 # VGA
colorspace = 11 # RGB
nameId = 'python_GVM'
nameId = vd.subscribe(nameId, resolution, colorspace, fps)
# vd.setResolution("python_GVM", 2) # non sembra avere effetto
parent = "C:\\Users\\Federico\\Desktop\\"
path = parent + "naoimages\\"
print "recordVideo: Recording"
t0 = time.time()
image_width = 640 # image[0]
image_height = 480 # image[1]
images = []
for i in range(0, duration*fps):
ta = time.time()
print "recordVideo: Frame " + str(i)
image = vd.getImageRemote(nameId)
images.append(image[6])
vd.releaseImage(nameId)
tb = time.time()
#print (1/float(fps)) - (tb - ta)
time.sleep((1/float(fps)) - (tb - ta)) #(float(1/fps))
#time.sleep(1/float(fps))
t1 = time.time()
print "recordVideo: " + str(t1 - t0) + " s elapsed. Done"
vd.unsubscribe(nameId)
for i in range(0, duration*fps):
im = Image.fromstring("RGB", (image_width, image_height), images[i])
im.save(path + str(i) + ".jpeg", "JPEG")
# mencoder
os.chdir("C:\\Users\\Federico\\Desktop\\naoimages\\")
os.system("mencoder mf://*.jpeg -mf w=640:h=480:fps=" + str(fps) +
":type=jpg -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o output.avi")
pass
IP = '127.0.0.1'
Port = 9559
mo = ALProxy("ALMotion", IP, Port)
po = ALProxy("ALRobotPosture", IP, Port)
def loophead():
print "started"
mo.stiffnessInterpolation("Body", 1, 1)
mo.moveInit()
d = 0
while True:
mo.setAngles("HeadYaw", d, 0.1)
time.sleep(1)
d = 1 - d
pass
#
# po.goToPosture("Stand", 0.5)
mo.stiffnessInterpolation("Body", 1, 1)
mo.moveInit()
mo.moveToward(0.5, 0, 0)
# problema: sia recordvideo che loophead vanno in loop e si escludono
# (modo per mettere in coda chiamate asincrone?)
# TODO: rendere lopphead asincrona senza fare impallare tutto
loophead()
#recordVideo(10, 25)
# p = multiprocessing.Process(target = loophead)
# p.start()