[Python]黑色背景白色块滑动视频

黑色背景白色块滑动视频,单帧效果如下:

配置参数

1920 1080 400 400 300 60 1920x1080.avi

c 复制代码
import numpy as np
import cv2 as cv
import os
import sys

width = 1920
height = 1080
rect_szx = 400
rect_szy = 300
sz_y_init = 400
fps = 24

width = int(sys.argv[1])
height = int(sys.argv[2])
sz_y_init = int(sys.argv[3])
rect_szx = int(sys.argv[4])
rect_szy = int(sys.argv[5])
fps = int(sys.argv[6])
file_name = sys.argv[7]

# 创建指定宽高、3通道、像素值都为0的图像
img = np.zeros((height, width, 3), np.uint8)
st_x = 0
st_y = 0
sz_x = 0
sz_y = 0
videoWriter = cv.VideoWriter(file_name, cv.VideoWriter_fourcc('X', 'V', 'I', 'D'), fps, (width, height))

for j in range(0, 5):
    for i in range(0, width + rect_szx, 20):
        if i < rect_szx:
            st_x = 0
            st_y = sz_y_init
            sz_x = i
            sz_y = rect_szy
        if i >= rect_szx and i < width:
            st_x = i - rect_szx
            st_y = sz_y_init
            sz_x = rect_szx
            sz_y = rect_szy
        if i >= width and i < width + rect_szx:
            st_x = i - rect_szx
            st_y = sz_y_init
            sz_x = width - st_x
            sz_y = rect_szy
        # print(st_x, ":", (st_x + sz_x))
        # print(st_y, ":", (st_y + sz_y))
        img_dst = img.copy()
        img_dst[st_y : (st_y + sz_y),st_x : (st_x + sz_x),0] = 255
        img_dst[st_y : (st_y + sz_y),st_x : (st_x + sz_x),1] = 255
        img_dst[st_y : (st_y + sz_y),st_x : (st_x + sz_x),2] = 255

        videoWriter.write(img_dst)
        # cv.imwrite("test.jpg", img_dst)

        # cv.imshow("black", img_dst)
        # cv.waitKey(30)
        # cv.destroyAllWindows()
    videoWriter.write(img)
相关推荐
聪明的墨菲特i几秒前
Django前后端分离基本流程
后端·python·django·web3
安步当歌3 分钟前
【WebRTC】视频编码链路中各个类的简单分析——VideoEncoder
音视频·webrtc·视频编解码·video-codec
工业3D_大熊6 分钟前
【虚拟仿真】CEETRON SDK在船舶流体与结构仿真中的应用解读
java·python·科技·信息可视化·c#·制造·虚拟现实
SEEONTIME15 分钟前
python-24-一篇文章彻底掌握Python HTTP库Requests
开发语言·python·http·http库requests
Bearnaise15 分钟前
PointMamba: A Simple State Space Model for Point Cloud Analysis——点云论文阅读(10)
论文阅读·笔记·python·深度学习·机器学习·计算机视觉·3d
哇咔咔哇咔1 小时前
【科普】conda、virtualenv, venv分别是什么?它们之间有什么区别?
python·conda·virtualenv
jndingxin1 小时前
OpenCV相机标定与3D重建(1)概述
数码相机·opencv·3d
CSXB991 小时前
三十四、Python基础语法(文件操作-上)
开发语言·python·功能测试·测试工具
亚图跨际2 小时前
MATLAB和Python及R潜变量模型和降维
python·matlab·r语言·生物学·潜变量模型
IT古董2 小时前
【机器学习】决定系数(R²:Coefficient of Determination)
人工智能·python·机器学习