-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
492 additions
and
295 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/main/java/org/photo/modular/HivisionIDPhotos/contorller/HivisionIDPhotosController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.photo.modular.HivisionIDPhotos.contorller; | ||
|
||
import org.photo.modular.HivisionIDPhotos.request.HIDAddBackgroundRequest; | ||
import org.photo.modular.HivisionIDPhotos.request.HIDIdPhotoRequest; | ||
import org.photo.modular.HivisionIDPhotos.response.HIDHivisionResponse; | ||
import org.photo.modular.HivisionIDPhotos.service.HivisionIDPhotosService; | ||
import org.photo.util.R; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
|
||
@RestController | ||
@RequestMapping("/idPhotoApi") | ||
public class HivisionIDPhotosController { | ||
|
||
@Autowired | ||
private HivisionIDPhotosService hivisionIDPhotosService; | ||
|
||
@PostMapping("/idphoto") | ||
public HIDHivisionResponse idphoto(MultipartFile file, HIDIdPhotoRequest request) throws IOException { | ||
request.setInput_image(file); | ||
return hivisionIDPhotosService.idphoto(request); | ||
} | ||
|
||
@PostMapping("/add_background") | ||
public R<HIDHivisionResponse> add_background(MultipartFile file, HIDAddBackgroundRequest request) throws IOException { | ||
request.setInput_image(file); | ||
return R.ok(hivisionIDPhotosService.add_background(request)); | ||
} | ||
|
||
@PostMapping("/generate_layout_photos") | ||
public R<HIDHivisionResponse> generate_layout_photos(MultipartFile file, HIDAddBackgroundRequest request) throws IOException { | ||
request.setInput_image(file); | ||
return R.ok(hivisionIDPhotosService.generate_layout_photos(request)); | ||
} | ||
|
||
@PostMapping("/human_matting") | ||
public R<HIDHivisionResponse> human_matting(MultipartFile file, HIDAddBackgroundRequest request) throws IOException { | ||
request.setInput_image(file); | ||
return R.ok(hivisionIDPhotosService.human_matting(request)); | ||
} | ||
|
||
@PostMapping("/watermark") | ||
public R<HIDHivisionResponse> watermark(MultipartFile file, HIDAddBackgroundRequest request) throws IOException { | ||
request.setInput_image(file); | ||
return R.ok(hivisionIDPhotosService.watermark(request)); | ||
} | ||
|
||
@PostMapping("/set_kb") | ||
public R<HIDHivisionResponse> set_kb(MultipartFile file, HIDAddBackgroundRequest request) throws IOException { | ||
request.setInput_image(file); | ||
return R.ok(hivisionIDPhotosService.set_kb(request)); | ||
} | ||
|
||
@PostMapping("/idphoto_crop") | ||
public R<HIDHivisionResponse> idphoto_crop(MultipartFile file, HIDAddBackgroundRequest request) throws IOException { | ||
request.setInput_image(file); | ||
return R.ok(hivisionIDPhotosService.idphoto_crop(request)); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/org/photo/modular/HivisionIDPhotos/enums/HIDOptTypeEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.photo.modular.HivisionIDPhotos.enums; | ||
|
||
import cn.hutool.core.util.ObjectUtil; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
/** | ||
* 积分类型枚举 | ||
* | ||
* @author Chopper | ||
* @since 2021/3/20 10:44 | ||
*/ | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum HIDOptTypeEnum { | ||
/** | ||
* 生成证件照(底透明) | ||
*/ | ||
IDPHOTO(1, "idphoto"), | ||
/** | ||
* 添加背景色 | ||
*/ | ||
ADD_BACKGROUND(2, "add_background"), | ||
/** | ||
* 生成六寸排版照 | ||
*/ | ||
GENERATE_LAYOUT_PHOTOS(3, "generate_layout_photos"), | ||
/** | ||
* 人像抠图 | ||
*/ | ||
HUMAN_MATTING(4, "human_matting"), | ||
/** | ||
* 图像加水印 | ||
*/ | ||
WATERMARK(5, "watermark"), | ||
/** | ||
* 设置图像KB大小 | ||
*/ | ||
SET_KB(6, "set_kb"), | ||
/** | ||
* 证件照裁切 | ||
*/ | ||
IDPHOTO_CROP(7, "idphoto_crop"); | ||
|
||
|
||
private Integer value; | ||
private String name; | ||
|
||
public static String getNameByValue(Integer code){ | ||
if(ObjectUtil.isNotEmpty(code)) { | ||
for (HIDOptTypeEnum pointOptEnum : values()) { | ||
if (pointOptEnum.getValue().toString().equals(code.toString())) { | ||
return pointOptEnum.getName(); | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/photo/modular/HivisionIDPhotos/request/HIDAddBackgroundRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.photo.modular.HivisionIDPhotos.request; | ||
|
||
import lombok.Data; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Data | ||
public class HIDAddBackgroundRequest { | ||
private MultipartFile input_image; // 传入的图像文件路径 | ||
private String input_image_base64; // 传入的图像文件的base64编码 | ||
private String color; // 背景色HEX值,默认为000000 | ||
private Integer kb; // 输出照片的 KB 值,默认为None | ||
private Integer render; // 渲染模式,默认为0 | ||
private Integer dpi; // 图像分辨率,默认为300 | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/photo/modular/HivisionIDPhotos/request/HIDGenerateLayoutPhotosRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.photo.modular.HivisionIDPhotos.request; | ||
|
||
import lombok.Data; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Data | ||
public class HIDGenerateLayoutPhotosRequest { | ||
private MultipartFile input_image; // 传入的图像文件路径 | ||
private String input_image_base64; // 传入的图像文件的base64编码 | ||
private Integer height; // 输入图像的高度,默认为413 | ||
private Integer width; // 输入图像的宽度,默认为295 | ||
private Integer kb; // 输出照片的 KB 值,默认为None | ||
private Integer dpi; // 图像分辨率,默认为300 | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/photo/modular/HivisionIDPhotos/request/HIDHumanMattingRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.photo.modular.HivisionIDPhotos.request; | ||
|
||
import lombok.Data; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Data | ||
public class HIDHumanMattingRequest { | ||
private MultipartFile input_image; // 传入的图像文件路径 | ||
private String human_matting_model; // 人像分割模型,默认为modnet_photographic_portrait_matting | ||
private Integer dpi; // 图像分辨率,默认为300 | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/photo/modular/HivisionIDPhotos/request/HIDIdPhotoCropRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.photo.modular.HivisionIDPhotos.request; | ||
|
||
import lombok.Data; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Data | ||
public class HIDIdPhotoCropRequest { | ||
private MultipartFile input_image; // 传入的图像文件路径 | ||
private String input_image_base64; // 传入的图像文件的base64编码 | ||
private Integer height; // 标准证件照高度,默认为413 | ||
private Integer width; // 标准证件照宽度,默认为295 | ||
private String face_detect_model; // 人脸检测模型,默认为mtcnn | ||
private Boolean hd; // 是否生成高清证件照,默认为true | ||
private Integer dpi; // 图像分辨率,默认为300 | ||
private Float head_measure_ratio; // 面部面积与照片面积的比例,默认为0.2 | ||
private Float head_height_ratio; // 面部中心与照片顶部的高度比例,默认为0.45 | ||
private Float top_distance_max; // 头部与照片顶部距离的比例最大值,默认为0.12 | ||
private Float top_distance_min; // 头部与照片顶部距离的比例最小值,默认为0.1 | ||
} |
4 changes: 2 additions & 2 deletions
4
...ar/idPhotoApi/request/IdPhotoRequest.java → ...onIDPhotos/request/HIDIdPhotoRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/org/photo/modular/HivisionIDPhotos/request/HIDSetKbRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.photo.modular.HivisionIDPhotos.request; | ||
|
||
import lombok.Data; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Data | ||
public class HIDSetKbRequest { | ||
private MultipartFile input_image; // 传入的图像文件路径 | ||
private String input_image_base64; // 传入的图像文件的base64编码 | ||
private Integer kb; // 输出照片的 KB 值,默认为None | ||
private Integer dpi; // 图像分辨率,默认为300 | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/photo/modular/HivisionIDPhotos/request/HIDWatermarkRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.photo.modular.HivisionIDPhotos.request; | ||
|
||
import lombok.Data; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Data | ||
public class HIDWatermarkRequest { | ||
private MultipartFile input_image; // 传入的图像文件路径 | ||
private String input_image_base64; // 传入的图像文件的base64编码 | ||
private String text; // 水印文本,默认为Hello | ||
private Integer size; // 水印字体大小,默认为20 | ||
private Float opacity; // 水印透明度,默认为0.5 | ||
private Integer angle; // 水印旋转角度,默认为30 | ||
private String color; // 水印颜色,默认为#000000 | ||
private Integer space; // 水印间距,默认为25 | ||
private Integer dpi; // 图像分辨率,默认为300 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/org/photo/modular/HivisionIDPhotos/service/HivisionIDPhotosService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.photo.modular.HivisionIDPhotos.service; | ||
|
||
import org.photo.modular.HivisionIDPhotos.enums.HIDOptTypeEnum; | ||
import org.photo.modular.HivisionIDPhotos.request.HIDAddBackgroundRequest; | ||
import org.photo.modular.HivisionIDPhotos.request.HIDIdPhotoRequest; | ||
import org.photo.modular.HivisionIDPhotos.response.HIDHivisionResponse; | ||
|
||
import java.io.IOException; | ||
|
||
public interface HivisionIDPhotosService { | ||
|
||
/** | ||
* 生成证件照 | ||
* 接口的逻辑是发送一张 RGB 图像,输出一张标准证件照和一张高清证件照: | ||
* 高清证件照:根据size的宽高比例制作的证件照,文件名为output_image_dir增加_hd后缀 | ||
* 标准证件照:尺寸等于size,由高清证件照缩放而来,文件名为output_image_dir | ||
* 需要注意的是,生成的两张照片都是透明的(RGBA 四通道图像),要生成完整的证件照,还需要下面的添加背景色接口。 | ||
* @param request | ||
* @return | ||
* @throws IOException | ||
*/ | ||
HIDHivisionResponse idphoto(HIDIdPhotoRequest request) throws IOException; | ||
|
||
/** | ||
* 添加背景色 | ||
* 接口的逻辑是接收一张 RGBA 图像(透明图),根据color添加背景色,合成一张 JPG 图像。 | ||
* @param request | ||
* @return | ||
* @throws IOException | ||
*/ | ||
HIDHivisionResponse add_background(HIDAddBackgroundRequest request) throws IOException; | ||
|
||
/** | ||
* 生成六寸排版照 | ||
* 接口的逻辑是接收一张 RGB 图像(一般为添加背景色之后的证件照),根据size进行照片排布,然后生成一张六寸排版照。 | ||
* @param request | ||
* @return | ||
* @throws IOException | ||
*/ | ||
HIDHivisionResponse generate_layout_photos(HIDAddBackgroundRequest request) throws IOException; | ||
|
||
/** | ||
* 人像抠图 | ||
* 接口的逻辑是接收一张 RGB 图像,输出一张标准抠图人像照和高清抠图人像照(无任何背景填充)。 | ||
* @param request | ||
* @return | ||
* @throws IOException | ||
*/ | ||
HIDHivisionResponse human_matting(HIDAddBackgroundRequest request) throws IOException; | ||
|
||
/** | ||
* 图像加水印 | ||
* 接口的功能是接收一个水印文本,然后在原图上添加指定的水印。用户可以指定水印的位置、透明度和大小等属性,以便将水印无缝地融合到原图中。 | ||
* @param request | ||
* @return | ||
* @throws IOException | ||
*/ | ||
HIDHivisionResponse watermark(HIDAddBackgroundRequest request) throws IOException; | ||
/** | ||
* 设置图像KB大小 | ||
* 接口的功能是接收一张图像和目标文件大小(以KB为单位),如果设置的KB值小于原文件,则调整压缩率;如果设置的KB值大于源文件,则通过给文件头添加信息的方式调大KB值,目标是让图像的最终大小与设置的KB值一致。 | ||
* @param request | ||
* @return | ||
* @throws IOException | ||
*/ | ||
HIDHivisionResponse set_kb(HIDAddBackgroundRequest request) throws IOException; | ||
|
||
/** | ||
* 证件照裁切 | ||
* 接口的功能是接收一张 RBGA 图像(透明图),输出一张标准证件照和一张高清证件照。 | ||
* @param request | ||
* @return | ||
* @throws IOException | ||
*/ | ||
HIDHivisionResponse idphoto_crop(HIDAddBackgroundRequest request) throws IOException; | ||
|
||
|
||
} |
Oops, something went wrong.