def video_to_frames(video: cv2.VideoCapture,
                    out_path,
                    start=0,
                    end=-1,
                    step=24):
    if not video.isOpened():
        print('No video')
        return

    video.set(cv2.CAP_PROP_POS_FRAMES, start)

    if end == -1:
        end = video.get(cv2.CAP_PROP_FRAME_COUNT)

    paths = []
    f_count = 0
    while video.isOpened() and video.get(cv2.CAP_PROP_POS_FRAMES) < end:
        _, img = video.read()
        path = os.path.join(out_path, f'video-{f_count}.png')
        question_2.write_image(img, path)
        paths.append(path)
        f_count += 1
        current_frame = video.get(cv2.CAP_PROP_POS_FRAMES)
        video.set(cv2.CAP_PROP_POS_FRAMES, current_frame + step)

    return paths
Exemplo n.º 2
0
def main():
    img = to_greyscale('../res/img.png')
    question_2.display_image(img)
    question_2.write_image(img,
                           '../outputs/Assignment1/question_3_greyscale.png')
    grey = to_grey('../res/img.png')
    question_2.display_image(grey, 'custom function')
    question_2.write_image(
        grey, '../outputs/Assignment1/question_3_greyscale_custom.png')
def contrast_stretch(image):
    r1 = 70
    s1 = 0
    r2 = 140
    s2 = 255
    pixel_vec = np.vectorize(pixel_val)
    contrast_stretched = pixel_vec(image, r1, s1, r2, s2)
    display_image(image, win_name='original')
    display_image(contrast_stretched, win_name='output')
    write_image(contrast_stretched, '../outputs/Assignment1/question_10.png')
def main():
    img = read_image('../res/img.png', cv2.IMREAD_GRAYSCALE)
    flat_img_array = img.flatten()
    hist = calc_hist(flat_img_array, 256)
    cumulative = cumulative_freq(hist)
    equalized = equalize_hist(img, flat_img_array, cumulative)
    display_image(img, 'original')
    display_image(equalized, 'equalized')
    cv2.waitKey()
    cv2.destroyAllWindows()
    write_image(equalized, '../outputs/Assignment1/question_6.png')
Exemplo n.º 5
0
def gamma_correction(image):
    for gamma in [0.1, 0.5, 1.2, 2.2]:
        gamma_corrected = np.array(255 * (image / 255) ** gamma, dtype=np.uint8)
        write_image(gamma_corrected, f'../outputs/Assignment1/question_9-{gamma}.png')