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

相关推荐
yangshicong1 天前
第11章:结构化输出与数据提取 —— 让 AI 直接返回你想要的数据格式
数据库·人工智能·redis·python·langchain·ai编程
言之。1 天前
【Python】免费的中文 AI 配音方案
开发语言·人工智能·python
Warson_L1 天前
python dict key详解
python
天天进步20151 天前
Python全栈项目:从零手操一个高性能 API 网关
开发语言·python
安生生申1 天前
使用pygame实现2048
开发语言·python·pygame
潜创微科技1 天前
IT68353:双 DP1.4a+HDMI2.0 转 HDMI2.0 单芯片 KVM 切换方案
嵌入式硬件·音视频
徐图图不糊涂1 天前
搭建简易版的Rag系统
python·pycharm
灰灰勇闯IT1 天前
pyasc:用 Python 调用 CANN 的推理能力
开发语言·python
沐禾安信1 天前
同一画面,如何两个视频同时播放,两个方法
电脑·音视频·分屏·视频转换
500841 天前
Conv + BN + ReLU 融合:省掉两次显存读写
flutter·架构·开源·wpf·音视频