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.sitestuff; 031 032import java.io.File; 033import java.io.IOException; 034import java.net.MalformedURLException; 035import java.net.URL; 036 037import org.openimaj.image.DisplayUtilities; 038import org.openimaj.image.FImage; 039import org.openimaj.image.ImageUtilities; 040import org.openimaj.image.MBFImage; 041import org.openimaj.image.colour.ColourSpace; 042import org.openimaj.image.processing.face.detection.CLMDetectedFace; 043import org.openimaj.image.processing.face.detection.CLMFaceDetector; 044import org.openimaj.image.processing.face.detection.DetectedFace; 045import org.openimaj.image.processing.face.detection.HaarCascadeDetector; 046import org.openimaj.image.processing.face.detection.keypoints.FKEFaceDetector; 047import org.openimaj.image.processing.face.detection.keypoints.KEDetectedFace; 048import org.openimaj.image.processing.face.util.CLMDetectedFaceRenderer; 049import org.openimaj.image.processing.face.util.KEDetectedFaceRenderer; 050import org.openimaj.image.processing.face.util.SimpleDetectedFaceRenderer; 051import org.openimaj.image.processing.resize.ResizeProcessor; 052 053public class FaceDetSiteDemo { 054 public static void main(String[] args) throws MalformedURLException, IOException { 055 // Load the image 056 FImage img = ImageUtilities.readF(new URL("file:///Users/ss/Desktop/Barack-Obama-02.jpg")); 057 img.processInplace(new ResizeProcessor(640, 480)); 058 059 MBFImage mbfAll = new MBFImage(img.width*3, img.height, ColourSpace.RGB); 060 MBFImage mbf; 061 062 // A simple Haar-Cascade face detector 063 HaarCascadeDetector det1 = new HaarCascadeDetector(); 064 DetectedFace face1 = det1.detectFaces(img).get(0); 065 066 mbf = MBFImage.createRGB(img); 067 new SimpleDetectedFaceRenderer().drawDetectedFace(mbf,10,face1); 068 mbfAll.drawImage(mbf, 0, 0); 069 070 071 // Get the facial keypoints 072 FKEFaceDetector det2 = new FKEFaceDetector(); 073 KEDetectedFace face2 = det2.detectFaces(img).get(0); 074 075 mbf = MBFImage.createRGB(img); 076 new KEDetectedFaceRenderer().drawDetectedFace(mbf,10,face2); 077 mbfAll.drawImage(mbf, img.width, 0); 078 079 080 // With the CLM Face Model 081 CLMFaceDetector det3 = new CLMFaceDetector(); 082 CLMDetectedFace face3 = det3.detectFaces(img).get(0); 083 084 mbf = MBFImage.createRGB(img); 085 new CLMDetectedFaceRenderer().drawDetectedFace(mbf,10,face3); 086 mbfAll.drawImage(mbf, img.width*2, 0); 087 088 mbfAll.processInplace(new ResizeProcessor(320,240)); 089 090 DisplayUtilities.display(mbfAll); 091 ImageUtilities.write(mbfAll, new File("/Users/ss/Desktop/barack-detected.png")); 092 } 093}