You should have already completed Assignment: Google Cloud Vision Setup Test. You will need the .json file that you downloaded for the next part.
In the starter you are given two .java files: GoogleCloudVision.java and SeeFood.java. DO NOT CHANGE ANY OF THE CODE IN GoogleCloudVision.java!!! In fact, you will NOT be submitting it. All your work will be done in SeeFood.java. There are 3 methods in SeeFood.java, which you must complete, each are marked with TODO in comments and details of each are in the JavaDoc comments in the file as well as below. You may add additional helper methods to SeeFood.java as desired. However, YOU MAY NOT CHANGE ANY OF THE METHOD NAMES, RETURN TYPES, PARAMETER LISTS, OR THROWS CLAUSES IN SeeFood.java. Doing so will result in severe point penalties up to a 0 for the exam.
The GoogleCloudVision class contains a single public static method named detectImageLabels which takes a String which is either a filename for an image or a URL to an image. It returns an ArrayList<String> that contains the objects that are contained in the image as detected by Google Cloud Vision. You do not need to know how Google Cloud Vision works, nor how to access it directly, the detectImageLabels method handles all the dirty work for you. However, once again, for it to work you must have completed Assignment: Google Cloud Vision Setup Test and put your credentials .json file in the src folder with the .java files. You will note that detectImageLabels throws a couple of exceptions. You are NOT expected to handle those. In fact, you may note that the methods in SeeFood simply pass the exception out through main.
As the name suggests, and as the JavaDoc comments for the method describe, this method must present a JFileChooser for the user that will allow them to select JPEG and PNG files. IMPORTANT NOTE JPEG files can end in either .jpg or .jpeg. The method returns the absolute path to the file or the empty String if the user clicks Cancel.
This method takes a single parameter, filename, a String that is the filename for the image. It then uses Google Cloud Vision API by calling GoogleCloudVision.detectImageLabels to get an ArrayList of Strings that are the (object) labels of things in the image. Using that list, your code will determine if the image contains a hot dog or not. The method will then display the image in a JLabel in a JFrame. If the image contains a hot dog, then a centered JLabel with a green background and white text saying "Hot Dog" should be added at the top of the label containing the image, like so.
Otherwise, a centered JLabel with a red background and white text saying "Not Hot Dog" should be added at the bottom of the label containing the image, like so.
IMPORTANT NOTE your code must work for any JPEG or PNG file fed to it -- the TAs may select any image files they want for testing including images that are not included in the starter project. In other words, you cannot use a simple selection (if or switch) statement that checks the filename and displays "Hot Dog" or "Not Hot Dog" based off of that. Your decision about whether a hot dog exists in the image must come from code you write that (correctly) checks the results from GoogleCloudVision.detectImageLabels.
As noted in the TODO comments in main, you must write the code to call the appropriate methods to do the following:
Get Free Quote!
380 Experts Online