Search in sources :

Example 11 with MediaSegmentDescriptor

use of org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor in project cineast by vitrivr.

the class FindSegmentsByObjectIdGetHandler method doGet.

@Override
public MediaSegmentQueryResult doGet(Context ctx) {
    final Map<String, String> parameters = ctx.pathParamMap();
    final String objectId = parameters.get(ID_NAME);
    final MediaSegmentReader sl = new MediaSegmentReader(Config.sharedConfig().getDatabase().getSelectorSupplier().get());
    final List<MediaSegmentDescriptor> list = sl.lookUpSegmentsOfObject(objectId);
    sl.close();
    return new MediaSegmentQueryResult("", list);
}
Also used : MediaSegmentReader(org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader) MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) MediaSegmentQueryResult(org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult)

Example 12 with MediaSegmentDescriptor

use of org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor in project cineast by vitrivr.

the class TrecvidMasterShotReferenceDecoder method decode.

/**
 * decodes shot boundaries in the format used for TRECVID
 *
 * @param msr     the file containing the master shot reference
 * @param videoId the video id
 */
public static List<MediaSegmentDescriptor> decode(File msr, String videoId) {
    ArrayList<MediaSegmentDescriptor> _return = new ArrayList<>();
    try {
        BufferedReader reader = new BufferedReader(new FileReader(msr));
        String line = null;
        int shotCounter = 0;
        while ((line = reader.readLine()) != null) {
            line = line.trim();
            if (line.isEmpty()) {
                // skip empty lines
                continue;
            }
            if (!Character.isDigit(line.charAt(0))) {
                // line does not start with a number
                continue;
            }
            String[] split = line.split(" ");
            if (split.length < 2) {
                // there are not two blocks on this line
                continue;
            }
            int start, end;
            try {
                // TRECVID msr starts with 0
                start = 1 + Integer.parseInt(split[0]);
                end = 1 + Integer.parseInt(split[1]);
            } catch (NumberFormatException e) {
                continue;
            }
            ++shotCounter;
            /* TODO: Derive absolute start and end position of MediaSegmentDescriptor. */
            _return.add(new MediaSegmentDescriptor(videoId, MediaType.generateSegmentId(MediaType.VIDEO, videoId, shotCounter), shotCounter, start, end, -1.0f, -1.0f, true));
        }
        reader.close();
    } catch (FileNotFoundException e) {
        LOGGER.error("error in TrecvidMasterShotReferenceDecoder.decode, file '{}' was not found", msr.getAbsolutePath());
    } catch (IOException e) {
        LOGGER.error("error while reading file '{}' in TrecvidMasterShotReferenceDecoder.decode: {}", msr.getAbsolutePath(), e.getMessage());
    }
    return _return;
}
Also used : MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException)

Example 13 with MediaSegmentDescriptor

use of org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor in project cineast by vitrivr.

the class ScoreFusion method fuseObjectScoreIntoSegments.

private static void fuseObjectScoreIntoSegments(TObjectDoubleMap<String> scoreBySegmentId, double objectScore, List<MediaSegmentDescriptor> segments) {
    boolean objectSegmentsFoundInResults = false;
    for (MediaSegmentDescriptor segment : segments) {
        boolean foundElement = scoreBySegmentId.adjustValue(segment.getSegmentId(), objectScore);
        if (foundElement) {
            objectSegmentsFoundInResults = true;
        }
    }
    if (!objectSegmentsFoundInResults) {
        MediaSegmentDescriptor firstSegment = segments.get(0);
        String firstId = firstSegment.getSegmentId();
        scoreBySegmentId.put(firstId, objectScore);
    }
}
Also used : MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor)

Example 14 with MediaSegmentDescriptor

use of org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor in project cineast by vitrivr.

the class CliUtils method printInfoForSegment.

public static void printInfoForSegment(String segmentId, DBSelector selector, String _filterCategory, boolean printObjInfo) {
    System.out.println("= Retrieving segment information for " + segmentId + "=");
    MediaSegmentReader segmentReader = new MediaSegmentReader(selector);
    Optional<MediaSegmentDescriptor> segmentDescriptor = segmentReader.lookUpSegment(segmentId);
    segmentDescriptor.ifPresent(System.out::println);
    segmentDescriptor.ifPresent(descriptor -> {
        if (printObjInfo) {
            printInfoForObject(descriptor.getObjectId(), selector);
        }
    });
    System.out.println("= Retrieving segment metadata =");
    MediaSegmentMetadataReader reader = new MediaSegmentMetadataReader(selector);
    reader.lookupMultimediaMetadata(segmentId).forEach(System.out::println);
    System.out.println("Retrieving all columns for segment " + segmentId);
    RetrievalRuntimeConfig retrievalRuntimeConfig = Config.sharedConfig().getRetriever();
    retrievalRuntimeConfig.getRetrieverCategories().forEach(cat -> {
        if (_filterCategory != null) {
            if (!cat.equals(_filterCategory)) {
                return;
            }
        }
        retrievalRuntimeConfig.getRetrieversByCategory(cat).forEachEntry((retriever, weight) -> {
            System.out.println("= Retrieving for feature: " + retriever.getClass().getSimpleName() + " =");
            retriever.getTableNames().forEach(tableName -> {
                selector.open(tableName);
                List<Map<String, PrimitiveTypeProvider>> rows = selector.getRows("id", new StringTypeProvider(segmentId));
                if (retriever.getClass() == RangeBooleanRetriever.class) {
                    rows = selector.getRows("segmentid", new StringTypeProvider(segmentId));
                }
                rows.forEach(row -> {
                    System.out.println("== New row == ");
                    row.forEach((key, value) -> System.out.println(tableName + "." + key + " - " + value));
                });
            });
            return true;
        });
    });
    System.out.println("Done");
}
Also used : MediaSegmentMetadataReader(org.vitrivr.cineast.core.db.dao.reader.MediaSegmentMetadataReader) MediaSegmentReader(org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader) StringTypeProvider(org.vitrivr.cineast.core.data.providers.primitive.StringTypeProvider) MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor) RetrievalRuntimeConfig(org.vitrivr.cineast.standalone.config.RetrievalRuntimeConfig) Map(java.util.Map)

Example 15 with MediaSegmentDescriptor

use of org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor in project cineast by vitrivr.

the class LSC21TemporalUpdateCommand method convert.

private static MediaSegmentDescriptor convert(Tuple segmentTuple) {
    final String oid = (String) segmentTuple.get(CineastConstants.OBJECT_ID_COLUMN_QUALIFIER);
    final String sid = (String) segmentTuple.get(CineastConstants.SEGMENT_ID_COLUMN_QUALIFIER);
    final int number = (Integer) segmentTuple.get(MediaSegmentDescriptor.SEGMENT_NO_COL_NAME);
    final int start = (Integer) segmentTuple.get(MediaSegmentDescriptor.SEGMENT_START_COL_NAME);
    final int end = (Integer) segmentTuple.get(MediaSegmentDescriptor.SEGMENT_END_COL_NAME);
    final double startabs = (Double) segmentTuple.get(MediaSegmentDescriptor.SEGMENT_STARTABS_COL_NAME);
    final double endabs = (Double) segmentTuple.get(MediaSegmentDescriptor.SEGMENT_ENDABS_COL_NAME);
    MediaSegmentDescriptor segment = new MediaSegmentDescriptor(oid, sid, number, start, end, (float) startabs, (float) endabs, true);
    return segment;
}
Also used : MediaSegmentDescriptor(org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor)

Aggregations

MediaSegmentDescriptor (org.vitrivr.cineast.core.data.entities.MediaSegmentDescriptor)23 ArrayList (java.util.ArrayList)12 List (java.util.List)10 HashMap (java.util.HashMap)9 StringDoublePair (org.vitrivr.cineast.core.data.StringDoublePair)8 MediaSegmentReader (org.vitrivr.cineast.core.db.dao.reader.MediaSegmentReader)8 Map (java.util.Map)7 TemporalObject (org.vitrivr.cineast.core.data.TemporalObject)7 Collectors (java.util.stream.Collectors)5 HashSet (java.util.HashSet)4 MediaSegmentQueryResult (org.vitrivr.cineast.api.messages.result.MediaSegmentQueryResult)4 Config (org.vitrivr.cineast.standalone.config.Config)4 Set (java.util.Set)3 IntStream (java.util.stream.IntStream)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 MediaObjectDescriptor (org.vitrivr.cineast.core.data.entities.MediaObjectDescriptor)3 FileNotFoundException (java.io.FileNotFoundException)2 Comparator (java.util.Comparator)2 TreeMap (java.util.TreeMap)2