如何将视频帧分成 9 块?

How to split a video frame into 9 pieces?

我在 Python3 中使用 Opencv2。
我正在为新闻视频编写 "shot boundary detection" 程序。
一开始我只需要将一个视频帧分成 9 块。但是,我不确定该怎么做,因为我是这个领域的新手。我是通过裁剪来做到的,但在我看来,将一个框架分成几块是不对的。

注意:当我用 "my title" 搜索时,我无法找到 ROI 答案。但现在看来,这就是投资回报率。

例如,您需要使用 ROI 并将不同的图像添加到数组中。

我用我的猫测试过:

这里有代码:(按'q'键完成)

import cv2

cap = cv2.VideoCapture(0)
n_rows = 3
n_images_per_row = 3

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()
    height, width, ch = frame.shape

    roi_height = height / n_rows
    roi_width = width / n_images_per_row

    images = []

    for x in range(0, n_rows):
        for y in range(0,n_images_per_row):
            tmp_image=frame[x*roi_height:(x+1)*roi_height, y*roi_width:(y+1)*roi_width]
            images.append(tmp_image)

    # Display the resulting sub-frame
    for x in range(0, n_rows):
        for y in range(0, n_images_per_row):
            cv2.imshow(str(x*n_images_per_row+y+1), images[x*n_images_per_row+y])
            cv2.moveWindow(str(x*n_images_per_row+y+1), 100+(y*roi_width), 50+(x*roi_height))

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()