-
Notifications
You must be signed in to change notification settings - Fork 3
/
action_data_creator.py
executable file
·85 lines (65 loc) · 1.8 KB
/
action_data_creator.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
import rospy
import sys
try:
sys.path.remove('/opt/ros/kinetic/lib/python2.7/dist-packages')
except:
pass
# print('yeah!')
from std_msgs.msg import Int32
import sys, select, termios, tty
import os, time, signal, threading
from subprocess import call
from subprocess import Popen
import subprocess
import numpy as np
import cv2
global proc
import csv
def getKey():
tty.setraw(sys.stdin.fileno())
rlist, _, _ = select.select([sys.stdin], [], [], 0.1)
if rlist:
key = sys.stdin.read(1)
else:
key = ''
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)
return key
if __name__=="__main__":
settings = termios.tcgetattr(sys.stdin)
rospy.init_node('stairybot_teleop')
pub = rospy.Publisher('in_put', Int32 , queue_size=10)
x = 9
status = 0
count = 0
cap = cv2.VideoCapture(1)
csv_data = [['FileName','Action']]
while(True):
csv_row = []
key = getKey()
ret, frame = cap.read()
if key is not '' or count > 0 :
if key == ' ' :
x = 0
elif key == 'w' :
x = 5
elif key == 'd' :
x = 2
elif key == 's' :
x = 4
elif key == 'a' :
x = 3
elif (key == '\x03'):
break
pub.publish(x)
count= count + 1
print(x)
imagename = "image" + str(count) + ".jpg"
cv2.imwrite(imagename,frame)
csv_row.append(imagename)
csv_row.append(x)
csv_data.append(csv_row)
with open('record.csv', 'w') as csvFile:
writer = csv.writer(csvFile)
writer.writerows(csv_data)
csvFile.close()
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)