[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)
相关推荐
顾一大人5 分钟前
dp自动化登陆之hCaptcha 验证码
爬虫·python·自动化
多巴胺与内啡肽.15 分钟前
OpenCV进阶操作:人脸检测、微笑检测
人工智能·opencv·计算机视觉
知舟不叙1 小时前
基于OpenCV中的图像拼接方法详解
人工智能·opencv·计算机视觉·图像拼接
Code_流苏1 小时前
《Python星球日记》 第71天:命名实体识别(NER)与关系抽取
python·深度学习·ner·预训练语言模型·关系抽取·统计机器学习·标注方式
点云SLAM1 小时前
Python中列表(list)知识详解(2)和注意事项以及应用示例
开发语言·人工智能·python·python学习·数据结果·list数据结果
国强_dev1 小时前
任意复杂度的 JSON 数据转换为多个结构化的 Pandas DataFrame 表格
开发语言·python
伊织code1 小时前
PyTorch API 7 - TorchScript、hub、矩阵、打包、profile
人工智能·pytorch·python·ai·矩阵·api
小龙Guo1 小时前
QT+opencv实现卡尺工具找圆、拟合圆
开发语言·qt·opencv
开开心心就好1 小时前
高效全能PDF工具,支持OCR识别
java·前端·python·pdf·ocr·maven·jetty
18538162800余。2 小时前
碰一碰发视频源码搭建,支持OEM
音视频