package imagetools;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
/**
* Tries to find the base spline for the top bottom and then middle of the
* image and then calculates the angle using the horizon as the reference plane.
*
* @author aevens
*
*/
public class Deskew implements Proximity{
private Image image=Image.getInstance();
private ArrayList<PtObject> points;
private EdgePtObject ptobject;
/**
* Empty Constructor
*/
public Deskew() {
}
/**
* Set the image from a file path
*/
@Override
public void setImage(String inpath) {
// TODO Auto-generated method stub
Pattern p=Pattern.compile("(?mi)(\\.jpg|\\.jpeg|\\.gif|\\.bmp)");
Matcher m=p.matcher(inpath);
if(m.find()){
image.setPath(inpath);
try {
image.setImage(ImageIO.read(new File(image.getPath())));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
try{
throw new FileTypeException("Image must be a jpg, gif, bmp, or jpeg");
}catch(FileTypeException e){
e.printStackTrace();
}
}
}
/**
* Set an image path
*/
@Override
public void setPath(String path) {
// TODO Auto-generated method stub
image.setPath(path);
}
/**
* Get the image path
*/
@Override
public String getPath() {
// TODO Auto-generated method stub
return image.getPath();
}
/**
* Get the image points
* @return
*/
public ArrayList<PtObject> getPoints() {
return points;
}
/**
* Set the image points
* @param points
*/
public void setPoints(ArrayList<PtObject> points) {
this.points = points;
}
/**
* Get the Edges from an image
*/
public void getEdges() {
}
/**
* Get the Buffered Image
* @return
*/
public BufferedImage getBufferedImage() {
return image.getImage();
}
/**
* Get the Image
*/
@Override
public Image getImage(){
return image;
}
/**
* Set the point object
* @param ptobject
*/
public void setPtobject(EdgePtObject ptobject) {
this.ptobject = ptobject;
}
/**
* Set the image froma buffered image
*/
@Override
public void setImage(BufferedImage inimage) {
image.setImage(inimage);
}
/**
* Calculate the Object Skews by finding the base points and then getting splines
* for the top, middle, and bottom lines found. Make sure to use this class
* with a cropped out version of the full image you wish to use
*/
private void calcObjectSkews() {
// TODO calculate the maximum and minimum heights of objects found and
// then calculate the angle of the object
BufferedImage proxyimage=image.getImage();
for (int i = 0; i < proxyimage.getWidth(); i++) {
for (int j = 0; j < proxyimage.getHeight(); j++) {
}
}
}
private void calcSkew() {
// TODO take in the individual skews and find a mean angle from the
// horizontal
}
private void rotate() {
// TODO rotate an object by the skew angle using hte rotate class
}
public EdgePtObject getPtobject() {
return ptobject;
}
public void run() {
}
/**
* Save the Image
*/
@Override
public void save() {
// TODO Auto-generated method stub
image.save();
}
/**
* Delete the Image
*/
@Override
public void delete() {
// TODO Auto-generated method stub
image.delete();
}
}