Esempio n. 1
0
    def __init__(self, videopath, calibrationfile, bblpath, cam_angle_degrees=0, initial_offset=0):
        # General video stuff
        self.cap = cv2.VideoCapture(videopath)
        self.width = int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH))
        self.height = int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
        self.fps = self.cap.get(cv2.CAP_PROP_FPS)
        self.num_frames = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))


        # Camera undistortion stuff
        self.undistort = FisheyeCalibrator()
        self.undistort.load_calibration_json(calibrationfile, True)
        self.map1, self.map2 = self.undistort.get_maps(1.6,new_img_dim=(self.width,self.height))

        # Get gyro data
        self.bbe = BlackboxExtractor("test_clips/GX015563.MP4_emuf_004.bbl")
        self.gyro_data = self.bbe.get_gyro_data(cam_angle_degrees=cam_angle_degrees)

        # This seems to make the orientation match. Implement auto match later
        self.gyro_data[:,[2, 3]] = self.gyro_data[:,[3, 2]]
        self.gyro_data[:,2] = -self.gyro_data[:,2]

        # Other attributes
        initial_orientation = Rotation.from_euler('xyz', [0, 0, 0], degrees=True).as_quat()

        self.integrator = GyroIntegrator(self.gyro_data,initial_orientation=initial_orientation)
        self.integrator.integrate_all()
        self.times = None
        self.stab_transform = None

        self.initial_offset = initial_offset
Esempio n. 2
0
    def __init__(self, videopath, calibrationfile, gyrocsv, fov_scale = 1.6):
        # General video stuff
        self.undistort_fov_scale = fov_scale
        self.cap = cv2.VideoCapture(videopath)
        self.width = int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH))
        self.height = int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
        self.fps = self.cap.get(cv2.CAP_PROP_FPS)
        self.num_frames = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))


        # Camera undistortion stuff
        self.undistort = FisheyeCalibrator()
        self.undistort.load_calibration_json(calibrationfile, True)
        self.map1, self.map2 = self.undistort.get_maps(self.undistort_fov_scale,new_img_dim=(self.width,self.height))

        # Get gyro data

        self.gyro_data = self.instaCSVGyro(gyrocsv)
        hero = 6

        # Hero 6??
        if hero == 6:
            self.gyro_data[:,1] = self.gyro_data[:,1]
            self.gyro_data[:,2] = -self.gyro_data[:,2]
            self.gyro_data[:,3] = self.gyro_data[:,3]
        elif hero == 5:
            self.gyro_data[:,1] = -self.gyro_data[:,1]
            self.gyro_data[:,2] = self.gyro_data[:,2]
            self.gyro_data[:,3] = -self.gyro_data[:,3]
            self.gyro_data[:,[2, 3]] = self.gyro_data[:,[3, 2]]

        elif hero == 8:
            # Hero 8??
            self.gyro_data[:,[2, 3]] = self.gyro_data[:,[3, 2]]

        

        #gyro_data[:,1] = gyro_data[:,1]
        #gyro_data[:,2] = -gyro_data[:,2]
        #gyro_data[:,3] = gyro_data[:,3]

        #gyro_data[:,1:] = -gyro_data[:,1:]

        #points_test = np.array([[[0,0],[100,100],[200,300],[400,400]]], dtype = np.float32)
        #result = self.undistort.undistort_points(points_test, new_img_dim=(self.width,self.height))
        #print(result)
        #exit()

        # Other attributes
        initial_orientation = Rotation.from_euler('xyz', [0, 0, 0], degrees=True).as_quat()

        self.integrator = GyroIntegrator(self.gyro_data,zero_out_time=False,initial_orientation=initial_orientation)
        self.integrator.integrate_all()
        self.times = None
        self.stab_transform = None


        self.initial_offset = 0
Esempio n. 3
0
def render_queue():

    new_dim = (2560, 1440)

    undistort = FisheyeCalibrator()
    undistort.load_calibration_json(
        "../camera_presets\RunCam\DEV_Runcam_5_Orange_4K_30FPS_XV_16by9_stretched.json",
        True)

    N = 64

    start = time.time()

    for i in range(N):
        print(i)
        map1, map2 = undistort.get_maps(1,
                                        output_dim=new_dim,
                                        update_new_K=False,
                                        quat=np.array([1, 0, 0, 0]))

    tot = time.time() - start
    print(f"Single: {tot}s")

    start = time.time()
    n_proc = 4  # mp.cpu_count()
    chunksize = N // n_proc

    indices = [x for x in range(N)]

    proc_chunks = []
    for i_proc in range(n_proc):
        chunkstart = i_proc * chunksize
        # make sure to include the division remainder for the last process
        chunkend = (i_proc + 1) * chunksize if i_proc < n_proc - 1 else None

        proc_chunks.append(indices[chunkstart:chunkend])

    assert sum(map(len, proc_chunks)) == N

    with mp.Pool(processes=n_proc) as pool:
        # starts the sub-processes without blocking
        # pass the chunk to each worker process
        proc_results = [
            pool.apply_async(get_map_placeholder, args=(
                undistort,
                chunk,
            )) for chunk in proc_chunks
        ]
        # blocks until all results are fetched
        result_chunks = [r.get() for r in proc_results]

    tot = time.time() - start
    print(f"Multi: {tot}s")
    print(result_chunks)
Esempio n. 4
0
    def __init__(self, videopath, calibrationfile):
        # General video stuff
        self.cap = cv2.VideoCapture(videopath)
        self.width = int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH))
        self.height = int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
        self.fps = self.cap.get(cv2.CAP_PROP_FPS)
        self.num_frames = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))


        # Camera undistortion stuff
        self.undistort = FisheyeCalibrator()
        self.undistort.load_calibration_json(calibrationfile, True)
        self.map1, self.map2 = self.undistort.get_maps(1.6,new_img_dim=(self.width,self.height))

        # Other attributes
        self.times = None
        self.stab_transform = None
Esempio n. 5
0
    def __init__(self, videopath, calibrationfile):
        # General video stuff
        self.cap = cv2.VideoCapture(videopath)
        self.width = int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH))
        self.height = int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
        self.fps = self.cap.get(cv2.CAP_PROP_FPS)
        self.num_frames = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))

        # Camera undistortion stuff
        self.undistort = FisheyeCalibrator()
        self.undistort.load_calibration_json(calibrationfile, True)
        self.map1, self.map2 = self.undistort.get_maps(
            1.6, new_img_dim=(self.width, self.height))

        # Get gyro data
        self.gpmf = Extractor(videopath)
        self.gyro_data = self.gpmf.get_gyro(True)

        # Hero 6??
        #self.gyro_data[:,1] = self.gyro_data[:,1]
        #self.gyro_data[:,2] = -self.gyro_data[:,2]
        #self.gyro_data[:,3] = self.gyro_data[:,3]

        # Hero 8??
        self.gyro_data[:, [2, 3]] = self.gyro_data[:, [3, 2]]
        #gyro_data[:,1] = gyro_data[:,1]
        #gyro_data[:,2] = -gyro_data[:,2]
        #gyro_data[:,3] = gyro_data[:,3]

        #gyro_data[:,1:] = -gyro_data[:,1:]

        # Other attributes
        initial_orientation = Rotation.from_euler('xyz', [0, 0, 0],
                                                  degrees=True).as_quat()

        self.integrator = GyroIntegrator(
            self.gyro_data, initial_orientation=initial_orientation)
        self.integrator.integrate_all()
        self.times = None
        self.stab_transform = None
Esempio n. 6
0
ports = serial.tools.list_ports.comports(include_links=False)
for port in ports:
    print('Find port ' + port.device)

ser = serial.Serial(port.device)
if ser.isOpen():
    ser.close()

ser = serial.Serial(port.device, 9600, timeout=1)
ser.flushInput()
ser.flushOutput()
print('Connect ' + ser.name)

preset_path = "../camera_presets/Caddx/Caddx_Ratel_2_1mm_4by3.json"

undistort = FisheyeCalibrator()
undistort.load_calibration_json(preset_path)

cap = cv2.VideoCapture(1)

width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

quat = np.array([1, 0, 0, 0])
smoothed_quat = np.array([1, 0, 0, 0])
correction_quat = np.array([1, 0, 0, 0])


def quaternion(w, x, y, z):
    return np.array([w, x, y, z])
Esempio n. 7
0
def video_speed():
    new_dim = (2560, 1440)

    undistort = FisheyeCalibrator()
    undistort.load_calibration_json(
        "../camera_presets\RunCam\DEV_Runcam_5_Orange_4K_30FPS_XV_16by9_stretched.json",
        True)

    # Create a VideoCapture object and read from input file
    cap = cv2.VideoCapture('../test_clips/Runcam/RC_0036_filtered.MP4')
    #cap = cv2.VideoCapture('C:/Users/elvin/Downloads/IF-RC01_0000.MP4')
    #cap.set(cv2.CAP_PROP_POS_FRAMES, 60 * 10)

    ret, frame_out = cap.read()

    frame_out = (frame_out * 0).astype(np.float64)

    mult = 3
    num_blend = 3

    i = 1

    tstart = time.time()

    # Read until video is completed
    while (cap.isOpened()):

        # Capture frame-by-frame
        ret, frame = cap.read()
        if ret == True:

            # Display the resulting frame

            if True:
                print(i)
                # Some random processing steps
                #prev_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
                map1, map2 = undistort.get_maps(1,
                                                output_dim=new_dim,
                                                update_new_K=False,
                                                quat=np.array([1, 0, 0, 0]))
                frame_out = cv2.remap(frame,
                                      map1,
                                      map2,
                                      interpolation=cv2.INTER_LINEAR)
                #cv2.imshow('Frame', frame_out)
                #cv2.waitKey(1)
            else:

                if (i - 1) % mult == 0:
                    # Reset frame at beginning of hyperlapse range
                    print("reset")
                    frame_out = frame_out * 0.0

                if (i - 1) % mult < num_blend:
                    print(f"adding {i}")
                    frame_out += 1 / (num_blend) * frame.astype(np.float64)

                if ((i - 1) - num_blend + 1) % mult == 0:
                    cv2.imshow('Frame', frame_out.astype(np.uint8))

                    cv2.waitKey(5)

            i += 1
            # Press Q on keyboard to  exit
            if 0xFF == ord('q'):
                break

        else:
            break
        if i == 200:
            break

    tstop = time.time()
    dtime = tstop - tstart
    process_fps = 200 / dtime
    print(f"elapsed: {dtime}, fps: {process_fps}")

    cap.release()
    cv2.destroyAllWindows()