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,就说明输出图想你设置的宽高和原来的宽高不匹配

相关推荐
天佑木枫11 分钟前
15天Python入门系列 · 序
开发语言·python
happylifetree11 分钟前
Python017-第二章15.数据容器-dict常用操作
python
装不满的克莱因瓶26 分钟前
了解 LangChain 中的 LLM 与 ChatModel 的差异
人工智能·python·ai·langchain·llm·agent·chatmodel
IT知识分享1 小时前
从零开发在线简繁转换工具:OpenCC 实战、避坑经验与方案选型
javascript·python
lunzi_08261 小时前
【学习笔记】《Python编程 从入门到实践》第8章:函数定义、参数传递与模块导入
笔记·python·学习
杨运交2 小时前
[030][Web模块]Spring Boot 验证与 OpenAPI 集成实战:从校验规则到文档生成
前端·spring boot·python
培培说证2 小时前
2026财务岗位如何快速提升自身能力
python
努力攻坚操作系统2 小时前
编程语言编译运行机制对比:C / Java / Python
java·c语言·python
godspeed_lucip2 小时前
LLM和Agent——专题6:Multi Agent 入门(5)
人工智能·python