Import redaction fixes
This commit is contained in:
parent
b09f036253
commit
350de7f385
@ -58,7 +58,7 @@ public class RedactionExtractorService {
|
|||||||
Map<Integer, List<ImportedRedaction>> importedRedactionsMap = new HashMap<>();
|
Map<Integer, List<ImportedRedaction>> importedRedactionsMap = new HashMap<>();
|
||||||
for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++) {
|
for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++) {
|
||||||
PDPage page = pdfDocument.getPage(pageNumber - 1);
|
PDPage page = pdfDocument.getPage(pageNumber - 1);
|
||||||
BufferedImage image = pageConvertToImage(pdfDocument, page, 144, ImageType.GRAY);
|
BufferedImage image = pageConvertToImage(pdfDocument, page, 200, ImageType.GRAY);
|
||||||
|
|
||||||
|
|
||||||
Mat imageAsMat = bufferedImage2Mat(image);
|
Mat imageAsMat = bufferedImage2Mat(image);
|
||||||
@ -74,7 +74,7 @@ public class RedactionExtractorService {
|
|||||||
Mat blurred = new Mat();
|
Mat blurred = new Mat();
|
||||||
Imgproc.GaussianBlur(imageAsMatINv,blurred, new Size(5, 5), 1);
|
Imgproc.GaussianBlur(imageAsMatINv,blurred, new Size(5, 5), 1);
|
||||||
Mat thresh = new Mat();
|
Mat thresh = new Mat();
|
||||||
Imgproc.threshold(blurred, thresh, 250, 255, Imgproc.THRESH_BINARY);
|
Imgproc.threshold(blurred, thresh, 240, 255, Imgproc.THRESH_BINARY);
|
||||||
|
|
||||||
|
|
||||||
Mat hierachy = new Mat();
|
Mat hierachy = new Mat();
|
||||||
@ -85,13 +85,13 @@ public class RedactionExtractorService {
|
|||||||
System.out.println(contours);
|
System.out.println(contours);
|
||||||
System.out.println(hierachy.size(3));
|
System.out.println(hierachy.size(3));
|
||||||
|
|
||||||
var min_nomralized_area=600;
|
var min_nomralized_area=800;
|
||||||
|
|
||||||
|
if(hierachy.rows() > 0 && hierachy.row(0).rows() > 0) {
|
||||||
hierachy = hierachy.row(0).row(0);
|
hierachy = hierachy.row(0).row(0);
|
||||||
|
|
||||||
System.out.println("Cont" + contours.size() + "Hier" + hierachy.cols());
|
System.out.println("Cont" + contours.size() + "Hier" + hierachy.cols());
|
||||||
|
|
||||||
|
|
||||||
// for(int j = 0; j<= hierachy.cols(); j++){
|
// for(int j = 0; j<= hierachy.cols(); j++){
|
||||||
// System.out.println("----> Col " + j);
|
// System.out.println("----> Col " + j);
|
||||||
// for (double d :hierachy.get(0,j)){
|
// for (double d :hierachy.get(0,j)){
|
||||||
@ -99,8 +99,6 @@ public class RedactionExtractorService {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
List<MatOfPoint> filterd = new ArrayList<>();
|
List<MatOfPoint> filterd = new ArrayList<>();
|
||||||
for (MatOfPoint contour : contours) {
|
for (MatOfPoint contour : contours) {
|
||||||
@ -110,25 +108,22 @@ public class RedactionExtractorService {
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Imgproc.drawContours(imageAsMat, filterd, -1, new Scalar(180), 2);
|
Imgproc.drawContours(imageAsMat, filterd, -1, new Scalar(180), 2);
|
||||||
|
|
||||||
|
|
||||||
List<ImportedRedaction> importedRedactions = new ArrayList<>();
|
List<ImportedRedaction> importedRedactions = new ArrayList<>();
|
||||||
for (MatOfPoint contour : filterd) {
|
for (MatOfPoint contour : filterd) {
|
||||||
Rect rect = Imgproc.boundingRect(contour);
|
Rect rect = Imgproc.boundingRect(contour);
|
||||||
|
|
||||||
importedRedactions.add(new ImportedRedaction(UUID.randomUUID().toString(), List.of(
|
importedRedactions.add(new ImportedRedaction(UUID.randomUUID().toString(), List.of(new Rectangle(new Point((float) (rect.x * page.getCropBox()
|
||||||
new Rectangle(new Point((float) (rect.x * page.getCropBox().getWidth() / image.getWidth()),
|
.getWidth() / image.getWidth()), (float) (page.getCropBox().getHeight() - rect.y * page.getCropBox()
|
||||||
(float) (page.getCropBox().getHeight() - rect.y * page.getCropBox().getWidth() / image.getWidth())),
|
.getWidth() / image.getWidth())), rect.width * page.getCropBox()
|
||||||
rect.width * page.getCropBox().getWidth() / image.getWidth(),
|
.getWidth() / image.getWidth(), -rect.height * page.getCropBox()
|
||||||
-rect.height * page.getCropBox().getWidth() / image.getWidth(),
|
.getWidth() / image.getWidth(), pageNumber))));
|
||||||
1))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
importedRedactionsMap.put(pageNumber, importedRedactions);
|
||||||
|
|
||||||
importedRedactionsMap.put(1, importedRedactions);
|
}
|
||||||
|
|
||||||
|
|
||||||
// BufferedImage gray = new BufferedImage(imageAsMat.width(), imageAsMat.height(), BufferedImage.TYPE_BYTE_GRAY);
|
// BufferedImage gray = new BufferedImage(imageAsMat.width(), imageAsMat.height(), BufferedImage.TYPE_BYTE_GRAY);
|
||||||
// byte[] data = ((DataBufferByte) gray.getRaster().getDataBuffer()).getData();
|
// byte[] data = ((DataBufferByte) gray.getRaster().getDataBuffer()).getData();
|
||||||
@ -141,6 +136,8 @@ public class RedactionExtractorService {
|
|||||||
|
|
||||||
// System.out.println(contours);
|
// System.out.println(contours);
|
||||||
}
|
}
|
||||||
|
pdfDocument.close();
|
||||||
|
|
||||||
return new ImportedRedactions(importedRedactionsMap);
|
return new ImportedRedactions(importedRedactionsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -567,15 +567,16 @@ public class RedactionIntegrationTest {
|
|||||||
public void testImportRedactions() {
|
public void testImportRedactions() {
|
||||||
nu.pattern.OpenCV.loadShared();
|
nu.pattern.OpenCV.loadShared();
|
||||||
|
|
||||||
ClassPathResource pdfFileResource = new ClassPathResource("files/redest_man_page.pdf");
|
ClassPathResource pdfFileResource = new ClassPathResource("files/Metolachlor/S-Metolachlor_RAR_01_Volume_1_2018-09-06_redacted1.pdf");
|
||||||
|
|
||||||
ImportedRedactions importedRedactions = redactionExtractorService.extractRedaction(pdfFileResource.getInputStream());
|
ImportedRedactions importedRedactions = redactionExtractorService.extractRedaction(pdfFileResource.getInputStream());
|
||||||
|
|
||||||
|
|
||||||
String outputFileName = OsUtils.getTemporaryDirectory() + "/Annotated.pdf";
|
String outputFileName = OsUtils.getTemporaryDirectory() + "/Annotated.pdf";
|
||||||
|
|
||||||
|
ClassPathResource pdfFileResource2 = new ClassPathResource("files/Metolachlor/S-Metolachlor_RAR_01_Volume_1_2018-09-06.pdf");
|
||||||
|
|
||||||
AnalyzeRequest request = prepareStorage(pdfFileResource.getInputStream());
|
AnalyzeRequest request = prepareStorage(pdfFileResource2.getInputStream());
|
||||||
storageService.storeObject(RedactionStorageService.StorageIdUtils.getStorageId(TEST_DOSSIER_ID, TEST_FILE_ID, FileType.IMPORTED_REDACTIONS), objectMapper.writeValueAsBytes(importedRedactions));
|
storageService.storeObject(RedactionStorageService.StorageIdUtils.getStorageId(TEST_DOSSIER_ID, TEST_FILE_ID, FileType.IMPORTED_REDACTIONS), objectMapper.writeValueAsBytes(importedRedactions));
|
||||||
|
|
||||||
analyzeService.analyzeDocumentStructure(new StructureAnalyzeRequest(request.getDossierId(), request.getFileId()));
|
analyzeService.analyzeDocumentStructure(new StructureAnalyzeRequest(request.getDossierId(), request.getFileId()));
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user