-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(process-file): Find 2D-Docs on images
- Loading branch information
1 parent
3ad98c2
commit 57f42b3
Showing
9 changed files
with
99 additions
and
5 deletions.
There are no files selected for viewing
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
15 changes: 15 additions & 0 deletions
15
...-file/src/main/java/fr/dossierfacile/process/file/barcode/twoddoc/reader/CroppedFile.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 |
---|---|---|
@@ -1,6 +1,21 @@ | ||
package fr.dossierfacile.process.file.barcode.twoddoc.reader; | ||
|
||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
|
||
record CroppedFile(BufferedImage bufferedImage) { | ||
|
||
CroppedFile rotate(int degrees) { | ||
int width = bufferedImage.getWidth(); | ||
int height = bufferedImage.getHeight(); | ||
|
||
BufferedImage result = new BufferedImage(width, height, bufferedImage.getType()); | ||
Graphics2D graphics2D = result.createGraphics(); | ||
|
||
graphics2D.rotate(Math.toRadians(degrees), (double) width / 2, (double) height / 2); | ||
graphics2D.drawImage(bufferedImage, null, 0, 0); | ||
|
||
return new CroppedFile(result); | ||
} | ||
|
||
} |
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
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
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
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
30 changes: 30 additions & 0 deletions
30
...rc/main/java/fr/dossierfacile/process/file/barcode/twoddoc/reader/TwoDDocImageFinder.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,30 @@ | ||
package fr.dossierfacile.process.file.barcode.twoddoc.reader; | ||
|
||
import fr.dossierfacile.process.file.barcode.twoddoc.TwoDDocRawContent; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Slf4j | ||
public class TwoDDocImageFinder extends TwoDDocFinder { | ||
|
||
private final BufferedImage image; | ||
|
||
public TwoDDocImageFinder(BufferedImage image) { | ||
super(FileCropper.fromImageSource(image)); | ||
this.image = image; | ||
} | ||
|
||
@Override | ||
public Optional<TwoDDocRawContent> find2DDoc() { | ||
TwoDDocSize twoDDocSize = TwoDDocSize.on(image); | ||
List<SquarePosition> list = KnownTwoDDocLocations.stream() | ||
.map(location -> location.toCoordinates(image)) | ||
.map(coordinates -> coordinates.toSquare(twoDDocSize.width())) | ||
.toList(); | ||
return tryToFindTwoDDocIn(list); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
...est/java/fr/dossierfacile/process/file/barcode/twoddoc/reader/TwoDDocImageFinderTest.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,33 @@ | ||
package fr.dossierfacile.process.file.barcode.twoddoc.reader; | ||
|
||
import fr.dossierfacile.process.file.TestFilesUtil; | ||
import fr.dossierfacile.process.file.barcode.twoddoc.TwoDDocRawContent; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.awt.image.BufferedImage; | ||
import java.io.IOException; | ||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class TwoDDocImageFinderTest { | ||
|
||
@Test | ||
void should_read_2DDoc_on_image() throws IOException { | ||
Optional<TwoDDocRawContent> actualContent = findOnImage("2ddoc.jpg"); | ||
TwoDDocRawContent expectedContent = new TwoDDocRawContent("DC02FR000001125E125B0126FR247500010MME/SPECIMEN/NATACHA\u001D22145 AVENUE DES SPECIMENS\u001D\u001F54LDD5F7JD4JEFPR6WZYVZVB2JZXPZB73SP7WUTN5N44P3GESXW75JZUZD5FM3G4URAJ6IKDSSUB66Y3OWQIEH22G46QOAGWH7YHJWQ"); | ||
assertThat(actualContent).isPresent().contains(expectedContent); | ||
} | ||
|
||
@Test | ||
void should_return_empty_if_no_2DDoc_found() throws IOException { | ||
Optional<TwoDDocRawContent> twoDDoc = findOnImage("qr-code.jpg"); | ||
assertThat(twoDDoc).isEmpty(); | ||
} | ||
|
||
private static Optional<TwoDDocRawContent> findOnImage(String fileName) throws IOException { | ||
BufferedImage image = TestFilesUtil.getImage(fileName); | ||
return new TwoDDocImageFinder(image).find2DDoc(); | ||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.