I use .curveTo method to draw a curved line with Bezier curve. Now, I want to count the distance between pixels' coordinates using Hausdorff Distance method. I set the starting point, control points, and end points manually. How can I get and print all (x,y)coordinates which has been passed by the curve? At least, for the right or left eyebrow.
This is my source code:
package emodetection;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.Path2D;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Bezier extends JPanel {
private static BufferedImage bi;
private static int w;
private static int h;
public Bezier() {
ImageIcon ii = new ImageIcon("images/output.jpg");
Image img = ii.getImage();
int imageWidth = img.getWidth(this);
int imageHeight = img.getHeight(this);
w = imageWidth/2;
h = imageHeight/2;
bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
Graphics g = bi.createGraphics();
g.drawImage(img, 0, 0, (int) w, (int) h, this);
ImageIcon newii = new ImageIcon(bi);
System.out.println("img height is " + img.getHeight(this));
JLabel imageLabel = new JLabel("", newii, JLabel.RIGHT);
super.add(imageLabel, JPanel.RIGHT_ALIGNMENT);
}
// Draw curve line in an image
public void paintComponent (Graphics g) {
super.paintComponent(g);
Graphics2D g2 = bi.createGraphics();
ImageIcon ii = new ImageIcon("image/output.jpg");
JLabel imageLabel = new JLabel("Face", ii, JLabel.CENTER);
JPanel jp = new JPanel(new BorderLayout());
jp.add(imageLabel, BorderLayout.CENTER);
g2.setColor(Color.BLUE);
// Right eyebrow
Path2D rightEB = new Path2D.Double();
rightEB.moveTo(80/2, 260/2);
rightEB.curveTo(79/2, 169/2, 316/2, 171/2, 314/2, 196/2);
g2.draw(rightEB);
// Left eyebrow
Path2D leftEB = new Path2D.Double();
leftEB.moveTo(698/2, 227/2);
leftEB.curveTo(702/2, 154/2, 465/2, 155/2, 467/2, 184/2);
g2.draw(leftEB);
// Right eye
Path2D re1 = new Path2D.Double();
re1.moveTo(156/2, 312/2);
re1.curveTo(156/2, 278/2, 313/2, 277/2, 318/2, 321/2);
g2.draw(re1);
Path2D re2 = new Path2D.Double();
re2.moveTo(156/2, 312/2);
re2.curveTo(156/2, 342/2, 319/2, 338/2, 318/2, 321/2);
g2.draw(re2);
// Left eye
Path2D le1 = new Path2D.Double();
le1.moveTo(481/2, 310/2);
le1.curveTo(480/2, 265/2, 642/2, 264/2, 642/2, 300/2);
g2.draw(le1);
Path2D le2 = new Path2D.Double();
le2.moveTo(481/2, 310/2);
le2.curveTo(481/2, 336/2, 642/2, 337/2, 642/2, 300/2);
g2.draw(le2);
// Lip
// Upper lip
Path2D m1 = new Path2D.Double();
m1.moveTo(238/2, 657/2);
m1.curveTo(238/2, 626/2, 577/2, 626/2, 577/2, 647/2);
System.out.println(m1.getPathIterator(null));
g2.draw(m1);
// Lower lip
Path2D m2 = new Path2D.Double();
m2.moveTo(238/2, 657/2);
m2.curveTo(238/2, 788/2, 579/2, 788/2, 577/2, 647/2);
g2.draw(m2);
}
public static void main(String[] args) {
JFrame frame = new JFrame("Testing Bezier Curve");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Bezier bezier = new Bezier();
frame.add(bezier);
frame.setSize(w*3, h);
frame.setVisible(true);
}
}
I would be really grateful for any help offered.