python端上传图像到minio

捕捉视频流的异常帧,将对应帧上传至对应服务器

from concurrent.futures import thread
from xmlrpc.client import ResponseError
import datetime
from minio import Minio
import os
import cv2

client = Minio('ip:9000/',access_key='账号',secret_key='密码',secure=False)
#采用rtsp协议获取帧
url = "rtsp://" + "摄像头账号" + ":摄像头密码@" + "摄像头IP"
cap = cv2.VideoCapture(url)

ret, frame = cap.read()
while True:
    try:
        found = client.bucket_exists(bucket_name = "wxaidp")
        #获取年月日

        dir_name_master = datetime.datetime.now().strftime("%Y-%m") 
        dir_name_slave = datetime.datetime.now().strftime("%Y-%m-%d")
        #设置文件的年月日时分秒格式
        file_name = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
        middle_file_path = os.getcwd()
        if ret:            
            cv2.imwrite(r"F:\script\imageutils\data"+ "\\" + file_name + '.jpg' ,frame)            
        client.fput_object("wxaidp", "w2spot001/" + dir_name_master + "/"+ dir_name_slave + "/" + file_name  + ".jpg","F:\script\imageutils\data"+ "\\" + file_name + '.jpg')
        os.remove("F:\script\imageutils\data"+ "\\" + file_name + '.jpg')

    except ResponseError as err:
        print(err)



你可能感兴趣的:(python)