1 /** 2 * Copyright (c) 2011, The University of Southampton and the individual contributors. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * * Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 11 * * Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * * Neither the name of the University of Southampton nor the names of its 16 * contributors may be used to endorse or promote products derived from this 17 * software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 package org.openimaj.demos; 31 32 import java.io.IOException; 33 34 import org.openimaj.hardware.kinect.KinectException; 35 import org.openimaj.image.DisplayUtilities; 36 import org.openimaj.image.FImage; 37 import org.openimaj.image.MBFImage; 38 import org.openimaj.image.analysis.algorithm.HoughCircles; 39 import org.openimaj.image.analysis.algorithm.HoughCircles.WeightedCircle; 40 import org.openimaj.image.processing.edges.CannyEdgeDetector; 41 import org.openimaj.image.processing.resize.ResizeProcessor; 42 import org.openimaj.video.VideoDisplay; 43 import org.openimaj.video.VideoDisplayListener; 44 import org.openimaj.video.capture.VideoCapture; 45 46 public class JugglingKinect { 47 public static void main(String[] args) throws KinectException, IOException { 48 // KinectController c = new KinectController(); 49 // VideoDisplay<MBFImage> vid = (VideoDisplay<MBFImage>) VideoDisplay.createVideoDisplay(c.videoStream); 50 VideoDisplay<MBFImage> vid = VideoDisplay.createVideoDisplay(new VideoCapture(320,240)); 51 vid.addVideoListener(new VideoDisplayListener<MBFImage>() { 52 int frames = 0; 53 private HoughCircles circles; 54 @Override 55 public void beforeUpdate(MBFImage frame) { 56 if(frame==null)return; 57 FImage gframe = frame.flatten(); 58 frames ++; 59 // FImage hband = trans.getBand(1).normalise(); 60 // frame = frame.process(new Disk(20)); 61 CannyEdgeDetector d = new CannyEdgeDetector(); 62 ResizeProcessor resize = new ResizeProcessor(0.3f); 63 FImage resized = gframe.process(resize); 64 // FImage canny = resized.process(new FSobelMagnitude()).threshold(0.8f); 65 FImage canny = resized.process(d); 66 if(this.circles == null) 67 this.circles = new HoughCircles(canny.width/15,canny.width/4,5,360); 68 canny.analyseWith(circles); 69 // if(frames % 2 == 0){ 70 // f = f.process(circles); 71 // f.drawPoints(circles.accum, 1.f, 10); 72 // f.drawShape(new Circle(10,10,10), 1f); 73 // } 74 MBFImage colResized = new MBFImage(resized.clone(),resized.clone(),resized.clone()); 75 for (WeightedCircle circ : circles.getBest(5)) { 76 System.out.println(circ.weight); 77 colResized.drawShape(circ, new Float[]{circ.weight,0f,0f}); 78 } 79 80 DisplayUtilities.displayName(canny,"circles"); 81 DisplayUtilities.displayName(colResized,"wang"); 82 } 83 84 @Override 85 public void afterUpdate(VideoDisplay<MBFImage> display) { 86 // TODO Auto-generated method stub 87 88 } 89 }); 90 } 91 }