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);
}
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;
}
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);
}
}
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");
}
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;
}
Aggregations