diff --git a/documentation-samples/quickstarts/ComputerVision/ComputerVisionQuickstart.java b/documentation-samples/quickstarts/ComputerVision/ComputerVisionQuickstart.java deleted file mode 100644 index 19f580f..0000000 --- a/documentation-samples/quickstarts/ComputerVision/ComputerVisionQuickstart.java +++ /dev/null @@ -1,267 +0,0 @@ -import com.microsoft.azure.cognitiveservices.vision.computervision.*; -import com.microsoft.azure.cognitiveservices.vision.computervision.models.*; - -import java.io.File; -import java.io.FileInputStream; -import java.nio.file.Files; - -import java.util.ArrayList; -import java.util.List; - -public class ComputerVisionQuickstarts -{ - public static void main(String[] args) - { - System.out.println("\nAzure Cognitive Services Computer Vision - Java Quickstart Sample"); - RunQuickstarts(); - } - - /** - * This Quickstart for the Azure Cognitive Services Computer Vision API shows how to analyze - * an image both locally and from a URL. - * Analyzing an image includes: - * - Displaying image captions and confidence values - * - Displaying image category names and confidence values - * - Displaying image tags and confidence values - * - Displaying any faces found in the image and their bounding boxes - * - Displaying whether any adult or racy content was detected and the confidence values - * - Displaying the image color scheme - * - Displaying any celebrities detected in the image and their bounding boxes - * - Displaying any landmarks detected in the image and their bounding boxes - * - Displaying what type of clip art or line drawing the image is - */ - - public static void RunQuickstarts() - { - // Add your Computer Vision subscription key and endpoint to your environment variables. - // After setting, close and then re-open your command shell or project. - String subscriptionKey = System.getenv("COMPUTER_VISION_SUBSCRIPTION_KEY"); - String endpoint = System.getenv("COMPUTER_VISION_ENDPOINT"); - - // Create an authenticated Computer Vision client - ComputerVisionClient compVisClient = ComputerVisionManager.authenticate(subscriptionKey).withEndpoint(endpoint); - // END - Create an authenticated Computer Vision client. - - - /* Analyze a local image: - * - * Set a string variable equal to the path of a local image. The image path below is a relative path. - */ - String pathToLocalImage = "src\\main\\resources\\landmark.jpg"; - - // This list defines the features to be extracted from the image. - List featuresToExtractFromLocalImage = new ArrayList<>(); - featuresToExtractFromLocalImage.add(VisualFeatureTypes.DESCRIPTION); - featuresToExtractFromLocalImage.add(VisualFeatureTypes.CATEGORIES); - featuresToExtractFromLocalImage.add(VisualFeatureTypes.TAGS); - featuresToExtractFromLocalImage.add(VisualFeatureTypes.FACES); - featuresToExtractFromLocalImage.add(VisualFeatureTypes.ADULT); - featuresToExtractFromLocalImage.add(VisualFeatureTypes.COLOR); - featuresToExtractFromLocalImage.add(VisualFeatureTypes.IMAGE_TYPE); - - System.out.println("\nAnalyzing local image ..."); - - try - { - // Need a byte array for analyzing a local image. - File rawImage = new File(pathToLocalImage); - byte[] imageByteArray = Files.readAllBytes(rawImage.toPath()); - - // Call the Computer Vision service and tell it to analyze the loaded image. - ImageAnalysis analysis = compVisClient.computerVision().analyzeImageInStream() - .withImage(imageByteArray) - .withVisualFeatures(featuresToExtractFromLocalImage) - .execute(); - - // Display image captions and confidence values. - System.out.println("\nCaptions: "); - for (ImageCaption caption : analysis.description().captions()) { - System.out.printf("\'%s\' with confidence %f\n", caption.text(), caption.confidence()); - } - - // Display image category names and confidence values. - System.out.println("\nCategories: "); - for (Category category : analysis.categories()) { - System.out.printf("\'%s\' with confidence %f\n", category.name(), category.score()); - } - - // Display image tags and confidence values. - System.out.println("\nTags: "); - for (ImageTag tag : analysis.tags()) { - System.out.printf("\'%s\' with confidence %f\n", tag.name(), tag.confidence()); - } - - // Display any faces found in the image and their location. - System.out.println("\nFaces: "); - for (FaceDescription face : analysis.faces()) { - System.out.printf("\'%s\' of age %d at location (%d, %d), (%d, %d)\n", face.gender(), face.age(), - face.faceRectangle().left(), face.faceRectangle().top(), - face.faceRectangle().left() + face.faceRectangle().width(), - face.faceRectangle().top() + face.faceRectangle().height()); - } - - // Display whether any adult or racy content was detected and the confidence values. - System.out.println("\nAdult: "); - System.out.printf("Is adult content: %b with confidence %f\n", analysis.adult().isAdultContent(), analysis.adult().adultScore()); - System.out.printf("Has racy content: %b with confidence %f\n", analysis.adult().isRacyContent(), analysis.adult().racyScore()); - - // Display the image color scheme. - System.out.println("\nColor scheme: "); - System.out.println("Is black and white: " + analysis.color().isBWImg()); - System.out.println("Accent color: " + analysis.color().accentColor()); - System.out.println("Dominant background color: " + analysis.color().dominantColorBackground()); - System.out.println("Dominant foreground color: " + analysis.color().dominantColorForeground()); - System.out.println("Dominant colors: " + String.join(", ", analysis.color().dominantColors())); - - // Display any celebrities detected in the image and their locations. - System.out.println("\nCelebrities: "); - for (Category category : analysis.categories()) - { - if (category.detail() != null && category.detail().celebrities() != null) - { - for (CelebritiesModel celeb : category.detail().celebrities()) - { - System.out.printf("\'%s\' with confidence %f at location (%d, %d), (%d, %d)\n", celeb.name(), celeb.confidence(), - celeb.faceRectangle().left(), celeb.faceRectangle().top(), - celeb.faceRectangle().left() + celeb.faceRectangle().width(), - celeb.faceRectangle().top() + celeb.faceRectangle().height()); - } - } - } - - // Display any landmarks detected in the image and their locations. - System.out.println("\nLandmarks: "); - for (Category category : analysis.categories()) - { - if (category.detail() != null && category.detail().landmarks() != null) - { - for (LandmarksModel landmark : category.detail().landmarks()) - { - System.out.printf("\'%s\' with confidence %f\n", landmark.name(), landmark.confidence()); - } - } - } - - // Display what type of clip art or line drawing the image is. - System.out.println("\nImage type:"); - System.out.println("Clip art type: " + analysis.imageType().clipArtType()); - System.out.println("Line drawing type: " + analysis.imageType().lineDrawingType()); - } - - catch (Exception e) - { - System.out.println(e.getMessage()); - e.printStackTrace(); - } - // END - Analyze a local image. - - - /* Analyze an image from a URL: - * - * Set a string variable equal to the path of a remote image. - */ - String pathToRemoteImage = "https://github.com/Azure-Samples/cognitive-services-sample-data-files/raw/master/ComputerVision/Images/faces.jpg"; - - // This list defines the features to be extracted from the image. - List featuresToExtractFromRemoteImage = new ArrayList<>(); - featuresToExtractFromRemoteImage.add(VisualFeatureTypes.DESCRIPTION); - featuresToExtractFromRemoteImage.add(VisualFeatureTypes.CATEGORIES); - featuresToExtractFromRemoteImage.add(VisualFeatureTypes.TAGS); - featuresToExtractFromRemoteImage.add(VisualFeatureTypes.FACES); - featuresToExtractFromRemoteImage.add(VisualFeatureTypes.ADULT); - featuresToExtractFromRemoteImage.add(VisualFeatureTypes.COLOR); - featuresToExtractFromRemoteImage.add(VisualFeatureTypes.IMAGE_TYPE); - - System.out.println("\n\nAnalyzing an image from a URL ..."); - - try - { - // Call the Computer Vision service and tell it to analyze the loaded image. - ImageAnalysis analysis = compVisClient.computerVision().analyzeImage() - .withUrl(pathToRemoteImage) - .withVisualFeatures(featuresToExtractFromRemoteImage) - .execute(); - - // Display image captions and confidence values. - System.out.println("\nCaptions: "); - for (ImageCaption caption : analysis.description().captions()) { - System.out.printf("\'%s\' with confidence %f\n", caption.text(), caption.confidence()); - } - - // Display image category names and confidence values. - System.out.println("\nCategories: "); - for (Category category : analysis.categories()) { - System.out.printf("\'%s\' with confidence %f\n", category.name(), category.score()); - } - - // Display image tags and confidence values. - System.out.println("\nTags: "); - for (ImageTag tag : analysis.tags()) { - System.out.printf("\'%s\' with confidence %f\n", tag.name(), tag.confidence()); - } - - // Display any faces found in the image and their location. - System.out.println("\nFaces: "); - for (FaceDescription face : analysis.faces()) { - System.out.printf("\'%s\' of age %d at location (%d, %d), (%d, %d)\n", face.gender(), face.age(), - face.faceRectangle().left(), face.faceRectangle().top(), - face.faceRectangle().left() + face.faceRectangle().width(), - face.faceRectangle().top() + face.faceRectangle().height()); - } - - // Display whether any adult or racy content was detected and the confidence values. - System.out.println("\nAdult: "); - System.out.printf("Is adult content: %b with confidence %f\n", analysis.adult().isAdultContent(), analysis.adult().adultScore()); - System.out.printf("Has racy content: %b with confidence %f\n", analysis.adult().isRacyContent(), analysis.adult().racyScore()); - - // Display the image color scheme. - System.out.println("\nColor scheme: "); - System.out.println("Is black and white: " + analysis.color().isBWImg()); - System.out.println("Accent color: " + analysis.color().accentColor()); - System.out.println("Dominant background color: " + analysis.color().dominantColorBackground()); - System.out.println("Dominant foreground color: " + analysis.color().dominantColorForeground()); - System.out.println("Dominant colors: " + String.join(", ", analysis.color().dominantColors())); - - // Display any celebrities detected in the image and their locations. - System.out.println("\nCelebrities: "); - for (Category category : analysis.categories()) - { - if (category.detail() != null && category.detail().celebrities() != null) - { - for (CelebritiesModel celeb : category.detail().celebrities()) - { - System.out.printf("\'%s\' with confidence %f at location (%d, %d), (%d, %d)\n", celeb.name(), celeb.confidence(), - celeb.faceRectangle().left(), celeb.faceRectangle().top(), - celeb.faceRectangle().left() + celeb.faceRectangle().width(), - celeb.faceRectangle().top() + celeb.faceRectangle().height()); - } - } - } - - // Display any landmarks detected in the image and their locations. - System.out.println("\nLandmarks: "); - for (Category category : analysis.categories()) - { - if (category.detail() != null && category.detail().landmarks() != null) - { - for (LandmarksModel landmark : category.detail().landmarks()) - { - System.out.printf("\'%s\' with confidence %f\n", landmark.name(), landmark.confidence()); - } - } - } - - // Display what type of clip art or line drawing the image is. - System.out.println("\nImage type:"); - System.out.println("Clip art type: " + analysis.imageType().clipArtType()); - System.out.println("Line drawing type: " + analysis.imageType().lineDrawingType()); - // END - Analyze an image from a URL. - } - - catch (Exception e) - { - System.out.println(e.getMessage()); - e.printStackTrace(); - } - } -} diff --git a/documentation-samples/quickstarts/Face/FaceQuickstart.java b/documentation-samples/quickstarts/Face/FaceQuickstart.java deleted file mode 100644 index 18a76c2..0000000 --- a/documentation-samples/quickstarts/Face/FaceQuickstart.java +++ /dev/null @@ -1,92 +0,0 @@ -import com.microsoft.azure.cognitiveservices.vision.faceapi.*; -import com.microsoft.azure.cognitiveservices.vision.faceapi.models.*; - -import java.io.*; -import java.lang.Object.*; -import java.util.*; -import java.net.*; - -/** - * Libraries needed (use these until the Face SDK is updated): - * see dependencies.txt for list of libraries, include these .jar files in your lib folder. - * To compile and run, enter the following at a command prompt: - * javac FaceQuickstart.java -cp .;lib\* - * java -cp .;lib\* FaceQuickstart - * This presumes your libraries are stored in a folder named "lib" in the same folder as MainClass.java. - * If not, adjust the -cp value accordingly. - * - * Note If you run this sample with JRE 9+, you may encounter the following issue: - * https://github.com/Azure/autorest-clientruntime-for-java/issues/569 which results in the following output: - * WARNING: An illegal reflective access operation has occurred ... (plus several more warnings) - * - * This should not prevent the sample from running correctly, so ignore it. - */ - -public class FaceQuickstart { - - public static void main(String[] args) { - /** - * Find Similar, Face API - * This sample detects faces in a single-person image and in a group image. - * It then searches the group image to find a simlar face as seen in the single-person image. - */ - - // This image should have a single face. - final String singleFaceUrl = "https://www.biography.com/.image/t_share/MTQ1MzAyNzYzOTgxNTE0NTEz/john-f-kennedy---mini-biography.jpg"; - final String singleImageName = singleFaceUrl.substring( singleFaceUrl.lastIndexOf('/')+1, singleFaceUrl.length() ); - // This image should have several faces. At least one should be similar to the face in singleFaceImage. - final String groupFacesUrl = "http://www.historyplace.com/kennedy/president-family-portrait-closeup.jpg"; - final String groupImageName = groupFacesUrl.substring( groupFacesUrl.lastIndexOf('/')+1, groupFacesUrl.length() ); - - /** - * Authenticate - */ - // Add FACE_SUBSCRIPTION_KEY to your environment variables with your key as the value. - final String key = System.getenv("FACE_SUBSCRIPTION_KEY"); - // You must use the same region as you used to get your Face subscription keys. - // List of regions: https://docs.microsoft.com/en-us/java/api/com.microsoft.azure.cognitiveservices.vision.faceapi.models.azureregions?view=azure-java-stable - final AzureRegions region = AzureRegions.WESTUS; - // Create Face client - FaceAPI client = FaceAPIManager.authenticate(region, key); - - /** - * Detect the faces in both images - */ - System.out.println(); - System.out.println("Detecting faces ..."); - // Create face ID list for single face image. - List listSingle = client.faces().detectWithUrl(singleFaceUrl, new DetectWithUrlOptionalParameter().withReturnFaceId(true)); - System.out.println("Detected face ID from single image: " + singleImageName + " :"); - // Get & display single face UUID - System.out.println(listSingle.get(0).faceId()); - - // Create face IDs list for group image. - List listGroup = client.faces().detectWithUrl(groupFacesUrl, new DetectWithUrlOptionalParameter().withReturnFaceId(true)); - System.out.println("Detected face IDs from group image: " + groupImageName + " :"); - // Get group face UUIDs - List groupListOfUuids = new ArrayList<>(); - for (DetectedFace face : listGroup) { - groupListOfUuids.add(face.faceId()); - System.out.println(face.faceId()); - } - System.out.println(); - - /** - * Find similar faces - */ - // Search for single face in the group image - List listSimilars = client.faces().findSimilar(listSingle.get(0).faceId(), new FindSimilarOptionalParameter().withFaceIds(groupListOfUuids)); - // Display the similar faces found - System.out.println(); - System.out.println("Similar faces found in group photo " + groupImageName + " are:"); - for (SimilarFace face : listSimilars) { - System.out.println("Face ID: " + face.faceId()); - // Get and print the level of certainty that there is a match - // Confidence range is 0.0 to 1.0. Closer to 1.0 is more confident - System.out.println("Confidence: " + face.confidence()); - } - - // END - Find Similar, Face API - } -} - diff --git a/documentation-samples/quickstarts/Face/dependencies.txt b/documentation-samples/quickstarts/Face/dependencies.txt deleted file mode 100644 index e951163..0000000 --- a/documentation-samples/quickstarts/Face/dependencies.txt +++ /dev/null @@ -1,27 +0,0 @@ -Include these jar libraries in a lib folder, in the root of your project. -They are dependencies for the FaceAPI SDK and AutoRest libraries. -Avoid any alpha or beta versions. -If specific versions are noted below, those are older versions that work better than the most recent, at the time of this commit. - -* https://mvnrepository.com/artifact/com.microsoft.azure/azure-client-runtime -* https://mvnrepository.com/artifact/com.microsoft.rest/client-runtime -* https://mvnrepository.com/artifact/com.fasterxml.jackson.datatype/jackson-datatype-joda -* https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -* https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -* https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -* https://mvnrepository.com/artifact/joda-time/joda-time -* https://mvnrepository.com/artifact/com.google.guava/guava -* https://mvnrepository.com/artifact/com.microsoft.azure/azure-annotations -* https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp/3.14.2 -* https://mvnrepository.com/artifact/com.squareup.okio/okio/1.17.4 -* https://mvnrepository.com/artifact/com.squareup.okhttp3/logging-interceptor -* https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp-urlconnection/3.14.2 -* https://mvnrepository.com/artifact/com.squareup.retrofit2/retrofit -* https://mvnrepository.com/artifact/com.squareup.retrofit2/converter-jackson -* https://mvnrepository.com/artifact/com.squareup.retrofit2/adapter-rxjava -* https://mvnrepository.com/artifact/io.reactivex/rxjava -* https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -* https://mvnrepository.com/artifact/org.slf4j/slf4j-api -* https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14/1.7.28 - -