ays*_*duz 2 python video opencv video-processing
我在Python3中使用Opencv2.
我正在为新闻视频写"镜头边界检测"程序.
我只需要将视频帧分成9个部分作为开头.但是,我不知道如何做到这一点我是这个领域的新手.我是通过裁剪做到的,但在我看来,将框架拆分成碎片是不对的.
注意:当我使用"我的标题"搜索时,我无法达到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()
Run Code Online (Sandbox Code Playgroud)