diff --git a/demo.iml b/demo.iml new file mode 100644 index 0000000..1e3d467 --- /dev/null +++ b/demo.iml @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 85c77e8..67c07dd 100644 --- a/pom.xml +++ b/pom.xml @@ -84,6 +84,11 @@ ibm-watson 8.5.0 + + com.ibm.watson + visual-recognition + 8.5.0 + diff --git a/src/main/java/com/example/demo/DemoApplication.java b/src/main/java/com/example/demo/DemoApplication.java index 1621886..d65c212 100644 --- a/src/main/java/com/example/demo/DemoApplication.java +++ b/src/main/java/com/example/demo/DemoApplication.java @@ -24,5 +24,4 @@ public void run(String... strings) throws Exception { // jdbcTemplate.update("INSERT INTO customers(first_name, last_name) VALUES ('John','Woo')"); } - } \ No newline at end of file diff --git a/src/main/java/com/example/demo/controller/ImageController.java b/src/main/java/com/example/demo/controller/ImageController.java new file mode 100644 index 0000000..2b83bfe --- /dev/null +++ b/src/main/java/com/example/demo/controller/ImageController.java @@ -0,0 +1,56 @@ +package com.example.demo.controller; + +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.ibm.cloud.sdk.core.security.IamAuthenticator; +import com.ibm.watson.natural_language_understanding.v1.model.AnalysisResults; +import com.ibm.watson.natural_language_understanding.v1.model.AnalyzeOptions; +import com.ibm.watson.natural_language_understanding.v1.model.CategoriesResult; +import com.ibm.watson.natural_language_understanding.v1.model.Features; +import com.ibm.watson.visual_recognition.v3.VisualRecognition; +import com.ibm.watson.visual_recognition.v3.model.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.RequestMethod; +import java.io.File; + +@RestController +@RequestMapping(path = "/Image") +public class ImageController { + private static final Logger LOG = LoggerFactory.getLogger(ImageController.class); + + @Autowired + JdbcTemplate jdbcTemplate; + + @RequestMapping(path = "/test", method = RequestMethod.GET) + public String test( + @RequestParam(name = "img_path", defaultValue = "/Users/NakamuraTsukasa/Desktop/633.png") String img_path + ) throws FileNotFoundException { +// String url = "https://zukan.pokemon.co.jp/zukan-api/up/images/index/94b9fb82b38847b83a8041e9a78989ce.png"; + + IamAuthenticator authenticator = new IamAuthenticator("8nwN0eKp7eZ73So4DLdPndp_yv-vtlI27pN1wK2TjVg1"); + VisualRecognition visualRecognition = new VisualRecognition("2019-07-12", authenticator); + + ClassifyOptions options = new ClassifyOptions.Builder() + //.url(url) + .imagesFile(new File(img_path)) + .build(); + ClassifiedImages result = visualRecognition.classify(options).execute().getResult(); + System.out.println(result); + + List images = result.getImages(); + + ClassifiedImage image = images.get(0); + ClassifierResult r = image.getClassifiers().get(0); + ClassResult c = r.getClasses().get(0); + + return c.getXClass(); + + } +} \ No newline at end of file diff --git a/target/classes/com/example/demo/DemoApplication.class b/target/classes/com/example/demo/DemoApplication.class new file mode 100644 index 0000000..0bd659e Binary files /dev/null and b/target/classes/com/example/demo/DemoApplication.class differ diff --git a/target/classes/com/example/demo/controller/ViewController.class b/target/classes/com/example/demo/controller/ViewController.class new file mode 100644 index 0000000..332e60b Binary files /dev/null and b/target/classes/com/example/demo/controller/ViewController.class differ diff --git a/target/classes/com/example/demo/entity/View.class b/target/classes/com/example/demo/entity/View.class new file mode 100644 index 0000000..ff85d8d Binary files /dev/null and b/target/classes/com/example/demo/entity/View.class differ diff --git a/target/classes/com/example/demo/repository/ViewRepository.class b/target/classes/com/example/demo/repository/ViewRepository.class new file mode 100644 index 0000000..2773c63 Binary files /dev/null and b/target/classes/com/example/demo/repository/ViewRepository.class differ diff --git a/target/classes/com/example/demo/service/ViewService.class b/target/classes/com/example/demo/service/ViewService.class new file mode 100644 index 0000000..cb57f99 Binary files /dev/null and b/target/classes/com/example/demo/service/ViewService.class differ diff --git a/target/test-classes/com/example/demo/DemoApplicationTests.class b/target/test-classes/com/example/demo/DemoApplicationTests.class new file mode 100644 index 0000000..94f7046 Binary files /dev/null and b/target/test-classes/com/example/demo/DemoApplicationTests.class differ