Beispiel #1
0
 def recognize_vehicle_parts_advance(self, request, runtime):
     # Step 0: init client
     access_key_id = self._credential.get_access_key_id()
     access_key_secret = self._credential.get_access_key_secret()
     auth_config = rpc_models.Config(access_key_id=access_key_id,
                                     access_key_secret=access_key_secret,
                                     type='access_key',
                                     endpoint='openplatform.aliyuncs.com',
                                     protocol=self._protocol,
                                     region_id=self._region_id)
     auth_client = OpenPlatformClient(auth_config)
     auth_request = open_platform_models.AuthorizeFileUploadRequest(
         product='objectdet', region_id=self._region_id)
     auth_response = open_platform_models.AuthorizeFileUploadResponse()
     oss_config = oss_models.Config(access_key_secret=access_key_secret,
                                    type='access_key',
                                    protocol=self._protocol,
                                    region_id=self._region_id)
     oss_client = None
     file_obj = file_form_models.FileField()
     oss_header = oss_models.PostObjectRequestHeader()
     upload_request = oss_models.PostObjectRequest()
     oss_runtime = ossutil_models.RuntimeOptions()
     OpenApiUtilClient.convert(runtime, oss_runtime)
     recognize_vehicle_parts_req = objectdet_20191230_models.RecognizeVehiclePartsRequest(
     )
     OpenApiUtilClient.convert(request, recognize_vehicle_parts_req)
     auth_response = auth_client.authorize_file_upload_with_options(
         auth_request, runtime)
     oss_config.access_key_id = auth_response.access_key_id
     oss_config.endpoint = OpenApiUtilClient.get_endpoint(
         auth_response.endpoint, auth_response.use_accelerate,
         self._endpoint_type)
     oss_client = OSSClient(oss_config)
     file_obj = file_form_models.FileField(
         filename=auth_response.object_key,
         content=request.image_urlobject,
         content_type='')
     oss_header = oss_models.PostObjectRequestHeader(
         access_key_id=auth_response.access_key_id,
         policy=auth_response.encoded_policy,
         signature=auth_response.signature,
         key=auth_response.object_key,
         file=file_obj,
         success_action_status='201')
     upload_request = oss_models.PostObjectRequest(
         bucket_name=auth_response.bucket, header=oss_header)
     oss_client.post_object(upload_request, oss_runtime)
     recognize_vehicle_parts_req.image_url = 'http://%s.%s/%s' % (
         TeaConverter.to_unicode(auth_response.bucket),
         TeaConverter.to_unicode(auth_response.endpoint),
         TeaConverter.to_unicode(auth_response.object_key))
     recognize_vehicle_parts_resp = self.recognize_vehicle_parts_with_options(
         recognize_vehicle_parts_req, runtime)
     return recognize_vehicle_parts_resp
Beispiel #2
0
 def detect_face_attributes_advance(self, request, runtime):
     # Step 0: init client
     access_key_id = self._credential.get_access_key_id()
     access_key_secret = self._credential.get_access_key_secret()
     security_token = self._credential.get_security_token()
     credential_type = self._credential.get_type()
     open_platform_endpoint = self._open_platform_endpoint
     if UtilClient.is_unset(open_platform_endpoint):
         open_platform_endpoint = 'openplatform.aliyuncs.com'
     if UtilClient.is_unset(credential_type):
         credential_type = 'access_key'
     auth_config = rpc_models.Config(access_key_id=access_key_id,
                                     access_key_secret=access_key_secret,
                                     security_token=security_token,
                                     type=credential_type,
                                     endpoint=open_platform_endpoint,
                                     protocol=self._protocol,
                                     region_id=self._region_id)
     auth_client = OpenPlatformClient(auth_config)
     auth_request = open_platform_models.AuthorizeFileUploadRequest(
         product='Cloudauth', region_id=self._region_id)
     auth_response = open_platform_models.AuthorizeFileUploadResponse()
     oss_config = oss_models.Config(access_key_secret=access_key_secret,
                                    type='access_key',
                                    protocol=self._protocol,
                                    region_id=self._region_id)
     oss_client = None
     file_obj = file_form_models.FileField()
     oss_header = oss_models.PostObjectRequestHeader()
     upload_request = oss_models.PostObjectRequest()
     oss_runtime = ossutil_models.RuntimeOptions()
     OpenApiUtilClient.convert(runtime, oss_runtime)
     detect_face_attributes_req = cloudauth_20201112_models.DetectFaceAttributesRequest(
     )
     OpenApiUtilClient.convert(request, detect_face_attributes_req)
     if not UtilClient.is_unset(request.image_file_object):
         auth_response = auth_client.authorize_file_upload_with_options(
             auth_request, runtime)
         oss_config.access_key_id = auth_response.access_key_id
         oss_config.endpoint = OpenApiUtilClient.get_endpoint(
             auth_response.endpoint, auth_response.use_accelerate,
             self._endpoint_type)
         oss_client = OSSClient(oss_config)
         file_obj = file_form_models.FileField(
             filename=auth_response.object_key,
             content=request.image_file_object,
             content_type='')
         oss_header = oss_models.PostObjectRequestHeader(
             access_key_id=auth_response.access_key_id,
             policy=auth_response.encoded_policy,
             signature=auth_response.signature,
             key=auth_response.object_key,
             file=file_obj,
             success_action_status='201')
         upload_request = oss_models.PostObjectRequest(
             bucket_name=auth_response.bucket, header=oss_header)
         oss_client.post_object(upload_request, oss_runtime)
         detect_face_attributes_req.image_file = 'http://%s.%s/%s' % (
             TeaConverter.to_unicode(auth_response.bucket),
             TeaConverter.to_unicode(auth_response.endpoint),
             TeaConverter.to_unicode(auth_response.object_key))
     detect_face_attributes_resp = self.detect_face_attributes_with_options(
         detect_face_attributes_req, runtime)
     return detect_face_attributes_resp