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.video.translator;
034
035import org.openimaj.image.Image;
036import org.openimaj.video.Video;
037import org.openimaj.video.processor.VideoProcessor;
038
039/**
040 *      A video translator is a video processor where the input and output
041 *      frame types may be different. This means that no processing can take
042 *      place in place but new frames must be returned.
043 *      <p>       
044 *      Although it overrides {@link VideoProcessor}, this processor must be
045 *      used in chain mode - that is, it appears as a {@link Video} of the output
046 *      type while taking a video of the input type.
047 *
048 *      @author David Dupplaw (dpd@ecs.soton.ac.uk)
049 *  @created 1 Mar 2012
050 *      
051 *
052 *      @param <INPUT> 
053 *      @param <OUTPUT> 
054 */
055public abstract class VideoTranslator<INPUT extends Image<?,INPUT>,
056        OUTPUT extends Image<?,OUTPUT>> 
057        extends Video<OUTPUT>
058{
059        /** The input video */
060        private Video<INPUT> video = null;
061        
062        /** The last processed frame */
063        private OUTPUT currentFrame = null;
064        
065        /**
066         *      Construct a new VideoTranslator that will translate
067         *      the given input video.
068         *      @param in The input video.
069         */
070        public VideoTranslator( Video<INPUT> in )
071        {
072                this.video = in;
073        }
074        
075        @Override
076        public double getFPS()
077        {
078                return video.getFPS();
079        }
080        
081        @Override
082        public OUTPUT getCurrentFrame()
083        {
084                return currentFrame;
085        }
086
087        @Override
088        public int getWidth()
089        {
090                return video.getWidth();
091        }
092
093        @Override
094        public int getHeight()
095        {
096                return video.getHeight();
097        }
098
099        @Override
100        public long getTimeStamp()
101        {
102                return video.getTimeStamp();
103        }
104
105        @Override
106        public boolean hasNextFrame()
107        {
108                return video.hasNextFrame();
109        }
110
111        @Override
112        public long countFrames()
113        {
114                return video.countFrames();
115        }
116
117        @Override
118        public void reset()
119        {
120                video.reset();
121        }
122
123        @Override
124        public OUTPUT getNextFrame()
125        {
126                return currentFrame = translateFrame( video.getNextFrame() );
127        }
128
129        /**
130         *      Translate the given input frame to the appropriate output frame.
131         * 
132         *      @param nextFrame The input frame.
133         *      @return The output frame
134         */
135        public abstract OUTPUT translateFrame( INPUT nextFrame );
136}