|
@@ -5,15 +5,15 @@ import os
|
|
|
import threading
|
|
|
import time
|
|
|
|
|
|
-import boto3
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
from AnsjerPush.config import BASE_DIR
|
|
|
from Model.models import UidPushModel, AiService, Device_Info
|
|
|
-from Object.ETkObject import ETkObject
|
|
|
from Object.AiImageObject import ImageProcessingObject
|
|
|
+from Object.ETkObject import ETkObject
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.utils import LocalDateTimeUtil
|
|
|
+from Object.utils.AmazonRekognitionUtil import AmazonRekognitionUtil
|
|
|
from Service.CommonService import CommonService
|
|
|
from Service.EquipmentInfoService import EquipmentInfoService
|
|
|
from Service.PushService import PushObject
|
|
@@ -37,7 +37,8 @@ class AiView(View):
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
|
- def identification(self, request_dict, response):
|
|
|
+ @staticmethod
|
|
|
+ def identification(request_dict, response):
|
|
|
"""
|
|
|
ai识别推送
|
|
|
@param request_dict: 请求数据
|
|
@@ -108,25 +109,14 @@ class AiView(View):
|
|
|
image_row = 1 # 合并成一张图后,一行有几个小图
|
|
|
image_processing_obj = ImageProcessingObject(dir_path, image_size, image_row)
|
|
|
image_processing_obj.merge_images()
|
|
|
- photo = open(dir_path + '.jpg', 'rb') # 打开合成图
|
|
|
-
|
|
|
- # 识别合成图片
|
|
|
- maxLabels = 50 # 最大标签
|
|
|
- minConfidence = 80 # 置信度
|
|
|
-
|
|
|
- client = boto3.client(
|
|
|
- 'rekognition',
|
|
|
- aws_access_key_id='AKIA2E67UIMD6JD6TN3J',
|
|
|
- aws_secret_access_key='6YaziO3aodyNUeaayaF8pK9BxHp/GvbbtdrOAI83',
|
|
|
- region_name='us-east-1')
|
|
|
- # doc: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rekognition.html#Rekognition.Client.detect_labels
|
|
|
- rekognition_res = client.detect_labels(
|
|
|
- Image={'Bytes': photo.read()},
|
|
|
- MaxLabels=maxLabels,
|
|
|
- MinConfidence=minConfidence)
|
|
|
- photo.close()
|
|
|
- if rekognition_res['ResponseMetadata']['HTTPStatusCode'] != 200:
|
|
|
- return response.json(5)
|
|
|
+
|
|
|
+ # 获取识别结果
|
|
|
+ aws_rekognition = AmazonRekognitionUtil()
|
|
|
+ with open(dir_path + '.jpg', 'rb') as f:
|
|
|
+ rekognition_res = aws_rekognition.detect_labels(f.read())
|
|
|
+
|
|
|
+ if not rekognition_res:
|
|
|
+ return response.json(0)
|
|
|
|
|
|
label_dict = image_processing_obj.handle_rekognition_res(detect_group, rekognition_res)
|
|
|
if not label_dict['label_list']:
|