mirror of
https://gitee.com/open-visual/face-search.git
synced 2025-07-25 19:41:42 +08:00
add:修复由于人脸过小,导致对齐异常的BUG
This commit is contained in:
parent
76c3eaa7e0
commit
3dda2d53a1
@ -12,6 +12,8 @@ import java.util.Map;
|
||||
* 五点对齐法
|
||||
*/
|
||||
public class Simple005pFaceAlignment implements FaceAlignment {
|
||||
/**最小边的长度**/
|
||||
private final static float minEdgeLength = 128;
|
||||
|
||||
/**对齐矩阵**/
|
||||
private final static double[][] dst_points = new double[][]{
|
||||
@ -31,16 +33,33 @@ public class Simple005pFaceAlignment implements FaceAlignment {
|
||||
*/
|
||||
@Override
|
||||
public ImageMat inference(ImageMat imageMat, FaceInfo.Points imagePoint, Map<String, Object> params) {
|
||||
double [][] image_points;
|
||||
if(imagePoint.size() == 5){
|
||||
image_points = imagePoint.toDoubleArray();
|
||||
}else if(imagePoint.size() == 106){
|
||||
image_points = imagePoint.select(38, 88, 80, 52, 61).toDoubleArray();
|
||||
}else{
|
||||
throw new RuntimeException("need 5 point, but get "+ imagePoint.size());
|
||||
ImageMat alignmentImageMat = null;
|
||||
try {
|
||||
FaceInfo.Points alignmentPoints = imagePoint;
|
||||
if(imageMat.getWidth() < minEdgeLength || imageMat.getHeight() < minEdgeLength){
|
||||
float scale = minEdgeLength / Math.min(imageMat.getWidth(), imageMat.getHeight());
|
||||
int newWidth = Float.valueOf(imageMat.getWidth() * scale).intValue();
|
||||
int newHeight = Float.valueOf(imageMat.getHeight() * scale).intValue();
|
||||
alignmentImageMat = imageMat.resizeAndNoReleaseMat(newWidth, newHeight);
|
||||
alignmentPoints = imagePoint.operateMultiply(scale);
|
||||
}else{
|
||||
alignmentImageMat = imageMat.clone();
|
||||
}
|
||||
double [][] image_points;
|
||||
if(alignmentPoints.size() == 5){
|
||||
image_points = alignmentPoints.toDoubleArray();
|
||||
}else if(alignmentPoints.size() == 106){
|
||||
image_points = alignmentPoints.select(38, 88, 80, 52, 61).toDoubleArray();
|
||||
}else{
|
||||
throw new RuntimeException("need 5 point, but get "+ imagePoint.size());
|
||||
}
|
||||
Mat alignMat = AlignUtil.alignedImage(alignmentImageMat.toCvMat(), image_points, 112, 112, dst_points);
|
||||
return ImageMat.fromCVMat(alignMat);
|
||||
}finally {
|
||||
if(null != alignmentImageMat){
|
||||
alignmentImageMat.release();
|
||||
}
|
||||
}
|
||||
Mat alignMat = AlignUtil.alignedImage(imageMat.toCvMat(), image_points, 112, 112, dst_points);
|
||||
return ImageMat.fromCVMat(alignMat);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,9 @@ import java.util.Map;
|
||||
|
||||
public class Simple106pFaceAlignment implements FaceAlignment {
|
||||
|
||||
/**最小边的长度**/
|
||||
private final static float minEdgeLength = 128;
|
||||
|
||||
/**矫正的偏移**/
|
||||
private final static double x_offset = 0;
|
||||
private final static double y_offset = -8;
|
||||
@ -125,14 +128,31 @@ public class Simple106pFaceAlignment implements FaceAlignment {
|
||||
|
||||
@Override
|
||||
public ImageMat inference(ImageMat imageMat, FaceInfo.Points imagePoint, Map<String, Object> params) {
|
||||
double [][] image_points;
|
||||
if(imagePoint.size() == 106){
|
||||
image_points = imagePoint.toDoubleArray();
|
||||
}else{
|
||||
throw new RuntimeException("need 106 point, but get "+ imagePoint.size());
|
||||
ImageMat alignmentImageMat = null;
|
||||
try {
|
||||
FaceInfo.Points alignmentPoints = imagePoint;
|
||||
if(imageMat.getWidth() < minEdgeLength || imageMat.getHeight() < minEdgeLength){
|
||||
float scale = minEdgeLength / Math.min(imageMat.getWidth(), imageMat.getHeight());
|
||||
int newWidth = Float.valueOf(imageMat.getWidth() * scale).intValue();
|
||||
int newHeight = Float.valueOf(imageMat.getHeight() * scale).intValue();
|
||||
alignmentImageMat = imageMat.resizeAndNoReleaseMat(newWidth, newHeight);
|
||||
alignmentPoints = imagePoint.operateMultiply(scale);
|
||||
}else{
|
||||
alignmentImageMat = imageMat.clone();
|
||||
}
|
||||
double [][] image_points;
|
||||
if(alignmentPoints.size() == 106){
|
||||
image_points = alignmentPoints.toDoubleArray();
|
||||
}else{
|
||||
throw new RuntimeException("need 106 point, but get "+ alignmentPoints.size());
|
||||
}
|
||||
Mat alignMat = AlignUtil.alignedImage(alignmentImageMat.toCvMat(), image_points, 112, 112, dst_points);
|
||||
return ImageMat.fromCVMat(alignMat);
|
||||
}finally {
|
||||
if(null != alignmentImageMat){
|
||||
alignmentImageMat.release();
|
||||
}
|
||||
}
|
||||
Mat alignMat = AlignUtil.alignedImage(imageMat.toCvMat(), image_points, 112, 112, dst_points);
|
||||
return ImageMat.fromCVMat(alignMat);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,12 +36,12 @@ public class FaceCompareTest extends BaseTest {
|
||||
// private static String imagePath2 = "face-search-core/src/test/resources/images/faces/compare/1682052669004.jpg";
|
||||
// private static String imagePath2 = "face-search-core/src/test/resources/images/faces/compare/1682053163961.jpg";
|
||||
// private static String imagePath1 = "face-search-test/src/main/resources/image/validate/index/张一鸣/1c7abcaf2dabdd2bc08e90c224d4c381.jpeg";
|
||||
private static String imagePath1 = "face-search-test/src/main/resources/image/validate/index/张一鸣/0762c790db41a64f8f3f97598a825372.jpeg";
|
||||
private static String imagePath2 = "face-search-test/src/main/resources/image/validate/index/张一鸣/ea191e61bdd4be8fddc89b828f5399b6.jpeg";
|
||||
private static String imagePath1 = "face-search-core/src/test/resources/images/faces/small/1.png";
|
||||
private static String imagePath2 = "face-search-core/src/test/resources/images/faces/small/2.png";
|
||||
public static void main(String[] args) {
|
||||
//口罩模型0.48,light模型0.52,normal模型0.62
|
||||
Map<String, String> map1 = getImagePathMap(imagePath);
|
||||
Map<String, String> map2 = getImagePathMap(imagePath3);
|
||||
Map<String, String> map1 = getImagePathMap(imagePath1);
|
||||
Map<String, String> map2 = getImagePathMap(imagePath2);
|
||||
FaceDetection insightScrfdFaceDetection = new InsightScrfdFaceDetection(modelScrfdPath, 1);
|
||||
FaceKeyPoint insightCoordFaceKeyPoint = new InsightCoordFaceKeyPoint(modelCoordPath, 1);
|
||||
FaceRecognition insightArcFaceRecognition = new InsightArcFaceRecognition(modelArcPath, 1);
|
||||
|
BIN
face-search-core/src/test/resources/images/faces/small/1.png
Normal file
BIN
face-search-core/src/test/resources/images/faces/small/1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 616 KiB |
BIN
face-search-core/src/test/resources/images/faces/small/2.png
Normal file
BIN
face-search-core/src/test/resources/images/faces/small/2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 727 KiB |
Loading…
x
Reference in New Issue
Block a user