package com.hygenics.facialrec; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.RecursiveTask; /** * This is Where the most important part of the splines are created. * Points are found by following edges on the face. When an edge is found, * Its tangent is followed. There is an attempt to ignore hair by using certain * features as the main points for mapping. Noise is also followed. If a spline * line returns to the original point, that line is projected further down by the * increment size. * * Defaults are 10 for step size and 1 for increment size. * * For more detail, increase the number of steps. (Height/steps+width/steps=splines). * * This will be a really unchangeable quadratic runtime so PLEASE PLEASE PLEASE ENSURE THAT OBJECTS ARE SMALL. * I do attempt to use threading to combat this though. * * @author asevans (note the com.hygenices package path v. the evans.imagetools package path) * */ public class GetPoints { private int incrementsize; private int step; private BufferedImage bi; private ArrayList<FoundObject> objs; private int splinenum=0; private int numysplines=0; private int numxsplines=0; private Map<Integer, ArrayList> horizsplines=new HashMap<Integer,ArrayList>(); public GetPoints() { } public ArrayList<FoundObject> getObjs() { return objs; } public void setObjs(ArrayList<FoundObject> objs) { this.objs = objs; } public int getNumSplines() { return splinenum; } public int getNumxsplines() { return numxsplines; } public int getNumysplines() { return numysplines; } public int getIncrementsize() { return incrementsize; } public void setIncrementsize(int incrementsize) { this.incrementsize = incrementsize; } public int getStep() { return step; } public void setStep(int step) { this.step = step; } public BufferedImage getBi() { return bi; } public void setBi(BufferedImage bi) { this.bi = bi; } /** * Take in an edge detected image and get the feature points which are used as control points. * The found object is used to offset the image points. * * @author asevans * */ private class FeaturePoints extends RecursiveTask<ArrayList<PointObject>>{ final FoundObject fo; final BufferedImage bi; final boolean xaxis; /** * Empty Constructor */ public FeaturePoints(final FoundObject fo, final BufferedImage bi,final boolean xaxis){ this.fo=fo; this.bi=bi; this.xaxis=xaxis; } /** * Compute points */ @Override protected ArrayList<PointObject> compute() { // TODO Get an ArrayList of Control Points Basedon Features ArrayList<PointObject> po; if(bi != null) { if(xaxis){ //iterate across the image and get the feature points (bottom to top with left to right to follow features) for(int x=0;x<bi.getWidth();x++) { //check for any distinct edge features //if a distinct edge is found follow it as long as it heads in an appropriate direction //and add points to our array until the same y distance is reached or the edge of the image is found } } else{ //iterate up the face and get feature points(bottom to top same general horizontal area) for(int y=0;y<bi.getHeight();y++){ //check for any distinct edge features //if a distinct edge is found follow it as long as it heads in an appropriate direction //and add points to our array until the same y distance is reached or the edge of the image is found } } } return null; } } /** * Attempts to determine the best control points for our current spline * from the Found Objects Array */ private ArrayList<ArrayList<PointObject>> findControlPoints(){ //TODO convert our initial image to black and white edge image if our boolean has not been changed //Fork Join Pool and set for calculating our points ForkJoinPool fjp=new ForkJoinPool(Runtime.getRuntime().availableProcessors()); //the returned arraylist ArrayList<ArrayList<PointObject>> po=new ArrayList<ArrayList<PointObject>>(); //the array list to end up storing ArrayList<PointObject> stepControls; //current x and y positions int x=0; int y=0; //current step id for determining how to proceed int step=0; //find the feature points for each object and keep track of ending y values while(x<bi.getWidth() & y< bi.getHeight()){ for(FoundObject fo: this.objs){ //get the spline points for this object } } return po; } /** * Runs the Get Points class and returns an arraylist of arraylists containing spline control points as point objects for * each step */ public void run(){ if(bi != null){ findControlPoints(); } else{ try{ throw new NullPointerException("No Image Provided"); }catch(NullPointerException e){ e.printStackTrace(); } } } }