Skip to content

Commit

Permalink
Merge pull request #9 from JanardhanBS-SyncByte/develop
Browse files Browse the repository at this point in the history
[MOSIP-29095] Payload information removed and Logs enabled
  • Loading branch information
gsasikumar authored Nov 27, 2023
2 parents 442dea9 + 6b7887d commit 07031be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion image-compressor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<maven-shade-plugin.version>2.3</maven-shade-plugin.version>

<!-- Mosip kernel -->
<kernel.version>1.2.0.1-SNAPSHOT</kernel.version>
<kernel.version>1.2.0.1-B1</kernel.version>
<kernel.biometrics.api.version>1.2.0.1-B2</kernel.biometrics.api.version>
<biometrics-util.version>1.2.0.1-B2-SNAPSHOT</biometrics-util.version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public ImageCompressionService(Environment env, BiometricRecord sample, List<Bio
this.modalitiesToExtract = modalitiesToExtract;
}

public Response<BiometricRecord> getExtractTemplateInfo() {
public Response<BiometricRecord> getExtractTemplateInfo() {
LOGGER.info("ExtractTemplateInfo :: Started Request :: " + sample != null ? sample.toString() : null);

ResponseStatus responseStatus = null;
Response<BiometricRecord> response = new Response<>();
try {
Expand All @@ -71,13 +73,20 @@ public Response<BiometricRecord> getExtractTemplateInfo() {
}

for (BIR segment : sample.getSegments()) {
// not validating ISO
/*
* Can do ISO validation here
*/
byte[] faceBdb = getBirData(segment);

/*
* Below Code can be removed if we require PayLoad information
*/
/*
if (segment.getBirInfo() == null)
segment.setBirInfo(new BIRInfo(new BIRInfoBuilder().withPayload(segment.getBdb())));
else
segment.getBirInfo().setPayload(segment.getBdb());
*/

BDBInfo bdbInfo = segment.getBdbInfo();
if (bdbInfo != null) {
Expand All @@ -90,7 +99,6 @@ public Response<BiometricRecord> getExtractTemplateInfo() {
// do actual resize and compression .. create the face ISO ISO19794_5_2011
byte[] data = doFaceConversion("REGISTRATION", resizeAndCompress(faceBdb));
segment.setBdb(Base64.getEncoder().encode(data));
//LOGGER.debug(Base64.getEncoder().encodeToString(data));
}
}
}
Expand Down Expand Up @@ -145,15 +153,16 @@ public Response<BiometricRecord> getExtractTemplateInfo() {
}
response.setStatusCode(ResponseStatus.SUCCESS.getStatusCode());
response.setResponse(sample);

LOGGER.info("ExtractTemplateInfo :: End Response :: ", response != null ? response.toString() : null);
return response;
}

public byte[] resizeAndCompress(byte[] jp2000Bytes) throws IOException {
// Storing the image in a Matrix object
// of Mat type
Mat src = Imgcodecs.imdecode(new MatOfByte(jp2000Bytes), Imgcodecs.IMREAD_UNCHANGED);
LOGGER.info("Orginal Image Details");
LOGGER.info(String.format("Width=%d, Height=%d, Total Size=%d ", src.width(), src.height(), (src.width() * src.height())));
LOGGER.info("Orginal Image Details :: Width {} Height {} Total Size {}", src.width(), src.height(), (src.width() * src.height()));
// New matrix to store the final image
// where the input image is supposed to be written
Mat dst = new Mat();
Expand All @@ -170,20 +179,17 @@ public byte[] resizeAndCompress(byte[] jp2000Bytes) throws IOException {
compression = this.getEnv().getProperty(SdkConstant.IMAGE_COMPRESSOR_COMPRESSION_RATIO, Integer.class, 50);
}

LOGGER.info("Factor ratio Details");
LOGGER.info(String.format("orginal fx=%.2f, orginal fy=%.2f, Compression Ratio==%d ", fxOrginal, fyOrginal, compression));
LOGGER.info("Factor ratio Details :: {} ", String.format("orginal fx=%.2f, orginal fy=%.2f, Compression Ratio==%d ", fxOrginal, fyOrginal, compression));

Imgproc.resize(src, dst, new Size(0, 0), fxOrginal, fyOrginal, Imgproc.INTER_AREA);
LOGGER.info("Resized Image Details");
LOGGER.info(String.format("Width=%d, Height=%d, Total Size=%d ", dst.width(), dst.height(), (dst.width() * dst.height())));
LOGGER.info("Resized Image Details :: Width {} Height {} Total Size {}", dst.width(), dst.height(), (dst.width() * dst.height()));

MatOfInt map = new MatOfInt(Imgcodecs.IMWRITE_JPEG2000_COMPRESSION_X1000, compression);
MatOfByte mem = new MatOfByte();
Imgcodecs.imencode(".jp2", dst, mem, map);
byte[] data = mem.toArray();

LOGGER.info("Compressed Image Details");
LOGGER.info(String.format("Image length==%d ", data.length));
LOGGER.info("Compressed Image Details :: Image length {}", data.length);

return data;
}
Expand All @@ -201,7 +207,8 @@ public byte[] doFaceConversion(String purpose, byte[] imageData) {
requestDto.setImageType(0);//0 = jp2, 1 = wsq
requestDto.setInputBytes(imageData);

return FaceEncoder.convertFaceImageToISO(requestDto);// get image quality = 40 by default
// get image quality = 40 by default
return FaceEncoder.convertFaceImageToISO(requestDto);
}
} catch (Exception ex) {
ex.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ protected byte[] getFaceBdb(PurposeType purposeType, String biometricSubType, St
responseStatus = ResponseStatus.INVALID_INPUT;
throw new SDKException(responseStatus.getStatusCode() + "", responseStatus.getStatusMessage());
}
System.out.println(bioData);
FaceBDIR bdir = FaceDecoder.getFaceBDIR(requestDto);

return bdir.getImage();
} catch (Exception ex) {
ex.printStackTrace();
Expand Down

0 comments on commit 07031be

Please sign in to comment.