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.image.processing.face.detection; 031 032import java.io.DataInput; 033import java.io.DataOutput; 034import java.io.IOException; 035 036import org.openimaj.image.FImage; 037import org.openimaj.image.pixel.ConnectedComponent; 038import org.openimaj.image.pixel.PixelSet; 039import org.openimaj.math.geometry.shape.Rectangle; 040import org.openimaj.math.geometry.shape.Shape; 041 042/** 043 * A {@link DetectedFace} that is represented/detected by a 044 * {@link ConnectedComponent}. 045 * 046 * @author Jonathon Hare (jsh2@ecs.soton.ac.uk) 047 * 048 */ 049public class CCDetectedFace extends DetectedFace { 050 ConnectedComponent connectedComponent; 051 052 /** 053 * Default constructor. 054 */ 055 public CCDetectedFace() { 056 super(); 057 } 058 059 /** 060 * Construct with a bounds rectangle (the bounding box of the face in the 061 * detection image),an image patch that describes the contents of the bounds 062 * rectangle from the original image, and a {@link ConnectedComponent} 063 * describing the shape of the detected face. 064 * 065 * @param bounds 066 * The bounding box of the face in the detection image 067 * @param patch 068 * The subimage describing the contents of the bounding box. 069 * @param cc 070 * The connected component representing the face. 071 * @param confidence 072 * The confidence of the detection 073 */ 074 public CCDetectedFace(Rectangle bounds, FImage patch, ConnectedComponent cc, float confidence) { 075 super(bounds, patch, confidence); 076 this.connectedComponent = cc; 077 } 078 079 /** 080 * @return Get the connected component representing the face. 081 */ 082 public PixelSet getConnectedComponent() { 083 return connectedComponent; 084 } 085 086 /* 087 * (non-Javadoc) 088 * 089 * @see 090 * org.openimaj.image.processing.face.detection.DetectedFace#writeBinary 091 * (java.io.DataOutput) 092 */ 093 @Override 094 public void writeBinary(DataOutput out) throws IOException { 095 super.writeBinary(out); 096 connectedComponent.writeBinary(out); 097 } 098 099 /* 100 * (non-Javadoc) 101 * 102 * @see 103 * org.openimaj.image.processing.face.detection.DetectedFace#binaryHeader() 104 */ 105 @Override 106 public byte[] binaryHeader() { 107 return "CCDF".getBytes(); 108 } 109 110 /* 111 * (non-Javadoc) 112 * 113 * @see 114 * org.openimaj.image.processing.face.detection.DetectedFace#readBinary( 115 * java.io.DataInput) 116 */ 117 @Override 118 public void readBinary(DataInput in) throws IOException { 119 super.readBinary(in); 120 connectedComponent.readBinary(in); 121 } 122 123 @Override 124 public Shape getShape() { 125 return connectedComponent.toPolygon(); 126 } 127}