Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencv 使用python处理使用EventGridEvent创建的blob_Opencv_Azure Functions_Azure Storage Blobs - Fatal编程技术网

Opencv 使用python处理使用EventGridEvent创建的blob

Opencv 使用python处理使用EventGridEvent创建的blob,opencv,azure-functions,azure-storage-blobs,Opencv,Azure Functions,Azure Storage Blobs,在下面的代码中,我检索了一个创建的blobURL,我打算对其进行处理。有谁能推荐一个教程,告诉我如何下载blob(这是一个视频),打开它,并在触发此事件时处理每一帧?您可以参考此方法下载blob import json import logging import cv2 import azure.functions as func from azure.storage.blob import BlobServiceClient, generate_blob_sas, AccessPolicy,

在下面的代码中,我检索了一个创建的blobURL,我打算对其进行处理。有谁能推荐一个教程,告诉我如何下载blob(这是一个视频),打开它,并在触发此事件时处理每一帧?

您可以参考此方法下载blob

import json
import logging
import cv2
import azure.functions as func

from azure.storage.blob import BlobServiceClient, generate_blob_sas, AccessPolicy, BlobSasPermissions
from azure.core.exceptions import ResourceExistsError
from datetime import datetime, timedelta

def main(event: func.EventGridEvent):
    result = json.dumps({
        'id': event.id,
        'data': event.get_json(),
        'topic': event.topic,
        'subject': event.subject,
        'event_type': event.event_type,
    })

    logging.info('Python EventGrid trigger processed an event: %s', result)

    connect_string = "connect string of storage"
    DEST_FILE = "path to download the video"

    blob_service_client = BlobServiceClient.from_connection_string(connect_string)

    blob_url = event.get_json().get('url')
    logging.info('blob URL: %s', blob_url)

    blob_name = blob_url.split("/")[-1].split("?")[0]
    container_name = blob_url.split("/")[-2].split("?")[0]

    # Download blob to DEST_FILE
    blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)
    with open(DEST_FILE, "wb") as my_blob:
       download_stream = blob_client.download_blob()
       my_blob.write(download_stream.readall())
    
    # Process images of a video, frame by frame
    video_path = DEST_FILE + "/" +blob_name
    logging.info('video path: %s', video_path)
    cap = cv2.VideoCapture(video_path)
    count = 0
    while cap.isOpened():
        ret,frame = cap.read()
        cv2.imshow('window-name', frame)
        cv2.imwrite("frame%d.jpg" % count, frame)
        count = count + 1
        if cv2.waitKey(10) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows() # destroy all opened windows
有关处理每个帧的信息,请参阅

import json
import logging
import cv2
import azure.functions as func

from azure.storage.blob import BlobServiceClient, generate_blob_sas, AccessPolicy, BlobSasPermissions
from azure.core.exceptions import ResourceExistsError
from datetime import datetime, timedelta

def main(event: func.EventGridEvent):
    result = json.dumps({
        'id': event.id,
        'data': event.get_json(),
        'topic': event.topic,
        'subject': event.subject,
        'event_type': event.event_type,
    })

    logging.info('Python EventGrid trigger processed an event: %s', result)

    connect_string = "connect string of storage"
    DEST_FILE = "path to download the video"

    blob_service_client = BlobServiceClient.from_connection_string(connect_string)

    blob_url = event.get_json().get('url')
    logging.info('blob URL: %s', blob_url)

    blob_name = blob_url.split("/")[-1].split("?")[0]
    container_name = blob_url.split("/")[-2].split("?")[0]

    # Download blob to DEST_FILE
    blob_client = blob_service_client.get_blob_client(container=container_name, blob=blob_name)
    with open(DEST_FILE, "wb") as my_blob:
       download_stream = blob_client.download_blob()
       my_blob.write(download_stream.readall())
    
    # Process images of a video, frame by frame
    video_path = DEST_FILE + "/" +blob_name
    logging.info('video path: %s', video_path)
    cap = cv2.VideoCapture(video_path)
    count = 0
    while cap.isOpened():
        ret,frame = cap.read()
        cv2.imshow('window-name', frame)
        cv2.imwrite("frame%d.jpg" % count, frame)
        count = count + 1
        if cv2.waitKey(10) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows() # destroy all opened windows

多谢各位