[英]Can not use AWS Rekognition to detect a video
# Detect the contents in a image
import boto3
def lambda_handler(event, context):
client = boto3.client("rekognition")
s3 = boto3.client("s3")
# Read file from S3 bucket and pass it as bytes
fileObj = s3.get_object(Bucket="rekognition3bucket", Key="test.png")
file_content = fileObj["Body"].read()
# Pass bytes data
response = client.detect_labels(
Image={"Bytes": file_content}, MinConfidence=50
)
# Passing S3 bucket object file reference
response = client.detect_labels(
Image={"S3Object": {"Bucket": "rekognition3bucket", "Name": "test.png"}},
MaxLabels=5,
MinConfidence=70,
)
print(response)
上述程序可以檢測圖像中的內容。 它可以顯示內容標簽。 但是,它無法檢測 MP4 視頻中的內容。 我應該怎么辦?
Rekognition 有幾個不同的端點,具體取決於您是針對圖像還是視頻使用它。 您在上面分享的片段(特別是detect_labels
)用於圖像。 您應該使用start_label_detection
( AWS Doc ) 開始檢測,然后get_label_detection
( AWS Doc ) 檢索結果。
視頻示例可能如下所示:
import boto3
def lambda_handler(event, context):
# Start Rekognition Client
client = boto3.client("rekognition")
# Begin label detection
start_detection = client.start_label_detection(
Video={
'S3Object': {
'Bucket': "rekognition3bucket",
'Name': "video.mp4"
}
},
MinConfidence=50
)
# Get Labels by JobID
labels_returned = client.get_label_detection(
JobId=start_detection['JobId']
)
print(labels_returned)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.