<jupyter_start><jupyter_text>OAK-D PREPROCESSINGSince the `recording_RGBD.py` scrips saves the data in .h265 and .h254 format, it is necesary to convert them into a more common formal like .mp4. In this scrip performs the following tasks:- Changes the video files from `.h265` and `.h254` format to `.mp4`- Copies the RGB files into a new dataset- Visualizes the background of a recordning<jupyter_code>import cv2
import numpy as np
import os
import matplotlib.pyplot as plt
import shutil
def create_dir(folder, force=True, verbose=False):
    '''   Create a directory if it doesn't exist  '''
    try:
        os.makedirs(folder)
        if verbose: print('Directory {} created succesfully.'.format(folder))   
    except:
        if force:
            if verbose: print('{} already exists. Creating a new one'.format(folder))
            shutil.rmtree(folder)
            os.makedirs(folder)
        else:
            if verbose: print('{} already exists.'.format(folder))
            pass<jupyter_output><empty_output><jupyter_text>We define the raw dataset path and the path to the dataset containing only the RGB video<jupyter_code>dataset = '/home/israel/Downloads/OAKD_8S/raw/'
color_dataset = '/home/israel/Downloads/OAKD_8S/color'
right_dataset = '/home/israel/Downloads/OAKD_8S/right'
left_dataset = '/home/israel/Downloads/OAKD_8S/left'

subjects = ['rami', 'isra', 'jos', 'carlos', 'jhane', 'guille', 'andrea', 'sus']
# subjects = ['carlos1']
walks = ['bk', 'nm', 'bg', 'cl']
files = ['color_video.h265', 'left_video.h264', 'right_video.h264']
mfiles = ['color_video.mp4', 'left_video.mp4', 'right_video.mp4']
views = sorted(os.listdir(dataset))
for view in views:
    recordings = os.listdir(os.path.join(dataset, view))
    for s, subject in enumerate(subjects):
#         os.system(f'rm {os.path.join(dataset, view, subject, f'convert.txt')}')
        color_path = os.path.join(color_dataset, view, f'{str(s).zfill(3)}')
        create_dir(color_path, force=True)
        right_path = os.path.join(right_dataset, view, f'{str(s).zfill(3)}')
        create_dir(right_path, force=True)
        left_path = os.path.join(left_dataset, view, f'{str(s).zfill(3)}')
        create_dir(left_path, force=True)
        for w, walk in enumerate(walks):
            for rec in recordings:
                if subject in rec and f'walk:{walk}' in rec:
                    for file in files:
                        print(f'View:{view} Subject: {subject} walk: {walk} vid: {rec}')
                        codec_file = os.path.join(dataset, view, rec, file)
                        mp4_file = codec_file[:-4]+'mp4'
                        cmd = f'ffmpeg -framerate 30 -i {codec_file} -c copy {mp4_file}'
                        os.system(cmd)
                        if 'color' in file:
                            new_path = os.path.join(color_path, f'{walk}.mp4' )
                            cmd = f'cp {mp4_file} {new_path}'
                            os.system(cmd)
                        if 'right' in file:
                            new_path = os.path.join(right_path, f'{walk}.mp4' )
                            cmd = f'cp {mp4_file} {new_path}'
                            os.system(cmd)    
                        if 'left' in file:
                            new_path = os.path.join(left_path, f'{walk}.mp4' )
                            cmd = f'cp {mp4_file} {new_path}'
                            os.system(cmd)

video_path = f'/home/israel/Downloads/OAK/j9/05.08.2021_12.48.12_id:carlos1_walk:bk//color_video.mp4'
cap = cv2.VideoCapture(video_path)
end = cap.get(cv2.CAP_PROP_FRAME_COUNT)
cap.set(cv2.CAP_PROP_POS_FRAMES, end-10)
ret, frame = cap.read()
frame = cv2.resize(frame, (1280, 720), cv2.INTER_AREA)
plt.imshow(frame[:,:,::-1])<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup