You should have already completed Assignment: Google Cloud Vision Setup Test. You will need the .json file that you downloaded for the next part.

computer science


You should have already completed Assignment: Google Cloud Vision Setup Test. You will need the .json file that you downloaded for the next part.


  1. Download the zipped starter project, unzip it, and open it in IntelliJ.
  2. Now copy your .json file you downloaded in the Assignment: Google Cloud Vision Setup Test to the src folder of the SeeFood IntelliJ project.


In the starter you are given two .java files: and DO NOT CHANGE ANY OF THE CODE IN!!! In fact, you will NOT be submitting it. All your work will be done in There are 3 methods in, 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 as desired. However, YOU MAY NOT CHANGE ANY OF THE METHOD NAMES, RETURN TYPES, PARAMETER LISTS, OR THROWS CLAUSES IN 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.

SeeFood Methods You Must Implement


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:

  1. Prompt the user for a JPEG or PNG file using a JFileChooser
  2. then, as long as the user has chosen a file, display the image in a JLabel in a JFrame with either "Hot Dog" or "Not Hot Dog" displayed in the appropriate place/color on the image depending on whether Google Cloud Vision detects a hot dog in the image.

Related Questions in computer science category