Search in sources :

Example 1 with Image

use of org.fagu.fmv.im.Image in project fmv by f-agu.

the class Images method prepare.

/**
 * @param size
 */
public PreparedImages prepare(Size size) throws IOException {
    final int COUNT_TOTAL = getImages().size();
    File destFolder = new File(sourceFolder.getParent(), sourceFolder.getName() + "-img2mov");
    if (destFolder.exists()) {
        File[] listFiles = destFolder.listFiles(f -> f.getName().startsWith("img_"));
        if (listFiles.length == COUNT_TOTAL) {
            return new PreparedImages(Arrays.asList(listFiles));
        }
    }
    final AtomicInteger count = new AtomicInteger();
    ConverterListener<Image> converterListener = new ConverterListener<Image>() {

        /**
         * @see org.fagu.fmv.mymedia.classify.ConverterListener#eventPreConvert(org.fagu.fmv.media.Media,
         *      java.io.File)
         */
        @Override
        public void eventPreConvert(Image srcMedia, File destFile) {
            System.out.println("Convert (" + count.incrementAndGet() + "/" + COUNT_TOTAL + "): " + srcMedia.getFile());
        }
    };
    try (ReduceImageConverter converter = new ReduceImageConverter(destFolder)) {
        converter.setSize(size);
        try (Classifier<ImageFinder, Image> classifier = ClassifierFactories.imagesToMovie().create(imageFinder, destFolder)) {
            return new PreparedImages(classifier.classify(converter, converterListener));
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImageFinder(org.fagu.fmv.mymedia.file.ImageFinder) ConverterListener(org.fagu.fmv.mymedia.classify.ConverterListener) Image(org.fagu.fmv.im.Image) File(java.io.File) ReduceImageConverter(org.fagu.fmv.mymedia.classify.image.ReduceImageConverter)

Example 2 with Image

use of org.fagu.fmv.im.Image in project fmv by f-agu.

the class Bootstrap method main.

/**
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    File source = new File(args[0]);
    File saveFile = new File(source, "image.save");
    File destFolder = new File(source.getParentFile(), source.getName() + "-out");
    Bootstrap bootstrap = new Bootstrap();
    try (ImageFinder imageFinder = bootstrap.findImage(saveFile, source)) {
        Organizer<ImageFinder, Image> organizer = new Organizer<>(Image.class);
        organizer.organize(destFolder, imageFinder);
    }
}
Also used : Organizer(org.fagu.fmv.mymedia.classify.Organizer) ImageFinder(org.fagu.fmv.mymedia.file.ImageFinder) Image(org.fagu.fmv.im.Image) File(java.io.File)

Example 3 with Image

use of org.fagu.fmv.im.Image in project fmv by f-agu.

the class TimeOffsetImageComparatorTestCase method mockImage.

/**
 * @param time
 * @param device
 * @param model
 * @param fileName
 * @return
 */
private FileFinder<Image>.InfosFile mockImage(long time, String device, String model, String fileName) {
    Image image = mock(Image.class);
    ImageMetadatas imageMetadatas = mock(ImageMetadatas.class);
    File file = mock(File.class);
    doReturn(time).when(image).getTime();
    doReturn(imageMetadatas).when(image).getMetadatas();
    doReturn(new Date(time)).when(imageMetadatas).getDate();
    if (device != null) {
        doReturn(device).when(imageMetadatas).getDevice();
    }
    if (model != null) {
        doReturn(model).when(imageMetadatas).getDeviceModel();
    }
    FileFinder<Image>.InfosFile infosFile = mock(InfosFile.class);
    doReturn(image).when(infosFile).getMain();
    doReturn(file).when(image).getFile();
    doReturn(fileName).when(file).getName();
    return infosFile;
}
Also used : ImageMetadatas(org.fagu.fmv.im.ImageMetadatas) FileFinder(org.fagu.fmv.utils.file.FileFinder) Image(org.fagu.fmv.im.Image) File(java.io.File) InfosFile(org.fagu.fmv.utils.file.FileFinder.InfosFile) Date(java.util.Date)

Example 4 with Image

use of org.fagu.fmv.im.Image in project fmv by f-agu.

the class TimeOffsetImageComparatorTestCase method testSome.

/**
 */
@Test
public void testSome() {
    TimeOffsetImageComparator comparator = new TimeOffsetImageComparator();
    comparator.addFilter(im -> "a".equals(im.getDevice()), 17);
    // 18 = 1 + 17
    FileFinder<Image>.InfosFile imageA1 = mockImage(1, "a", "a", "A1");
    // 21 = 4 + 17
    FileFinder<Image>.InfosFile imageA2 = mockImage(4, "a", "a", "A2");
    // 12
    FileFinder<Image>.InfosFile imageB1 = mockImage(15, "b", "b", "B1");
    // 15
    FileFinder<Image>.InfosFile imageB2 = mockImage(12, "b", "b", "B2");
    // 17
    FileFinder<Image>.InfosFile imageB3 = mockImage(17, "b", "b", "B3");
    // 19
    FileFinder<Image>.InfosFile imageB4 = mockImage(19, "b", "b", "B4");
    TreeSet<FileFinder<Image>.InfosFile> images = new TreeSet<>(comparator);
    images.add(imageA1);
    images.add(imageA2);
    images.add(imageB1);
    images.add(imageB2);
    images.add(imageB3);
    images.add(imageB4);
    Iterator<FileFinder<Image>.InfosFile> iterator = images.iterator();
    assertSame(imageB2, iterator.next());
    assertSame(imageB1, iterator.next());
    assertSame(imageB3, iterator.next());
    assertSame(imageA1, iterator.next());
    assertSame(imageB4, iterator.next());
    assertSame(imageA2, iterator.next());
    assertFalse(iterator.hasNext());
}
Also used : InfosFile(org.fagu.fmv.utils.file.FileFinder.InfosFile) TreeSet(java.util.TreeSet) TimeOffsetImageComparator(org.fagu.fmv.mymedia.classify.image.TimeOffsetImageComparator) FileFinder(org.fagu.fmv.utils.file.FileFinder) Image(org.fagu.fmv.im.Image) Test(org.junit.Test)

Example 5 with Image

use of org.fagu.fmv.im.Image in project fmv by f-agu.

the class FindDiffTime method main.

/**
 * @param args
 * @throws IOException
 */
public static void main(String[] args) throws IOException {
    ImageFinder imagesFinder = Sources.load(new File("C:\\tmp\\july\\save"));
    for (FileFinder<Image>.InfosFile infosFile : imagesFinder.getAll()) {
        Image image = infosFile.getMain();
        File file = image.getFile();
        System.out.println(file.getParentFile().getName() + "/" + file.getName() + " : " + DATE_FORMAT.format(new Date(image.getTime())));
        if ("GOPR0698.JPG".equals(file.getName())) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(2014, Calendar.JULY, 10, 15, 30, 0);
            System.out.println("############### " + (image.getTime() - calendar.getTimeInMillis()));
        }
    }
}
Also used : ImageFinder(org.fagu.fmv.mymedia.file.ImageFinder) Calendar(java.util.Calendar) FileFinder(org.fagu.fmv.utils.file.FileFinder) Image(org.fagu.fmv.im.Image) File(java.io.File) Date(java.util.Date)

Aggregations

Image (org.fagu.fmv.im.Image)5 File (java.io.File)4 ImageFinder (org.fagu.fmv.mymedia.file.ImageFinder)3 FileFinder (org.fagu.fmv.utils.file.FileFinder)3 Date (java.util.Date)2 InfosFile (org.fagu.fmv.utils.file.FileFinder.InfosFile)2 Calendar (java.util.Calendar)1 TreeSet (java.util.TreeSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ImageMetadatas (org.fagu.fmv.im.ImageMetadatas)1 ConverterListener (org.fagu.fmv.mymedia.classify.ConverterListener)1 Organizer (org.fagu.fmv.mymedia.classify.Organizer)1 ReduceImageConverter (org.fagu.fmv.mymedia.classify.image.ReduceImageConverter)1 TimeOffsetImageComparator (org.fagu.fmv.mymedia.classify.image.TimeOffsetImageComparator)1 Test (org.junit.Test)1