1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Find frames in the video that are similar to the static image, to crop the video

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I use opencv with ffmpeg to cut the video. Specifically, find the frame in the video that is the same as the picture, then cut the video at the time the video frame is the same as the picture.

    I found the code on google and edited it according to my needs, but when it comes to comparing frames and still images, I don't know how to ask you to add a comparison section to cut the video.

    import numpy as np
    import cv2
    import time
    from skimage.metrics import structural_similarity as compare_ssim

    hinh = cv2.imread("f:\\x.png")
    hinh1 = cv2.resize(hinh, (500, 300))
    cap = cv2.VideoCapture('f:\\tt.mp4')
    prev_frame_time = 0
    new_frame_time = 0
    cv2.imshow('hinh', hinh1)

    while(cap.isOpened()):
    ret, frame = cap.read()

    if not ret:
    break

    gray = frame

    gray = cv2.resize(gray, (500, 300))
    font = cv2.FONT_HERSHEY_SIMPLEX
    new_frame_time = time.time()

    fps = 1/(new_frame_time-prev_frame_time)
    prev_frame_time = new_frame_time

    fps = int(fps)

    fps = str(fps)

    cv2.putText(gray, fps, (7, 70), font, 3, (100, 255, 0), 3, cv2.LINE_AA)
    ##############

    # displaying the frame with fps

    cv2.imshow('frame', gray)

    # press 'Q' if you want to exit
    if cv2.waitKey(1) & 0xFF == ord('q'):
    break

    cap.release()
    cv2.destroyAllWindows()

    Continue reading...

Compartilhe esta Página