Example #1
0
def main():
    '''
    Main
    '''
    signal.signal(signal.SIGINT, ctrl_c_handler)
    parser = build_parser()
    args = parser.parse_args()

    if args.save:
        rec_folder = "rec_%s" % time.strftime("%d_%m_%Y_%H_%M_")
        rec_folder = os.path.join(config.pre_path, rec_folder)
        rec_dirs = [rec_folder + '/' + str(i) for i in range(2)]
        for directory in rec_dirs:
            if not os.path.exists(directory):
                os.makedirs(directory)

    cam_1_conf = config.camera_parser_config('camera_1.ini')
    cam_2_conf = config.camera_parser_config('camera_2.ini')
    disp_conf = config.display_parser_config('display.ini')
    cam_1 = Camera('cam_1', cam_1_conf)
    cam_2 = Camera('cam_2', cam_2_conf)
    atexit.register(cleanup, [cam_1, cam_2])
    pygame.init()
    screen = pygame.display.set_mode(disp_conf['doshape'])
    surface = [pygame.Surface(disp_conf['oshape']) for i in range(2)]

    running = True
    img_ind = 0
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
        image_1 = cam_1.get()
        image_2 = cam_2.get()
        pygame.pixelcopy.array_to_surface(surface[0], image_1)
        pygame.pixelcopy.array_to_surface(surface[1], image_2)
        screen.blit(surface[0], (0, 0))
        screen.blit(surface[1], (disp_conf['oshape'][0], 0))
        pygame.display.flip()
        if args.save:
            file_1_name = 'img_%05d.bmp' % img_ind
            file_2_name = 'img_%05d.bmp' % img_ind
            file_1_name = os.path.join(rec_dirs[0], file_1_name)
            file_2_name = os.path.join(rec_dirs[1], file_2_name)
            pygame.image.save(surface[0], file_1_name)
            pygame.image.save(surface[1], file_2_name)
            img_ind += 1
    cam_1.stop()
    cam_2.stop()
    pygame.quit()
Example #2
0
 def __init__(self, name, disp_conf, cam_confs, cam_num=2):
     '''
     Init function for Display
     '''
     if cam_num < 0 or not cam_confs:
         raise DisplayError("Display object has no cameras to instantiate.")
     self.cam_list = []
     for i in range(cam_num):
         cam_conf = config.camera_parser_config(cam_confs[i])
         cam = camera.Camera('cam_' + str(i + 1), cam_conf)
         self.cam_list.append(cam)
     self.frame_counter = 0
     self.disp_conf = disp_conf
     self.sv_thread_list = []
     self.capturing = True
     t = Thread(target=self._check_threads)
     t.daemon = True
     t.start()
Example #3
0
from robocar42 import config, util, models
from robocar42.car import Car
from robocar42.display import Display

logger = util.configure_log('drive')

NUM_CLASSES = 4
delta_time = 750
conf_level = 0.3

rc_car = Car(config.vehicle_parser_config(
    'vehicle.ini'))  # parses values from vehicle.ini into an object Car
disp_conf = config.display_parser_config(
    'display.ini')  # parses values from display.ini
cam_1 = config.camera_parser_config(
    'camera_1.ini')  # parses values from camera_1.ini
cam_2 = config.camera_parser_config(
    'camera_2.ini')  # parses values from camera_2.ini
model_conf = config.model_parser_config(
    'model_1.ini')  # sets values from model_1.ini

links = ['/fwd', '/fwd/lf', '/fwd/rt', '/rev', '/rev/lf', '/rev/rt',
         '']  # list of commands for a controller
actions = [pygame.K_UP, pygame.K_LEFT, pygame.K_RIGHT, pygame.K_DOWN]
attributes = ['cam_1', 'cam_2', 'action']  # list of attributes
rev_action = 3  # other drive values are 0 - 2


def check_cameras():
    '''
    checks to see if the cameras are online
Example #4
0
import pygame
import pyping

from robocar42 import config, util, models
from robocar42.car import Car
from robocar42.display import Display

logger = util.configure_log('drive')

NUM_CLASSES = 4
delta_time = 1000
conf_level = 0.3

rc_car = Car(config.vehicle_parser_config('vehicle.ini'))
disp_conf = config.display_parser_config('display.ini')
cam_1 = config.camera_parser_config('camera_1.ini')
cam_2 = config.camera_parser_config('camera_2.ini')
model_conf = config.model_parser_config('model_1.ini')

links = ['/fwd', '/fwd/lf', '/fwd/rt', '/rev', '/rev/lf', '/rev/rt', '']
actions = [pygame.K_UP,pygame.K_LEFT,pygame.K_RIGHT,pygame.K_DOWN]
attributes=['cam_1', 'cam_2', 'action']
rev_action = 3

def check_cameras():
    try:
        cam_1_ret = pyping.ping(cam_1['cam_url'], udp=True).ret_code
        cam_2_ret = pyping.ping(cam_2['cam_url'], udp=True).ret_code
        if not cam_1_ret and not cam_2_ret:
            return True
    except:
Example #5
0
 def setUp(self):
     cam_conf = config.camera_parser_config('camera_1.ini')
     disp_conf = config.display_parser_config('display.ini')
     self.cam = Camera('cam', cam_conf, disp_conf['oshape'], True)