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 */
030package org.openimaj.demos.acmmm11.presentation.slides;
031
032import java.awt.Component;
033import java.awt.GridLayout;
034import java.io.IOException;
035import java.util.ArrayList;
036import java.util.List;
037
038import javax.swing.JPanel;
039
040import org.openimaj.content.slideshow.CameraSelector;
041import org.openimaj.content.slideshow.Slide;
042import org.openimaj.demos.acmmm11.presentation.slides.tutorial.CannyVideoTutorial;
043import org.openimaj.demos.acmmm11.presentation.slides.tutorial.ColourHistogramGrid;
044import org.openimaj.demos.acmmm11.presentation.slides.tutorial.FaceTrackingTutorial;
045import org.openimaj.demos.acmmm11.presentation.slides.tutorial.SIFTFeatureTutorial;
046import org.openimaj.demos.acmmm11.presentation.slides.tutorial.SegmentationTutorial;
047import org.openimaj.demos.acmmm11.presentation.slides.tutorial.ShapeRenderingTutorial;
048import org.openimaj.demos.acmmm11.presentation.slides.tutorial.TutorialPanel;
049import org.openimaj.image.MBFImage;
050import org.openimaj.video.VideoDisplay;
051import org.openimaj.video.capture.VideoCapture;
052
053/**
054 * Slide showing the results from following the tutorial.
055 * 
056 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk)
057 * @author Sina Samagooei (ss@ecs.soton.ac.uk)
058 * 
059 */
060public class TutorialSlide implements Slide {
061        private VideoCapture capture;
062        private List<VideoDisplay<MBFImage>> displays;
063
064        @Override
065        public Component getComponent(int slideWidth, int slideHeight) throws IOException {
066                final JPanel panel = new JPanel();
067                panel.setOpaque(false);
068                panel.setLayout(new GridLayout(2, 3));
069
070                final int videoWidth = 320;
071                final int videoHeight = 240;
072
073                capture = CameraSelector.getPreferredVideoCapture(videoWidth, videoHeight);
074                displays = new ArrayList<VideoDisplay<MBFImage>>();
075
076                final TutorialPanel[] tutorials = new TutorialPanel[] {
077                                new FaceTrackingTutorial(capture, videoWidth, videoHeight),
078                                new SIFTFeatureTutorial(capture, videoWidth, videoHeight),
079                                new SegmentationTutorial(capture, videoWidth, videoHeight),
080                                new CannyVideoTutorial(capture, videoWidth, videoHeight),
081                                new ShapeRenderingTutorial(capture, videoWidth, videoHeight),
082                                new ColourHistogramGrid(capture, videoWidth, videoHeight)
083                };
084
085                for (final TutorialPanel innerPanel : tutorials) {
086                        panel.add(innerPanel);
087
088                        final VideoDisplay<MBFImage> vd = VideoDisplay.createOffscreenVideoDisplay(capture);
089                        vd.addVideoListener(innerPanel);
090                        displays.add(vd);
091                }
092
093                panel.validate();
094
095                return panel;
096        }
097
098        @Override
099        public void close() {
100                for (final VideoDisplay<MBFImage> vd : displays)
101                        vd.close();
102                displays.clear();
103                capture.stopCapture();
104        }
105}