|
|
@@ -1,5 +1,6 @@
|
|
|
package com.mokasz.image_pool.restful.controller;
|
|
|
|
|
|
+import com.mokasz.image_pool.algorithm.FeatureExtractor;
|
|
|
import com.mokasz.image_pool.restful.entity.ImageQueryResponse;
|
|
|
import com.mokasz.image_pool.restful.entity.ImageSaveResponse;
|
|
|
import org.bytedeco.javacpp.Loader;
|
|
|
@@ -67,6 +68,12 @@ public class ImageController {
|
|
|
return stringBuilder.toString();
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/store2")
|
|
|
+ public ImageSaveResponse store2 (@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
+ FeatureExtractor.compute(file.getBytes());
|
|
|
+ return new ImageSaveResponse("OK", 1L);
|
|
|
+ }
|
|
|
+
|
|
|
@PostMapping("/store")
|
|
|
public ImageSaveResponse store (@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
logger.info("File size: {} Name: {}", file.getSize(), file.getOriginalFilename());
|
|
|
@@ -89,7 +96,7 @@ public class ImageController {
|
|
|
float[] binaries = new float[64];
|
|
|
transformBinaryArray(floats, binaries);
|
|
|
logger.info("{}", floats);
|
|
|
- List<ImageQueryResponse> list = jdbcTemplate.query("SELECT hash, l2_distance(?::FLOAT2[], vector) AS similarity FROM image_pool.image_hash ORDER BY vector <-> ?::FLOAT2[] DESC LIMIT 2",
|
|
|
+ List<ImageQueryResponse> list = jdbcTemplate.query("SELECT hash, (64 - l2_distance(?::FLOAT2[], vector)) / 64 AS similarity FROM image_pool.image_hash ORDER BY vector <-> ?::FLOAT2[] ASC LIMIT 2",
|
|
|
(ResultSet rs, int rowNum) -> new ImageQueryResponse(rs.getFloat("similarity"), rs.getString("hash")), binaries, binaries);
|
|
|
return list;
|
|
|
}
|