opencv对视频图片进行修改 python

d代码如下:

复制代码
import cv2
def detect(frame):#对视频进行处理
    img=cv2.rectangle(frame,(1,10),(100,300),color=(255,255,1),thickness=3)#里面画一个框
    return img

mp4_path = r'..\data\fish.mp4'
print(mp4_path)
cap = cv2.VideoCapture(mp4_path)

# # 设置视频的编码格式
fourcc = cv2.VideoWriter.fourcc(*'avci')
# # 定义视频保存的输出属性
out = cv2.VideoWriter(r'outpt_test.mp4', fourcc, 15, (1280, 720))#图片的宽高一定要对应
while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break
    img = detect(frame)
    out.write(img)
out.release()
cap.release()

def detect(frame):#对视频进行处理

img=cv2.rectangle(frame,(1,10),(100,300),color=(255,255,1),thickness=3)#里面画一个框

return img

ps:如果显示出来的的保存的视频是1Kb,就说明输出图想你设置的宽高和原来的宽高不匹配

相关推荐
明月_清风2 小时前
Python 内存手术刀:sys.getrefcount 与引用计数的生死时速
后端·python
明月_清风2 小时前
Python 消失的内存:为什么 list=[] 是新手最容易踩的“毒苹果”?
后端·python
Flittly17 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(3)TodoWrite (待办写入)
python·agent
千寻girling21 小时前
一份不可多得的 《 Django 》 零基础入门教程
后端·python·面试
databook1 天前
探索视觉的边界:用 Manim 重现有趣的知觉错觉
python·动效
明月_清风1 天前
Python 性能微观世界:列表推导式 vs for 循环
后端·python
明月_清风1 天前
Python 性能翻身仗:从 O(n) 到 O(1) 的工程实践
后端·python
helloweilei2 天前
python 抽象基类
python
用户8356290780512 天前
Python 实现 PPT 转 HTML
后端·python
zone77392 天前
004:RAG 入门-LangChain读取PDF
后端·python·面试