coastalimagelib/corefunctions.py
def rectVideos(video_list, cameras, grid, numFrames):

    """
    This function performs image rectifications on video files,
    and saves a merged and rectified .avi to the user's drive.

    Inputs:
        video_list (list): 1xK list of paths to video files for each camera
        cameras (array of CameraData objects): 1xK array of CameraData
            intrinsic_list (list): 1x11xK internal calibration data
            extrinsic_list (list): 1x6xK external calibration data
            mType: intrinsic format ('DLT' or 'CIRN')
        xyz (ndarray): XYZ rectification grid
        numFrames (int): number of frames to rectify

    Returns:
        rect_array: h x w x numFrames array of rectified frames

    """

    caps = []
    nc = 3
    # Append each video capture object into structure
    for path in video_list:
        caps.append(cv.VideoCapture(path))

    # Loop through each frame
    for i in range(numFrames):
        for ind, cap in enumerate(caps):
            ret, frame = cap.read()
            if not ret:
                break

            # Add each frame into one object
            if ind == 0:
                all_frames = frame
                if i == 0:
                    fps = int(cap.get(cv.CAP_PROP_FRAME_COUNT))
            else:
                all_frames = np.append(all_frames, frame, axis=2)

        # All frames from one timestamp sent to mergeRectify
        merged = mergeRectify(all_frames, cameras, grid)
        cv.imshow("test", merged)
        cv.waitKey(0)

        if i == 0:
            # Create videowriter object to save video to drive
            outFile = initFullFileName(
                video_list[0],
                "video_capture.rect",
                type="avi"
            )
            result = cv.VideoWriter(
                outFile,
                cv.VideoWriter_fourcc("M", "J", "P", "G"),
                fps,
                (merged.shape[1], merged.shape[0]),
                1,
            )
            # Initialize array of images
            rect_arr = merged.astype(np.uint8)
            IrIndv = np.tile(np.zeros_like(merged), (numFrames,))

        IrIndv[:, :, (i * nc): (i * nc + nc)] = merged.astype(np.uint8)

        # Write to drive
        result.write(merged.astype(np.uint8))

    print("Rectified .avi movie saved to working directory as: " + outFile)
    result.release()

    return rect_arr

    This function performs image rectifications on video files,
    and saves a merged and rectified .avi to the user's drive.

    Inputs:
        video_list (list): 1xK list of paths to video files for each camera
        cameras (array of CameraData objects): 1xK array of CameraData
            intrinsic_list (list): 1x11xK internal calibration data
            extrinsic_list (list): 1x6xK external calibration data
            mType: intrinsic format ('DLT' or 'CIRN')
        xyz (ndarray): XYZ rectification grid
        numFrames (int): number of frames to rectify

    Returns:
        rect_array: h x w x numFrames array of rectified frames

    
This function performs image rectifications on video files,
and saves a merged and rectified .avi to the user's drive.


This function performs image rectifications on video files and saves a merged and rectified . avi to the user ' s drive .
def rectVideos(video_list, cameras, grid, numFrames):
    caps = []
    nc = 3
    for path in video_list:
        caps.append(cv.VideoCapture(path))
    for i in range(numFrames):
        for ind, cap in enumerate(caps):
            ret, frame = cap.read()
            if not ret:
                break
            if ind == 0:
                all_frames = frame
                if i == 0:
                    fps = int(cap.get(cv.CAP_PROP_FRAME_COUNT))
            else:
                all_frames = np.append(all_frames, frame, axis=2)
        merged = mergeRectify(all_frames, cameras, grid)
        cv.imshow("test", merged)
        cv.waitKey(0)
        if i == 0:
            outFile = initFullFileName(
                video_list[0],
                "video_capture.rect",
                type="avi"
            )
            result = cv.VideoWriter(
                outFile,
                cv.VideoWriter_fourcc("M", "J", "P", "G"),
                fps,
                (merged.shape[1], merged.shape[0]),
                1,
            )
            rect_arr = merged.astype(np.uint8)
            IrIndv = np.tile(np.zeros_like(merged), (numFrames,))
        IrIndv[:, :, (i * nc): (i * nc + nc)] = merged.astype(np.uint8)
        result.write(merged.astype(np.uint8))
    print("Rectified .avi movie saved to working directory as: " + outFile)
    result.release()
    return rect_arr
def rectVideos ( video_list , cameras , grid , numFrames ) : caps = [ ] nc = 3 for path in video_list : caps . append ( cv . VideoCapture ( path ) ) for i in range ( numFrames ) : for ind , cap in enumerate ( caps ) : ret , frame = cap . read ( ) if not ret : break if ind == 0 : all_frames = frame if i == 0 : fps = int ( cap . get ( cv . CAP_PROP_FRAME_COUNT ) ) else : all_frames = np . append ( all_frames , frame , axis = 2 ) merged = mergeRectify ( all_frames , cameras , grid ) cv . imshow ( "test" , merged ) cv . waitKey ( 0 ) if i == 0 : outFile = initFullFileName ( video_list [ 0 ] , "video_capture.rect" , type = "avi" ) result = cv . VideoWriter ( outFile , cv . VideoWriter_fourcc ( "M" , "J" , "P" , "G" ) , fps , ( merged . shape [ 1 ] , merged . shape [ 0 ] ) , 1 , ) rect_arr = merged . astype ( np . uint8 ) IrIndv = np . tile ( np . zeros_like ( merged ) , ( numFrames , ) ) IrIndv [ : , : , ( i * nc ) : ( i * nc + nc ) ] = merged . astype ( np . uint8 ) result . write ( merged . astype ( np . uint8 ) ) print ( "Rectified .avi movie saved to working directory as: " + outFile ) result . release ( ) return rect_arr
This function performs image rectifications on video files,
and saves a merged and rectified .avi to the user's drive.
This function performs image rectifications on video files and saves a merged and rectified . avi to the user ' s drive .
"""
    This function performs image rectifications on video files,
    and saves a merged and rectified .avi to the user's drive.

    Inputs:
        video_list (list): 1xK list of paths to video files for each camera
        cameras (array of CameraData objects): 1xK array of CameraData
            intrinsic_list (list): 1x11xK internal calibration data
            extrinsic_list (list): 1x6xK external calibration data
            mType: intrinsic format ('DLT' or 'CIRN')
        xyz (ndarray): XYZ rectification grid
        numFrames (int): number of frames to rectify

    Returns:
        rect_array: h x w x numFrames array of rectified frames

    """ # Append each video capture object into structure # Loop through each frame # Add each frame into one object # All frames from one timestamp sent to mergeRectify # Create videowriter object to save video to drive # Initialize array of images # Write to drive
h x w x numFrames array of rectified frames
h x w x numFrames array of rectified frames
rect_array
video_list
cameras
grid
numFrames