From 83ed249c1447da540675ffea784fb3b558b42e6f Mon Sep 17 00:00:00 2001 From: divenswu Date: Thu, 13 Jul 2023 09:54:02 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E6=9B=B4=E6=96=B0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/extract/FaceFeatureExtractTest.java | 13 ++++++---- .../models/InsightScrfdFaceDetectionTest.java | 24 +++++++++++++++---- .../models/PcnNetworkFaceDetectionTest.java | 3 ++- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/face-search-core/src/test/java/com/visual/face/search/core/test/extract/FaceFeatureExtractTest.java b/face-search-core/src/test/java/com/visual/face/search/core/test/extract/FaceFeatureExtractTest.java index 59b6f70..bdff7b4 100755 --- a/face-search-core/src/test/java/com/visual/face/search/core/test/extract/FaceFeatureExtractTest.java +++ b/face-search-core/src/test/java/com/visual/face/search/core/test/extract/FaceFeatureExtractTest.java @@ -1,5 +1,6 @@ package com.visual.face.search.core.test.extract; +import com.alibaba.fastjson.JSONObject; import com.visual.face.search.core.base.*; import com.visual.face.search.core.domain.ExtParam; import com.visual.face.search.core.domain.FaceImage; @@ -29,8 +30,9 @@ public class FaceFeatureExtractTest extends BaseTest { private static String modelArcPath = "face-search-core/src/main/resources/model/onnx/recognition_face_arc/glint360k_cosface_r18_fp16_0.1.onnx"; private static String modelArrPath = "face-search-core/src/main/resources/model/onnx/attribute_gender_age/insight_gender_age.onnx"; -// private static String imagePath = "face-search-core/src/test/resources/images/faces"; - private static String imagePath = "face-search-core/src/test/resources/images/faces/debug/debug_0001.jpg"; + private static String imagePath = "face-search-core/src/test/resources/images/faces"; +// private static String imagePath = "face-search-core/src/test/resources/images/faces/debug/debug_0001.jpg"; +// private static String imagePath = "face-search-core/src/test/resources/images/faces/rotate/rotate_0002.jpg"; public static void main(String[] args) { @@ -44,7 +46,7 @@ public class FaceFeatureExtractTest extends BaseTest { FaceAttribute insightFaceAttribute = new InsightAttributeDetection(modelArrPath, 1); FaceFeatureExtractor extractor = new FaceFeatureExtractorImpl( - pcnNetworkFaceDetection, insightScrfdFaceDetection, insightCoordFaceKeyPoint, + insightScrfdFaceDetection, pcnNetworkFaceDetection, insightCoordFaceKeyPoint, simple005pFaceAlignment, insightArcFaceRecognition, insightFaceAttribute); for(String fileName : map.keySet()){ String imageFilePath = map.get(fileName); @@ -56,7 +58,8 @@ public class FaceFeatureExtractTest extends BaseTest { .setTopK(20) .setScoreTh(0) .setIouTh(0); - FaceImage faceImage = extractor.extract(ImageMat.fromCVMat(image), extParam, null); + Map params = new JSONObject().fluentPut(InsightScrfdFaceDetection.scrfdFaceNeedCheckFaceAngleParamKey, true); + FaceImage faceImage = extractor.extract(ImageMat.fromCVMat(image), extParam, params); List faceInfos = faceImage.faceInfos(); long e = System.currentTimeMillis(); System.out.println("fileName="+fileName+",\tcost="+(e-s)+",\t"+faceInfos); @@ -67,7 +70,7 @@ public class FaceFeatureExtractTest extends BaseTest { Imgproc.line(image, new Point(box.rightTop.x, box.rightTop.y), new Point(box.rightBottom.x, box.rightBottom.y), new Scalar(255,0,0), 1); Imgproc.line(image, new Point(box.rightBottom.x, box.rightBottom.y), new Point(box.leftBottom.x, box.leftBottom.y), new Scalar(255,0,0), 1); Imgproc.line(image, new Point(box.leftBottom.x, box.leftBottom.y), new Point(box.leftTop.x, box.leftTop.y), new Scalar(255,0,0), 1); - Imgproc.putText(image, String.valueOf(faceInfo.angle), new Point(box.leftTop.x, box.leftTop.y), Imgproc.FONT_HERSHEY_PLAIN, 1, new Scalar(0,0,255)); + Imgproc.putText(image, String.valueOf(faceInfo.angle), new Point(box.leftTop.x, box.leftTop.y+15), Imgproc.FONT_HERSHEY_PLAIN, 1, new Scalar(0,0,255)); // Imgproc.rectangle(image, new Point(faceInfo.box.x1(), faceInfo.box.y1()), new Point(faceInfo.box.x2(), faceInfo.box.y2()), new Scalar(255,0,255)); FaceInfo.FaceBox box1 = faceInfo.rotateFaceBox(); diff --git a/face-search-core/src/test/java/com/visual/face/search/core/test/models/InsightScrfdFaceDetectionTest.java b/face-search-core/src/test/java/com/visual/face/search/core/test/models/InsightScrfdFaceDetectionTest.java index 60afa42..be620e4 100755 --- a/face-search-core/src/test/java/com/visual/face/search/core/test/models/InsightScrfdFaceDetectionTest.java +++ b/face-search-core/src/test/java/com/visual/face/search/core/test/models/InsightScrfdFaceDetectionTest.java @@ -1,5 +1,6 @@ package com.visual.face.search.core.test.models; +import com.alibaba.fastjson.JSONObject; import com.visual.face.search.core.domain.FaceInfo; import com.visual.face.search.core.domain.ImageMat; import com.visual.face.search.core.models.InsightScrfdFaceDetection; @@ -11,15 +12,16 @@ import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; +import java.util.HashMap; import java.util.List; import java.util.Map; public class InsightScrfdFaceDetectionTest extends BaseTest { private static String modelPath = "face-search-core/src/main/resources/model/onnx/detection_face_scrfd/scrfd_500m_bnkps.onnx"; - private static String imagePath = "face-search-core/src/test/resources/images/faces"; +// private static String imagePath = "face-search-core/src/test/resources/images/faces"; + private static String imagePath = "face-search-core/src/test/resources/images/faces/rotate/rotate_0001.jpg"; // private static String imagePath = "face-search-core/src/test/resources/images/faces/rotate"; -// private static String imagePath = "face-search-core/src/test/resources/images/faces/debug"; public static void main(String[] args) { @@ -31,7 +33,9 @@ public class InsightScrfdFaceDetectionTest extends BaseTest { System.out.println(imageFilePath); Mat image = Imgcodecs.imread(imageFilePath); long s = System.currentTimeMillis(); - List faceInfos = infer.inference(ImageMat.fromCVMat(image), 0.5f, 0.7f, null); + Map params = new JSONObject().fluentPut(InsightScrfdFaceDetection.scrfdFaceNeedCheckFaceAngleParamKey, true); + + List faceInfos = infer.inference(ImageMat.fromCVMat(image), 0.48f, 0.7f, params); long e = System.currentTimeMillis(); if(faceInfos.size() > 0){ System.out.println("fileName="+fileName+",\tcost="+(e-s)+",\t"+faceInfos.get(0).score); @@ -39,10 +43,20 @@ public class InsightScrfdFaceDetectionTest extends BaseTest { System.out.println("fileName="+fileName+",\tcost="+(e-s)+",\t"+faceInfos); } + //对坐标进行调整 for(FaceInfo faceInfo : faceInfos){ - Imgproc.rectangle(image, new Point(faceInfo.box.x1(), faceInfo.box.y1()), new Point(faceInfo.box.x2(), faceInfo.box.y2()), new Scalar(0,0,255)); + FaceInfo.FaceBox box = faceInfo.rotateFaceBox(); + Imgproc.circle(image, new Point(box.leftTop.x, box.leftTop.y), 3, new Scalar(0,0,255), -1); + Imgproc.circle(image, new Point(box.rightBottom.x, box.rightBottom.y), 3, new Scalar(0,0,255), -1); + Imgproc.line(image, new Point(box.leftTop.x, box.leftTop.y), new Point(box.rightTop.x, box.rightTop.y), new Scalar(0,0,255), 1); + Imgproc.line(image, new Point(box.rightTop.x, box.rightTop.y), new Point(box.rightBottom.x, box.rightBottom.y), new Scalar(255,0,0), 1); + Imgproc.line(image, new Point(box.rightBottom.x, box.rightBottom.y), new Point(box.leftBottom.x, box.leftBottom.y), new Scalar(255,0,0), 1); + Imgproc.line(image, new Point(box.leftBottom.x, box.leftBottom.y), new Point(box.leftTop.x, box.leftTop.y), new Scalar(255,0,0), 1); + Imgproc.putText(image, String.valueOf(faceInfo.angle), new Point(box.leftTop.x, box.leftTop.y), Imgproc.FONT_HERSHEY_PLAIN, 1, new Scalar(0,0,255)); + + FaceInfo.Points points = faceInfo.points; int pointNum = 1; - for(FaceInfo.Point keyPoint : faceInfo.points){ + for(FaceInfo.Point keyPoint : points){ Imgproc.circle(image, new Point(keyPoint.x, keyPoint.y), 3, new Scalar(0,0,255), -1); Imgproc.putText(image, String.valueOf(pointNum), new Point(keyPoint.x+1, keyPoint.y), Imgproc.FONT_HERSHEY_PLAIN, 1, new Scalar(255,0,0)); pointNum ++ ; diff --git a/face-search-core/src/test/java/com/visual/face/search/core/test/models/PcnNetworkFaceDetectionTest.java b/face-search-core/src/test/java/com/visual/face/search/core/test/models/PcnNetworkFaceDetectionTest.java index 43bbc6e..ef2fd0b 100755 --- a/face-search-core/src/test/java/com/visual/face/search/core/test/models/PcnNetworkFaceDetectionTest.java +++ b/face-search-core/src/test/java/com/visual/face/search/core/test/models/PcnNetworkFaceDetectionTest.java @@ -21,7 +21,8 @@ public class PcnNetworkFaceDetectionTest extends BaseTest { private static String model2Path = "face-search-core/src/main/resources/model/onnx/detection_face_pcn/pcn2_sd.onnx"; private static String model3Path = "face-search-core/src/main/resources/model/onnx/detection_face_pcn/pcn3_sd.onnx"; - private static String imagePath = "face-search-core/src/test/resources/images/faces"; +// private static String imagePath = "face-search-core/src/test/resources/images/faces"; + private static String imagePath = "face-search-core/src/test/resources/images/faces/rotate/rotate_0001.jpg"; // private static String imagePath = "face-search-core/src/test/resources/images/faces/rotate"; // private static String imagePath = "face-search-core/src/test/resources/images/faces/debug";