Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.pyc
*.h5
.idea/
*.pz
28 changes: 28 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os

DEFAULT_IP = 'localhost'
DEFAULT_PORT = 8000
FPS = 10
# FRAME = [480, 320]
FRAME = [320, 160]
base_path = os.getcwd()
output_file_dir = 'video/'
output_file_name = 'capturedVideo.avi'
DIR_PATH = os.path.join(base_path, output_file_dir)
GFILE_PATH = os.path.join(base_path, 'dataset_2_pnc.pz')

if os.path.exists(DIR_PATH):
temp_file_path = os.path.join(DIR_PATH, output_file_name)
if os.path.exists(temp_file_path):
os.remove(temp_file_path)
PATH = temp_file_path
else:
os.mkdir(DIR_PATH)
temp_file_path = os.path.join(DIR_PATH, output_file_name)
if os.path.exists(temp_file_path):
os.remove(temp_file_path)
PATH = temp_file_path




35 changes: 22 additions & 13 deletions dataset
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,53 @@

from deepgtav.messages import Start, Stop, Dataset, frame2numpy, Scenario
from deepgtav.client import Client
from config import *

import argparse
import time
import cv2


# fourcc = cv2.cv.CV_FOURCC('M', 'J', 'P', 'G')
# videoWriter = cv2.VideoWriter(PATH, -1, FPS, (FRAME[0], FRAME[1]))

# Stores a dataset file with data coming from DeepGTAV
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=None)
parser.add_argument('-l', '--host', default='localhost', help='The IP where DeepGTAV is running')
parser.add_argument('-p', '--port', default=8000, help='The port where DeepGTAV is running')
parser.add_argument('-d', '--dataset_path', default='dataset.pz', help='Place to store the dataset')
parser.add_argument('-l', '--host', default=DEFAULT_IP, help='The IP where DeepGTAV is running')
parser.add_argument('-p', '--port', default=DEFAULT_PORT, help='The port where DeepGTAV is running')
parser.add_argument('-d', '--dataset_path', default=GFILE_PATH, help='Place to store the dataset')
args = parser.parse_args()

# Creates a new connection to DeepGTAV using the specified ip and port.
# If desired, a dataset path and compression level can be set to store in memory all the data received in a gziped pickle file.
client = Client(ip=args.host, port=args.port, datasetPath=args.dataset_path, compressionLevel=9)

# Configures the information that we want DeepGTAV to generate and send to us.
# See deepgtav/messages.py to see what options are supported
dataset = Dataset(rate=30, frame=[320,160], throttle=True, brake=True, steering=True, vehicles=True, peds=True, reward=[15.0, 0.0], direction=None, speed=True, yawRate=True, location=True, time=True)
dataset = Dataset(rate=FPS, frame=FRAME, throttle=True, brake=True, steering=True, vehicles=True, peds=True,
reward=[15.0, 0.0], direction=None, speed=True, yawRate=True, location=True, time=True)
# Send the Start request to DeepGTAV.
scenario = Scenario(drivingMode=[786603,15.0]) # Driving style is set to normal, with a speed of 15.0 mph. All other scenario options are random.
client.sendMessage(Start(dataset=dataset,scenario=scenario))
scenario = Scenario(drivingMode=[786603,
15.0]) # Driving style is set to normal, with a speed of 15.0 mph. All other scenario options are random.
client.sendMessage(Start(dataset=dataset, scenario=scenario))

# Start listening for messages coming from DeepGTAV. We do it for 80 hours
stoptime = time.time() + 80*3600
stoptime = time.time() + 10 * 60
while time.time() < stoptime:
try:
# We receive a message as a Python dictionary
message = client.recvMessage()

# The frame is a numpy array and can be displayed using OpenCV or similar
# image = frame2numpy(message['frame'], (320,160))
message = client.recvMessage()

# The frame is a numpy array and can be displayed using OpenCV or similar
image = frame2numpy(message['frame'], (FRAME[0], FRAME[1]))

# cv2.imshow('img',image)
# cv2.waitKey(-1)
except KeyboardInterrupt:
break


# videoWriter.release()
# We tell DeepGTAV to stop
client.sendMessage(Stop())
client.close()
Empty file modified drive
100755 → 100644
Empty file.
54 changes: 54 additions & 0 deletions read.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import cv2
import gzip
from config import *
import pickle
from deepgtav.messages import frame2numpy

def parserCommands(dct):
"""
parse the Commands from every frame and return
:param dct: dct read from the file
:return: throttle, brake and steering
"""
return dct['throttle'], dct['brake'], dct['steering']

def parserState(dct):
"""
return the dict including the state of the vehicle
:param dct: dct read from the file
:return: location list, speed and yawRate
"""
stateDict = {}
stateDict['location'] = dct['location']
stateDict['speed'] = dct['speed']
stateDict['yawRate'] = dct['yawRate']
return stateDict

if __name__ == '__main__':
command_list = []
state_list = []
frame_list = []
# open the dataset.pz file
with gzip.open(
filename=GFILE_PATH, mode='rb', compresslevel=0
) as f:

while True:
try:
dct = pickle.load(f)
# show frame
frame = frame2numpy(dct['frame'], (FRAME[0], FRAME[1]))
# frame_list.append(frame)
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

# get command and state of the vehicle
throttle, brake, steering = parserCommands(dct)
stateDict = parserState(dct)
# command_list.append((throttle, brake, steering))
# state_list.append(stateDict)
except EOFError:
break

cv2.destroyAllWindows()