-
Notifications
You must be signed in to change notification settings - Fork 0
3. Quick Start
Follow the steps below to quickly get started with the PictureComparer library.
You can easily integrate PictureComparer into your project using one of the methods available in this section: Installation.
PictureComparer uses caching with the Caffeine library, which requires JVM memory for optimal cache allocation.
- Adjust Maximum Heap Size: Make sure to allocate enough memory to the JVM heap. You can set the maximum heap size using the following JVM options.
java -Xmx2G -Xms512M -jar your-application.jar
This sets the initial heap size to 512 MB (-Xms512M
) and the maximum heap size to 2 GB (-Xmx2G
).
Adjust according to your needs.
-
Monitor Cache Behavior: Use builtin solution (
monitor(...)
) method, which provides you with internal Cafeine metrics, or use tools like VisualVM or JConsole.
To log messages, PictureComparer uses SLF4J, and you can configure it to use different logging frameworks.
a. Logback Configuration (native solution)
Create a logback.xml
file in your src/main/resources
directory:
<configuration>
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} - %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="Console" />
</root>
</configuration>
This is only example configuration. Please follow instructions in the Logback's documentation.
b. Log4j2 Configuration
Alternatively, create a log4j2.xml
file in your src/main/resources
directory:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} - %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
This is only example configuration. Please follow instructions in the Log4j2's documentation.
Once the library is integrated into your project, you can start using it for image comparison and duplicate removal.
a. Create Instances of FileOperator
and Processor
public class MyClass {
public FileOperator fileOperator;
public Processor processor;
public MyClass() {
fileOperator = new FileOperator(new ImageFilePredicate(), Integer.MAX_VALUE);
processor = new Processor(
new CRC32Grouper(),
List.of(new PerceptualHash(), new PixelByPixel())
);
}
}
b. Prepare Your Image Collection
public static void main(String[] args) {
MyClass mc = new MyClass();
List<File> files = List.of(new File("path/to/my/gallery"));
files = mc.fileOperator.load(files);
}
c. Process the Image Collection
public static void main(String[] args) {
// ...
Map<File, Set<File>> duplicates = mc.processor.process(files);
// Handle the duplicates (e.g., remove them, log them)
}
With these steps, you should be able to quickly integrate PictureComparer into your project, configure it, and start processing images to find duplicates.