001/** 002 * Copyright (c) 2011, The University of Southampton and the individual contributors. 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without modification, 006 * are permitted provided that the following conditions are met: 007 * 008 * * Redistributions of source code must retain the above copyright notice, 009 * this list of conditions and the following disclaimer. 010 * 011 * * Redistributions in binary form must reproduce the above copyright notice, 012 * this list of conditions and the following disclaimer in the documentation 013 * and/or other materials provided with the distribution. 014 * 015 * * Neither the name of the University of Southampton nor the names of its 016 * contributors may be used to endorse or promote products derived from this 017 * software without specific prior written permission. 018 * 019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 029 */ 030/** 031 * 032 */ 033package org.openimaj.demos.sandbox.video; 034 035import java.util.HashSet; 036import java.util.Set; 037 038import org.openimaj.image.Image; 039import org.openimaj.video.processor.VideoProcessor; 040 041/** 042 * A {@link VideoProcessor} that is able to also provide annotations for 043 * the video it is processing. The type of the annotation that it provides is 044 * given in the generic arguments of the class. 045 * <p> 046 * As a video is being processed, the annotator may be asked to reset itself - 047 * to start the annotation process anew. The {@link #reset()} method should be 048 * called to do this, which will in turn call the {@link #resetAnnotator()} 049 * method which may be overridden in subclass implementations. 050 * 051 * @author David Dupplaw (dpd@ecs.soton.ac.uk) 052 * @created 22 Jan 2013 053 * @version $Author$, $Revision$, $Date$ 054 * @param <T> The image type 055 * @param <ANNOTATION> The annotation type 056 */ 057@SuppressWarnings( "javadoc" ) 058public abstract class VideoAnnotator<T extends Image<?,T>,ANNOTATION> 059 extends VideoProcessor<T> 060{ 061 /** The list of annotations generates for this video since the last reset */ 062 protected Set<ANNOTATION> annotations = new HashSet<ANNOTATION>(); 063 064 /** 065 * Returns the list of annotations generated for this annotator. 066 * @return The list of annotations generated since the last reset 067 */ 068 public final Set<ANNOTATION> getAnnotations() 069 { 070 this.updateAnnotations(); 071 return this.annotations; 072 } 073 074 /** 075 * Update the annotations list. The <code>annotations</code> member 076 * is a {@link Set}, so you should be able to add annotations without 077 * being concerned about duplicates, as long as the ANNOTATION type 078 * is {@link Comparable}. 079 */ 080 protected void updateAnnotations() 081 { 082 // No implementation. Override for your implementation. 083 } 084 085 /** 086 * Reset the annotator. 087 */ 088 protected void resetAnnotator() 089 { 090 // No implementation. Override for your implementation. 091 } 092 093 /** 094 * {@inheritDoc} 095 * @see org.openimaj.video.processor.VideoProcessor#reset() 096 */ 097 @Override 098 public final void reset() 099 { 100 this.annotations = new HashSet<ANNOTATION>(); 101 this.resetAnnotator(); 102 } 103}