diff --git a/config/sonic-server-folder-dev.yml b/config/sonic-server-folder-dev.yml index f82a7097..a4f4843a 100644 --- a/config/sonic-server-folder-dev.yml +++ b/config/sonic-server-folder-dev.yml @@ -2,13 +2,6 @@ server: port: 0 spring: - tomcat: - max-http-post-size: 100M - http: - multipart: - maxFileSize: 3000M - maxRequestSize: 3000M - maxPostSize: 3000M servlet: multipart: maxFileSize: -1 diff --git a/config/sonic-server-gateway-dev.yml b/config/sonic-server-gateway-dev.yml index 0f55c872..c7de5596 100644 --- a/config/sonic-server-gateway-dev.yml +++ b/config/sonic-server-gateway-dev.yml @@ -2,7 +2,7 @@ server: port: 8094 filter: - white-list: /users/login,/users/register,/swagger-resources,/v2/api-docs,/folder/upload,/folder/upload/recordFiles,/folder/upload/cv,/keepFiles/,/imageFiles/,/recordFiles/,/logFiles/,/packageFiles/ + white-list: /users/login,/users/register,/swagger-resources,/v2/api-docs,/folder/upload,/folder/upload/recordFiles,/keepFiles/,/imageFiles/,/recordFiles/,/logFiles/,/packageFiles/ spring: cloud: diff --git a/docker-compose.yml b/docker-compose.yml index 2b2d17a3..a1495fa2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: sonic-server-eureka: - image: "sonicorg/sonic-server-eureka:v1.3.0-beta2" + image: "sonicorg/sonic-server-eureka:v1.3.0-release" hostname: sonic-server-eureka environment: - EUREKA_HOST=sonic-server-eureka @@ -12,7 +12,7 @@ services: ports: - "9090:9090" sonic-server-bus: - image: "sonicorg/sonic-server-bus:v1.3.0-beta2" + image: "sonicorg/sonic-server-bus:v1.3.0-release" environment: - PROFILE=prod - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/ @@ -24,7 +24,7 @@ services: depends_on: - sonic-server-eureka sonic-server-gateway: - image: "sonicorg/sonic-server-gateway:v1.3.0-beta2" + image: "sonicorg/sonic-server-gateway:v1.3.0-release" environment: - PROFILE=prod - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/ @@ -38,7 +38,7 @@ services: ports: - "8094:8094" sonic-server-controller: - image: "sonicorg/sonic-server-controller:v1.3.0-beta2" + image: "sonicorg/sonic-server-controller:v1.3.0-release" environment: - PROFILE=prod - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/ @@ -51,7 +51,7 @@ services: - sonic-server-eureka - sonic-server-gateway sonic-server-folder: - image: "sonicorg/sonic-server-folder:v1.3.0-beta2" + image: "sonicorg/sonic-server-folder:v1.3.0-release" environment: - PROFILE=prod - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/ @@ -68,7 +68,7 @@ services: - sonic-server-eureka - sonic-server-gateway sonic-server-task: - image: "sonicorg/sonic-server-task:v1.3.0-beta2" + image: "sonicorg/sonic-server-task:v1.3.0-release" environment: - PROFILE=prod - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/ @@ -81,7 +81,7 @@ services: - sonic-server-eureka - sonic-server-gateway sonic-server-transport: - image: "sonicorg/sonic-server-transport:v1.3.0-beta2" + image: "sonicorg/sonic-server-transport:v1.3.0-release" environment: - PROFILE=prod - EUREKA_URL=http://sonic:sonic@sonic-server-eureka:9090/eureka/ diff --git a/sonic-server-bus/pom.xml b/sonic-server-bus/pom.xml index 9323d738..50a80987 100644 --- a/sonic-server-bus/pom.xml +++ b/sonic-server-bus/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-bus - v1.3.0-beta2 + v1.3.0-release jar @@ -42,23 +42,23 @@ - - - - - org.springframework.boot - spring-boot-maven-plugin - - true - - - - com.spotify - docker-maven-plugin - - true - - - - + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sonic-server-common/pom.xml b/sonic-server-common/pom.xml index 12821aa8..a3c2271e 100644 --- a/sonic-server-common/pom.xml +++ b/sonic-server-common/pom.xml @@ -24,7 +24,7 @@ com.alibaba fastjson - 1.2.41 + 1.2.79 diff --git a/sonic-server-controller/pom.xml b/sonic-server-controller/pom.xml index b3fc5a21..9bd415a0 100644 --- a/sonic-server-controller/pom.xml +++ b/sonic-server-controller/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-controller - v1.3.0-beta2 + v1.3.0-release jar @@ -94,24 +94,24 @@ - - - - - org.springframework.boot - spring-boot-maven-plugin - - true - - - - com.spotify - docker-maven-plugin - - true - - - - + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sonic-server-eureka/pom.xml b/sonic-server-eureka/pom.xml index b699e7db..66e0c6a6 100644 --- a/sonic-server-eureka/pom.xml +++ b/sonic-server-eureka/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-eureka - v1.3.0-beta2 + v1.3.0-release jar @@ -38,23 +38,23 @@ - - - - - org.springframework.boot - spring-boot-maven-plugin - - true - - - - com.spotify - docker-maven-plugin - - true - - - - + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sonic-server-folder/pom.xml b/sonic-server-folder/pom.xml index a9678d7f..9d914620 100644 --- a/sonic-server-folder/pom.xml +++ b/sonic-server-folder/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-folder - v1.3.0-beta2 + v1.3.0-release jar @@ -30,45 +30,11 @@ sonic-server-common 1.1.0 - - - org.bytedeco - javacv - 1.5.3 - - - org.bytedeco - openblas - 0.3.9-1.5.3 - - - org.bytedeco - opencv - 4.3.0-1.5.3 - - - org.bytedeco - javacpp - 1.5.3 - linux-x86_64 - - - org.bytedeco - opencv - 4.3.0-1.5.3 - linux-x86_64 - - - org.bytedeco - openblas - 0.3.9-1.5.3 - linux-x86_64 - - - - + + + @@ -76,13 +42,13 @@ - - com.spotify - docker-maven-plugin - - true - - - - + + + + + + + + + \ No newline at end of file diff --git a/sonic-server-folder/src/main/docker/sonic-server-folder.jar b/sonic-server-folder/src/main/docker/sonic-server-folder.jar deleted file mode 100644 index 837826cf..00000000 Binary files a/sonic-server-folder/src/main/docker/sonic-server-folder.jar and /dev/null differ diff --git a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/controller/UploadController.java b/sonic-server-folder/src/main/java/org/cloud/sonic/folder/controller/UploadController.java index 98980c7a..976ee021 100644 --- a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/controller/UploadController.java +++ b/sonic-server-folder/src/main/java/org/cloud/sonic/folder/controller/UploadController.java @@ -4,11 +4,6 @@ import org.cloud.sonic.common.config.WebAspect; import org.cloud.sonic.common.http.RespEnum; import org.cloud.sonic.common.http.RespModel; -import org.cloud.sonic.folder.cv.AKAZEFinder; -import org.cloud.sonic.folder.cv.SIFTFinder; -import org.cloud.sonic.folder.cv.SimilarityChecker; -import org.cloud.sonic.folder.cv.TemMatcher; -import org.cloud.sonic.folder.models.FindResult; import org.cloud.sonic.folder.tools.FileTool; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; @@ -33,14 +28,6 @@ public class UploadController { @Autowired private FileTool fileTool; - @Autowired - private AKAZEFinder akazeFinder; - @Autowired - private SIFTFinder siftFinder; - @Autowired - private SimilarityChecker similarityChecker; - @Autowired - private TemMatcher temMatcher; @WebAspect @ApiOperation(value = "上传文件", notes = "上传文件到服务器") @@ -93,68 +80,4 @@ public RespModel uploadRecord(@RequestParam(name = "file") MultipartFile } return responseModel; } - - @WebAspect - @ApiOperation(value = "cv定位", notes = "三种定位方式") - @ApiImplicitParams(value = { - @ApiImplicitParam(name = "file1", value = "模板文件", dataTypeClass = MultipartFile.class), - @ApiImplicitParam(name = "file2", value = "原文件", dataTypeClass = MultipartFile.class) - }) - @PostMapping("/cv") - public RespModel cv(@RequestParam(name = "file1") MultipartFile file1, - @RequestParam(name = "file2") MultipartFile file2, - @RequestParam(name = "type") String type) throws IOException { - File local1 = new File("imageFiles" + File.separator + - UUID.randomUUID() + file1.getOriginalFilename() - .substring(file1.getOriginalFilename().lastIndexOf("."))); - try { - file1.transferTo(local1.getAbsoluteFile()); - } catch (FileAlreadyExistsException e) { - log.error(e.getMessage()); - } - File local2 = new File("imageFiles" + File.separator + - UUID.randomUUID() + file2.getOriginalFilename() - .substring(file2.getOriginalFilename().lastIndexOf("."))); - try { - file2.transferTo(local2.getAbsoluteFile()); - } catch (FileAlreadyExistsException e) { - log.error(e.getMessage()); - } - switch (type) { - case "finder": { - FindResult findResult = null; - try { - findResult = siftFinder.getSIFTFindResult(local1, local2); - } catch (Exception e) { - log.info("SIFT图像算法出错,切换算法中..."); - } - if (findResult == null) { - try { - findResult = akazeFinder.getAKAZEFindResult(local1, local2); - } catch (Exception e) { - log.info("AKAZE图像算法出错,切换算法中..."); - } - if (findResult == null) { - try { - findResult = temMatcher.getTemMatchResult(local1, local2); - } catch (Exception e) { - log.info("模版匹配算法出错"); - } - } - } - if (findResult != null) { - return new RespModel(RespEnum.HANDLE_OK, findResult); - } else { - return new RespModel<>(RespEnum.UNKNOWN_ERROR); - } - } - case "checker": { - double score = similarityChecker.getSimilarMSSIMScore(local1, local2); - return new RespModel(RespEnum.SEARCH_OK, score); - } - default: { - return new RespModel(RespEnum.PARAMS_VIOLATE_ERROR); - } - } - } } diff --git a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/AKAZEFinder.java b/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/AKAZEFinder.java deleted file mode 100644 index 25b29865..00000000 --- a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/AKAZEFinder.java +++ /dev/null @@ -1,338 +0,0 @@ -package org.cloud.sonic.folder.cv; - -import org.bytedeco.opencv.opencv_core.*; -import org.bytedeco.opencv.opencv_features2d.AKAZE; -import org.bytedeco.opencv.opencv_flann.Index; -import org.bytedeco.opencv.opencv_flann.IndexParams; -import org.bytedeco.opencv.opencv_flann.LshIndexParams; -import org.bytedeco.opencv.opencv_flann.SearchParams; -import org.cloud.sonic.folder.models.FindResult; -import org.cloud.sonic.folder.tools.FileTool; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.UUID; -import java.util.concurrent.ThreadLocalRandom; - -import static org.bytedeco.opencv.global.opencv_calib3d.CV_RANSAC; -import static org.bytedeco.opencv.global.opencv_calib3d.findHomography; -import static org.bytedeco.opencv.global.opencv_core.*; -import static org.bytedeco.opencv.global.opencv_flann.FLANN_DIST_HAMMING; -import static org.bytedeco.opencv.global.opencv_imgcodecs.*; -import static org.bytedeco.opencv.global.opencv_imgproc.*; -import static org.bytedeco.opencv.helper.opencv_imgcodecs.cvLoadImage; -import static org.bytedeco.opencv.helper.opencv_imgcodecs.cvSaveImage; - -/** - * @author ZhouYiXun - * @des akaze算法 - * @date 2022/1/4 21:49 - */ -@Component -public class AKAZEFinder { - private final Logger logger = LoggerFactory.getLogger(AKAZEFinder.class); - IplImage objectImage = null; - AKAZE detector = AKAZE.create(); - double distanceThreshold = 0.6; - int matchesMin = 4; - double ransacReprojThreshold = 1.0; - boolean useFLANN = false; - KeyPointVector objectKeypoints = null, imageKeypoints = null; - Mat objectDescriptors = null, imageDescriptors = null; - Mat indicesMat, distsMat; - Index flannIndex = null; - IndexParams indexParams = null; - SearchParams searchParams = null; - Mat pt1 = null, pt2 = null, mask = null, H = null; - ArrayList ptpairs = null; - @Autowired - private FileTool fileTool; - - public void init() { - objectKeypoints = new KeyPointVector(); - objectDescriptors = new Mat(); - detector.detectAndCompute(cvarrToMat(objectImage), - new Mat(), objectKeypoints, objectDescriptors, false); - - int total = (int) objectKeypoints.size(); - if (useFLANN) { - indicesMat = new Mat(total, 2, CV_32SC1); - distsMat = new Mat(total, 2, CV_32FC1); - flannIndex = new Index(); - indexParams = new LshIndexParams(12, 20, 2); // using LSH Hamming distance - searchParams = new SearchParams(64, 0, true); // maximum number of leafs checked - searchParams.deallocate(false); // for some reason FLANN seems to do it for us - } - pt1 = new Mat(total, 1, CV_32FC2); - pt2 = new Mat(total, 1, CV_32FC2); - mask = new Mat(total, 1, CV_8UC1); - H = new Mat(3, 3, CV_64FC1); - ptpairs = new ArrayList(2 * objectDescriptors.rows()); - logger.info("模版图一共有" + total + "个特征点"); - } - - public double[] find(IplImage image) { - if (objectDescriptors.rows() < matchesMin) { - return null; - } - imageKeypoints = new KeyPointVector(); - imageDescriptors = new Mat(); - detector.detectAndCompute(cvarrToMat(image), - new Mat(), imageKeypoints, imageDescriptors, false); - if (imageDescriptors.rows() < matchesMin) { - return null; - } - - int total = (int) imageKeypoints.size(); - logger.info("原图一共有" + total + "个特征点"); - - int w = objectImage.width(); - int h = objectImage.height(); - double[] srcCorners = {0, 0, w, 0, w, h, 0, h}; - double[] dstCorners = locatePlanarObject(objectKeypoints, objectDescriptors, - imageKeypoints, imageDescriptors, srcCorners); - return dstCorners; - } - - private static final int[] bits = new int[256]; - - static { - for (int i = 0; i < bits.length; i++) { - for (int j = i; j != 0; j >>= 1) { - bits[i] += j & 0x1; - } - } - } - - private int compareDescriptors(ByteBuffer d1, ByteBuffer d2, int best) { - int totalCost = 0; - assert d1.limit() - d1.position() == d2.limit() - d2.position(); - while (d1.position() < d1.limit()) { - totalCost += bits[(d1.get() ^ d2.get()) & 0xFF]; - if (totalCost > best) - break; - } - return totalCost; - } - - private int naiveNearestNeighbor(ByteBuffer vec, ByteBuffer modelDescriptors) { - int neighbor = -1; - int d, dist1 = Integer.MAX_VALUE, dist2 = Integer.MAX_VALUE; - int size = vec.limit() - vec.position(); - - for (int i = 0; i * size < modelDescriptors.capacity(); i++) { - ByteBuffer mvec = (ByteBuffer) modelDescriptors.position(i * size).limit((i + 1) * size); - d = compareDescriptors((ByteBuffer) vec.reset(), mvec, dist2); - if (d < dist1) { - dist2 = dist1; - dist1 = d; - neighbor = i; - } else if (d < dist2) { - dist2 = d; - } - } - if (dist1 < distanceThreshold * dist2) - return neighbor; - return -1; - } - - private void findPairs(Mat objectDescriptors, Mat imageDescriptors) { - int size = imageDescriptors.cols(); - ByteBuffer objectBuf = objectDescriptors.createBuffer(); - ByteBuffer imageBuf = imageDescriptors.createBuffer(); - - for (int i = 0; i * size < objectBuf.capacity(); i++) { - ByteBuffer descriptor = (ByteBuffer) objectBuf.position(i * size).limit((i + 1) * size).mark(); - int nearestNeighbor = naiveNearestNeighbor(descriptor, imageBuf); - if (nearestNeighbor >= 0) { - ptpairs.add(i); - ptpairs.add(nearestNeighbor); - } - } - } - - private void flannFindPairs(Mat objectDescriptors, Mat imageDescriptors) { - int length = objectDescriptors.rows(); - flannIndex.build(imageDescriptors, indexParams, FLANN_DIST_HAMMING); - flannIndex.knnSearch(objectDescriptors, indicesMat, distsMat, 2, searchParams); - IntBuffer indicesBuf = indicesMat.createBuffer(); - IntBuffer distsBuf = distsMat.createBuffer(); - for (int i = 0; i < length; i++) { - if (distsBuf.get(2 * i) < distanceThreshold * distsBuf.get(2 * i + 1)) { - ptpairs.add(i); - ptpairs.add(indicesBuf.get(2 * i)); - } - } - } - - private double[] locatePlanarObject(KeyPointVector objectKeypoints, Mat objectDescriptors, - KeyPointVector imageKeypoints, Mat imageDescriptors, double[] srcCorners) { - ptpairs.clear(); - if (useFLANN) { - flannFindPairs(objectDescriptors, imageDescriptors); - } else { - findPairs(objectDescriptors, imageDescriptors); - } - int n = ptpairs.size() / 2; - logger.info("筛选后共有" + n + "个吻合点"); - if (n < matchesMin) { - return null; - } - - pt1.resize(n); - pt2.resize(n); - mask.resize(n); - FloatBuffer pt1Idx = pt1.createBuffer(); - FloatBuffer pt2Idx = pt2.createBuffer(); - for (int i = 0; i < n; i++) { - Point2f p1 = objectKeypoints.get(ptpairs.get(2 * i)).pt(); - pt1Idx.put(2 * i, p1.x()); - pt1Idx.put(2 * i + 1, p1.y()); - Point2f p2 = imageKeypoints.get(ptpairs.get(2 * i + 1)).pt(); - pt2Idx.put(2 * i, p2.x()); - pt2Idx.put(2 * i + 1, p2.y()); - } - - H = findHomography(pt1, pt2, CV_RANSAC, ransacReprojThreshold, mask, 2000, 0.995); - if (H.empty() || countNonZero(mask) < matchesMin) { - return null; - } - - double[] h = (double[]) H.createIndexer(false).array(); - double[] dstCorners = new double[srcCorners.length]; - for (int i = 0; i < srcCorners.length / 2; i++) { - double x = srcCorners[2 * i], y = srcCorners[2 * i + 1]; - double Z = 1 / (h[6] * x + h[7] * y + h[8]); - double X = (h[0] * x + h[1] * y + h[2]) * Z; - double Y = (h[3] * x + h[4] * y + h[5]) * Z; - dstCorners[2 * i] = X; - dstCorners[2 * i + 1] = Y; - } - return dstCorners; - } - - public static Scalar randColor() { - int b, g, r; - b = ThreadLocalRandom.current().nextInt(0, 255); - g = ThreadLocalRandom.current().nextInt(0, 255); - r = ThreadLocalRandom.current().nextInt(0, 255); - return new Scalar(b, g, r, 0); - } - - public FindResult getAKAZEFindResult(File temFile, File beforeFile) throws IOException { - IplImage object = cvLoadImage(temFile.getAbsolutePath(), IMREAD_GRAYSCALE); - IplImage image = cvLoadImage(beforeFile.getAbsolutePath(), IMREAD_GRAYSCALE); - logger.info("原图宽:" + image.width()); - logger.info("原图高:" + image.height()); - if (object == null || image == null) { - logger.error("读取图片失败!"); - temFile.delete(); - beforeFile.delete(); - return null; - } - - IplImage correspond = IplImage.create(image.width() + object.width(), image.height(), 8, 1); - cvSetImageROI(correspond, cvRect(0, 0, image.width(), correspond.height())); - cvCopy(image, correspond); - cvSetImageROI(correspond, cvRect(image.width(), 0, object.width(), object.height())); - cvCopy(object, correspond); - cvResetImageROI(correspond); - - objectImage = object; - useFLANN = true; - ransacReprojThreshold = 3; - init(); - - long start = System.currentTimeMillis(); - double[] dst_corners = find(image); - FindResult findResult = new FindResult(); - findResult.setTime((int) (System.currentTimeMillis() - start)); - logger.info("特征匹配时间: " + (System.currentTimeMillis() - start) + " ms"); - - IplImage correspondColor = IplImage.create(correspond.width(), correspond.height(), 8, 3); - cvCvtColor(correspond, correspondColor, CV_GRAY2BGR); - cvSetImageROI(correspondColor, cvRect(0, 0, image.width(), correspondColor.height())); - cvCopy(cvLoadImage(beforeFile.getAbsolutePath(), IMREAD_COLOR), correspondColor); - cvSetImageROI(correspondColor, cvRect(image.width(), 0, object.width(), object.height())); - cvCopy(cvLoadImage(temFile.getAbsolutePath(), IMREAD_COLOR), correspondColor); - cvResetImageROI(correspondColor); - - if (dst_corners != null) { - int resultX = 0; - int resultY = 0; - for (int i = 0; i < 4; i++) { - int j = (i + 1) % 4; - int x1 = (int) Math.round(dst_corners[2 * i]); - int y1 = (int) Math.round(dst_corners[2 * i + 1]); - int x2 = (int) Math.round(dst_corners[2 * j]); - int y2 = (int) Math.round(dst_corners[2 * j + 1]); - line(cvarrToMat(correspondColor), new Point(x1, y1), - new Point(x2, y2), - Scalar.RED, 2, CV_AA, 0); - if (i == 0) { - resultX = (x1 + x2) / 2; - } - if (i == 1) { - resultY = (y1 + y2) / 2; - } - } - if (resultX == 0 && resultY == 0) { - temFile.delete(); - beforeFile.delete(); - return null; - } - findResult.setX(resultX); - findResult.setY(resultY); - logger.info("结果坐标为(" + resultX + "," + resultY + ")"); - } - - if (objectKeypoints != null) { - for (int i = 0; i < objectKeypoints.size(); i++) { - KeyPoint r = objectKeypoints.get(i); - Point center = new Point(Math.round(r.pt().x()) + image.width(), Math.round(r.pt().y())); - int radius = Math.round(r.size() / 2); - circle(cvarrToMat(correspondColor), center, radius, randColor(), 1, CV_AA, 0); - } - } - - if (imageKeypoints != null) { - for (int i = 0; i < imageKeypoints.size(); i++) { - KeyPoint r = imageKeypoints.get(i); - Point center = new Point(Math.round(r.pt().x()), Math.round(r.pt().y())); - int radius = Math.round(r.size() / 2); - circle(cvarrToMat(correspondColor), center, radius, randColor(), 1, CV_AA, 0); - } - } - - for (int i = 0; i < ptpairs.size(); i += 2) { - Point2f pt1 = objectKeypoints.get(ptpairs.get(i)).pt(); - Point2f pt2 = imageKeypoints.get(ptpairs.get(i + 1)).pt(); - line(cvarrToMat(correspondColor), new Point(Math.round(pt1.x()) + image.width(), Math.round(pt1.y())), - new Point(Math.round(pt2.x()), Math.round(pt2.y())), - randColor(), 1, CV_AA, 0); - } - SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd"); - File folder = new File("imageFiles" + File.separator - + sf.format(Calendar.getInstance().getTimeInMillis())); - if (!folder.exists()) { - folder.mkdirs(); - } - File fileName = new File(folder.getPath() + File.separator + - UUID.randomUUID() + ".jpg"); - cvSaveImage(fileName.getAbsolutePath(), correspondColor); - findResult.setUrl(fileTool.upload(fileName)); - temFile.delete(); - beforeFile.delete(); - return findResult; - } -} \ No newline at end of file diff --git a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/SIFTFinder.java b/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/SIFTFinder.java deleted file mode 100644 index 330a8f6c..00000000 --- a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/SIFTFinder.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.cloud.sonic.folder.cv; - -import org.bytedeco.opencv.opencv_core.*; -import org.bytedeco.opencv.opencv_features2d.FlannBasedMatcher; -import org.bytedeco.opencv.opencv_xfeatures2d.SIFT; -import org.cloud.sonic.folder.models.FindResult; -import org.cloud.sonic.folder.tools.FileTool; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.io.File; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.*; - -import static org.bytedeco.opencv.global.opencv_features2d.drawMatchesKnn; -import static org.bytedeco.opencv.global.opencv_imgcodecs.imread; -import static org.bytedeco.opencv.global.opencv_imgcodecs.imwrite; -import static org.bytedeco.opencv.global.opencv_imgproc.*; - -/** - * @author ZhouYiXun - * @des sift算法 - * @date 2022/1/4 21:49 - */ -@Component -public class SIFTFinder { - private final Logger logger = LoggerFactory.getLogger(SIFTFinder.class); - @Autowired - private FileTool fileTool; - - public FindResult getSIFTFindResult(File temFile, File beforeFile) throws IOException { - Mat image01 = imread(beforeFile.getAbsolutePath()); - Mat image02 = imread(temFile.getAbsolutePath()); - - Mat image1 = new Mat(); - Mat image2 = new Mat(); - cvtColor(image01, image1, COLOR_BGR2GRAY); - cvtColor(image02, image2, COLOR_BGR2GRAY); - - KeyPointVector keyPointVector1 = new KeyPointVector(); - KeyPointVector keyPointVector2 = new KeyPointVector(); - Mat image11 = new Mat(); - Mat image22 = new Mat(); - - long start = System.currentTimeMillis(); - SIFT sift = SIFT.create(); - sift.detectAndCompute(image1, image1, keyPointVector1, image11); - sift.detectAndCompute(image2, image2, keyPointVector2, image22); - - FlannBasedMatcher flannBasedMatcher = new FlannBasedMatcher(); - DMatchVectorVector matchPoints = new DMatchVectorVector(); - - flannBasedMatcher.knnMatch(image11, image22, matchPoints, 2); - logger.info("处理前共有匹配数:" + matchPoints.size()); - DMatchVectorVector goodMatches = new DMatchVectorVector(); - - List xs = new ArrayList<>(); - List ys = new ArrayList<>(); - for (long i = 0; i < matchPoints.size(); i++) { - if (matchPoints.get(i).size() >= 2) { - DMatch match1 = matchPoints.get(i).get(0); - DMatch match2 = matchPoints.get(i).get(1); - - if (match1.distance() <= 0.6 * match2.distance()) { - xs.add((int) keyPointVector1.get(match1.queryIdx()).pt().x()); - ys.add((int) keyPointVector1.get(match1.queryIdx()).pt().y()); - goodMatches.push_back(matchPoints.get(i)); - } - } - } - logger.info("处理后匹配数:" + goodMatches.size()); - if (goodMatches.size() <= 4) { - temFile.delete(); - beforeFile.delete(); - return null; - } - FindResult findResult = new FindResult(); - findResult.setTime((int) (System.currentTimeMillis() - start)); - Mat result = new Mat(); - - drawMatchesKnn(image01, keyPointVector1, image02, keyPointVector2, goodMatches, result); - - int resultX = majorityElement(xs); - int resultY = majorityElement(ys); - findResult.setX(resultX); - findResult.setY(resultY); - logger.info("结果坐标为(" + resultX + "," + resultY + ")"); - circle(result, new Point(resultX, resultY), 5, Scalar.RED, 10, CV_AA, 0); - SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd"); - File folder = new File("imageFiles" + File.separator - + sf.format(Calendar.getInstance().getTimeInMillis())); - if (!folder.exists()) { - folder.mkdirs(); - } - File fileName = new File(folder.getPath() + File.separator + - UUID.randomUUID() + ".jpg"); - imwrite(fileName.getAbsolutePath(), result); - findResult.setUrl(fileTool.upload(fileName)); - temFile.delete(); - beforeFile.delete(); - return findResult; - } - - public static int majorityElement(List nums) { - double j; - Collections.sort(nums); - int size = nums.size(); - if (size % 2 == 1) { - j = nums.get((size - 1) / 2); - } else { - j = (nums.get(size / 2 - 1) + nums.get(size / 2) + 0.0) / 2; - } - return (int) j; - } -} diff --git a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/SimilarityChecker.java b/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/SimilarityChecker.java deleted file mode 100644 index af2023ce..00000000 --- a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/SimilarityChecker.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.cloud.sonic.folder.cv; - -import org.bytedeco.opencv.global.opencv_core; -import org.bytedeco.opencv.opencv_core.Mat; -import org.bytedeco.opencv.opencv_core.Scalar; -import org.bytedeco.opencv.opencv_core.Size; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import java.io.File; -import java.math.BigDecimal; -import java.math.RoundingMode; - -import static org.bytedeco.opencv.global.opencv_core.*; -import static org.bytedeco.opencv.global.opencv_imgcodecs.imread; -import static org.bytedeco.opencv.global.opencv_imgproc.GaussianBlur; - -/** - * @author ZhouYiXun - * @des 相似度比对 - * @date 2022/1/4 21:49 - */ -@Component -public class SimilarityChecker { - private final Logger logger = LoggerFactory.getLogger(SimilarityChecker.class); - - public double getSimilarMSSIMScore(File file1, File file2) { - synchronized (SimilarityChecker.class) { - Mat i1 = imread(file1.getAbsolutePath()); - Mat i2 = imread(file2.getAbsolutePath()); - if (i1.size().get() != i2.size().get()) { - return 0; - } - double C1 = 6.5025, C2 = 58.5225; - int d = opencv_core.CV_32F; - Mat I1 = new Mat(); - Mat I2 = new Mat(); - i1.convertTo(I1, d); - i2.convertTo(I2, d); - Mat I2_2 = I2.mul(I2).asMat(); - Mat I1_2 = I1.mul(I1).asMat(); - Mat I1_I2 = I1.mul(I2).asMat(); - Mat mu1 = new Mat(); - Mat mu2 = new Mat(); - GaussianBlur(I1, mu1, new Size(11, 11), 1.5); - GaussianBlur(I2, mu2, new Size(11, 11), 1.5); - Mat mu1_2 = mu1.mul(mu1).asMat(); - Mat mu2_2 = mu2.mul(mu2).asMat(); - Mat mu1_mu2 = mu1.mul(mu2).asMat(); - Mat sigma1_2 = new Mat(); - Mat sigma2_2 = new Mat(); - Mat sigma12 = new Mat(); - GaussianBlur(I1_2, sigma1_2, new Size(11, 11), 1.5); - sigma1_2 = subtract(sigma1_2, mu1_2).asMat(); - GaussianBlur(I2_2, sigma2_2, new Size(11, 11), 1.5); - sigma2_2 = subtract(sigma2_2, mu2_2).asMat(); - GaussianBlur(I1_I2, sigma12, new Size(11, 11), 1.5); - sigma12 = subtract(sigma12, mu1_mu2).asMat(); - Mat t1, t2, t3; - t1 = add(multiply(2, mu1_mu2), Scalar.all(C1)).asMat(); - t2 = add(multiply(2, sigma12), Scalar.all(C2)).asMat(); - t3 = t1.mul(t2).asMat(); - t1 = add(add(mu1_2, mu2_2), Scalar.all(C1)).asMat(); - t2 = add(add(sigma1_2, sigma2_2), Scalar.all(C2)).asMat(); - t1 = t1.mul(t2).asMat(); - Mat ssim_map = new Mat(); - divide(t3, t1, ssim_map); - Scalar mSsim = mean(ssim_map); - file1.delete(); - file2.delete(); - return new BigDecimal((mSsim.get(0) + mSsim.get(1) + mSsim.get(2)) / 3).setScale(2, RoundingMode.DOWN).doubleValue(); - } - } -} \ No newline at end of file diff --git a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/TemMatcher.java b/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/TemMatcher.java deleted file mode 100644 index b718ddf3..00000000 --- a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/TemMatcher.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.cloud.sonic.folder.cv; - -import org.bytedeco.javacpp.DoublePointer; -import org.bytedeco.opencv.opencv_core.*; -import org.cloud.sonic.folder.models.FindResult; -import org.cloud.sonic.folder.tools.FileTool; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.io.File; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.UUID; -import java.util.concurrent.ThreadLocalRandom; - -import static org.bytedeco.opencv.global.opencv_core.*; -import static org.bytedeco.opencv.global.opencv_imgcodecs.*; -import static org.bytedeco.opencv.global.opencv_imgproc.*; - -/** - * @author ZhouYiXun - * @des 模板匹配 - * @date 2022/1/4 21:49 - */ -@Component -public class TemMatcher { - private final Logger logger = LoggerFactory.getLogger(TemMatcher.class); - @Autowired - private FileTool fileTool; - - public FindResult getTemMatchResult(File temFile, File beforeFile) throws IOException { - try { - Mat sourceColor = imread(beforeFile.getAbsolutePath()); - Mat sourceGrey = new Mat(sourceColor.size(), CV_8UC1); - cvtColor(sourceColor, sourceGrey, COLOR_BGR2GRAY); - Mat template = imread(temFile.getAbsolutePath(), IMREAD_GRAYSCALE); - Size size = new Size(sourceGrey.cols() - template.cols() + 1, sourceGrey.rows() - template.rows() + 1); - Mat result = new Mat(size, CV_32FC1); - - long start = System.currentTimeMillis(); - matchTemplate(sourceGrey, template, result, TM_CCORR_NORMED); - DoublePointer minVal = new DoublePointer(); - DoublePointer maxVal = new DoublePointer(); - Point min = new Point(); - Point max = new Point(); - minMaxLoc(result, minVal, maxVal, min, max, null); - rectangle(sourceColor, new Rect(max.x(), max.y(), template.cols(), template.rows()), randColor(), 2, 0, 0); - FindResult findResult = new FindResult(); - findResult.setTime((int) (System.currentTimeMillis() - start)); - SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd"); - File folder = new File("imageFiles" + File.separator - + sf.format(Calendar.getInstance().getTimeInMillis())); - if (!folder.exists()) { - folder.mkdirs(); - } - File fileName = new File(folder.getPath() + File.separator + - UUID.randomUUID() + ".jpg"); - imwrite(fileName.getAbsolutePath(), sourceColor); - findResult.setX(max.x() + template.cols() / 2); - findResult.setY(max.y() + template.rows() / 2); - findResult.setUrl(fileTool.upload(fileName)); - return findResult; - } finally { - temFile.delete(); - beforeFile.delete(); - } - } - - public static Scalar randColor() { - int b, g, r; - b = ThreadLocalRandom.current().nextInt(0, 255 + 1); - g = ThreadLocalRandom.current().nextInt(0, 255 + 1); - r = ThreadLocalRandom.current().nextInt(0, 255 + 1); - return new Scalar(b, g, r, 0); - } -} \ No newline at end of file diff --git a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/TextReader.java b/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/TextReader.java deleted file mode 100644 index 843a1a47..00000000 --- a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/cv/TextReader.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.cloud.sonic.folder.cv; - -import org.bytedeco.javacpp.BytePointer; -import org.bytedeco.leptonica.PIX; -import org.bytedeco.tesseract.TessBaseAPI; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import java.io.File; - -import static org.bytedeco.leptonica.global.lept.pixRead; - -/** - * @author ZhouYiXun - * @des 文字识别(即将弃用) - * @date 2022/1/4 21:49 - */ -@Component -public class TextReader { - private final Logger logger = LoggerFactory.getLogger(TextReader.class); - - public String getTessResult(File file, String language) throws Exception { - BytePointer outText = null; - TessBaseAPI api = new TessBaseAPI(); - String result = ""; - if (api.Init("language", language) != 0) { - logger.info("找不到语言包!"); - return result; - } - try { - PIX image = pixRead(file.getAbsolutePath()); - api.SetImage(image); - outText = api.GetUTF8Text(); - result = outText.getString(); - } finally { - file.delete(); - api.End(); - outText.deallocate(); - } - return result; - } -} diff --git a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/models/FindResult.java b/sonic-server-folder/src/main/java/org/cloud/sonic/folder/models/FindResult.java deleted file mode 100644 index 413a5dfe..00000000 --- a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/models/FindResult.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.cloud.sonic.folder.models; - -public class FindResult { - private int x; - private int y; - private String url; - private int time; - - public FindResult() { - x = 0; - y = 0; - url = ""; - time = 0; - } - - public int getX() { - return x; - } - - public void setX(int x) { - this.x = x; - } - - public int getY() { - return y; - } - - public void setY(int y) { - this.y = y; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public int getTime() { - return time; - } - - public void setTime(int time) { - this.time = time; - } - - @Override - public String toString() { - return "FindResult{" + - "x=" + x + - ", y=" + y + - ", url='" + url + '\'' + - ", time=" + time + - '}'; - } -} diff --git a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/tools/FileTool.java b/sonic-server-folder/src/main/java/org/cloud/sonic/folder/tools/FileTool.java index 1acc0ac1..c22a66d1 100644 --- a/sonic-server-folder/src/main/java/org/cloud/sonic/folder/tools/FileTool.java +++ b/sonic-server-folder/src/main/java/org/cloud/sonic/folder/tools/FileTool.java @@ -55,17 +55,6 @@ public String upload(String folderName, MultipartFile file) throws IOException { return host + "/api/folder/" + local.getPath().replaceAll("\\\\", "/"); } - /** - * @param file 文件夹 - * @return java.lang.String - * @author ZhouYiXun - * @des 上传 - * @date 2021/8/18 20:41 - */ - public String upload(File file) throws IOException { - return host + "/api/folder/" + file.getPath().replaceAll("\\\\", "/"); - } - /** * @param file * @return void diff --git a/sonic-server-gateway/pom.xml b/sonic-server-gateway/pom.xml index dbf38114..9fa9c29b 100644 --- a/sonic-server-gateway/pom.xml +++ b/sonic-server-gateway/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-gateway - v1.3.0-beta2 + v1.3.0-release jar @@ -49,23 +49,23 @@ - - - - - org.springframework.boot - spring-boot-maven-plugin - - true - - - - com.spotify - docker-maven-plugin - - true - - - - + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sonic-server-task/pom.xml b/sonic-server-task/pom.xml index c5d1c097..03f401f5 100644 --- a/sonic-server-task/pom.xml +++ b/sonic-server-task/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-task - v1.3.0-beta2 + v1.3.0-release jar @@ -98,23 +98,23 @@ - - - - - org.springframework.boot - spring-boot-maven-plugin - - true - - - - com.spotify - docker-maven-plugin - - true - - - - + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sonic-server-transport/pom.xml b/sonic-server-transport/pom.xml index f1c2f375..7fd08f42 100644 --- a/sonic-server-transport/pom.xml +++ b/sonic-server-transport/pom.xml @@ -10,7 +10,7 @@ 4.0.0 sonic-server-transport - v1.3.0-beta2 + v1.3.0-release jar @@ -65,23 +65,23 @@ - - - - - org.springframework.boot - spring-boot-maven-plugin - - true - - - - com.spotify - docker-maven-plugin - - true - - - - + + + + + + + + + + + + + + + + + + + \ No newline at end of file