public ServiceCall < DetectedFaces > detectFaces ( DetectFacesOptions detectFacesOptions ) { Validator . notNull ( detectFacesOptions , "detectFacesOptions cannot be null" ) ; Validator . isTrue ( ( detectFacesOptions . imagesFile ( ) != null ) || ( detectFacesOptions . url ( ) != null ) , "At least one of imagesFile or url must be supplied." ) ; String [ ] pathSegments = { "v3/detect_faces" } ; RequestBuilder builder = RequestBuilder . post ( RequestBuilder . constructHttpUrl ( getEndPoint ( ) , pathSegments ) ) ; builder . query ( "version" , versionDate ) ; Map < String , String > sdkHeaders = SdkCommon . getSdkHeaders ( "watson_vision_combined" , "v3" , "detectFaces" ) ; for ( Entry < String , String > header : sdkHeaders . entrySet ( ) ) { builder . header ( header . getKey ( ) , header . getValue ( ) ) ; } builder . header ( "Accept" , "application/json" ) ; if ( detectFacesOptions . acceptLanguage ( ) != null ) { builder . header ( "Accept-Language" , detectFacesOptions . acceptLanguage ( ) ) ; } MultipartBody . Builder multipartBuilder = new MultipartBody . Builder ( ) ; multipartBuilder . setType ( MultipartBody . FORM ) ; if ( detectFacesOptions . imagesFile ( ) != null ) { RequestBody imagesFileBody = RequestUtils . inputStreamBody ( detectFacesOptions . imagesFile ( ) , detectFacesOptions . imagesFileContentType ( ) ) ; multipartBuilder . addFormDataPart ( "images_file" , detectFacesOptions . imagesFilename ( ) , imagesFileBody ) ; } if ( detectFacesOptions . url ( ) != null ) { multipartBuilder . addFormDataPart ( "url" , detectFacesOptions . url ( ) ) ; } builder . body ( multipartBuilder . build ( ) ) ; return createServiceCall ( builder . build ( ) , ResponseConverterUtils . getObject ( DetectedFaces . class ) ) ; }
Detect faces in images .