opencv

import cv2 as cv
import sys
import time

# 指定视屏存储解码格式
fourcc = cv.VideoWriter_fourcc(*'XVID')
out = cv.VideoWriter('out.avi', fourcc, 20.0, (640, 480))

def vido(camareID=0):
    cap=cv.VideoCapture(camareID)
    while cap.isOpened():
        #当前时间
        now=time.strftime(
             '%Y-%m-%d %H:%M:%S',
             time.localtime()
             )

        ret,frame=cap.read()
        if not ret:
            sys.exit("读取失败")
        # 定义视频颜色
        gray = cv.cvtColor(frame,cv.COLOR_BGR2GRAY)

        #frame = cv.flip(frame, 0) 视频翻转180
        frame = cv.flip(frame, 1)
        # 时间无法自动更新
        cv.putText(frame,now,org=(400,50),fontFace=cv.FONT_HERSHEY_PLAIN,fontScale=1.0,color=(255,255,255))
        out.write(frame)

        cv.imshow('',frame)
        if cv.waitKey(1) == ord('q'):
            break
    out.release()
    cap.release()
    cv.destroyAllWindows()

#camareID='http://admin:admin@10.250.209.225:8081'
#camareID='rtsp://admin:admin@10.250.209.225:8554/live'
camareID=0
vido(camareID)

posted @ 2022-09-05 17:11  mingtian是吧  阅读(15)  评论(0编辑  收藏  举报