Skip to content
Browse files

Changed to use config properties instead of command line options.

  • Loading branch information...
1 parent 8678fc4 commit a1912f24450e23a8fd66bca3ebc0b82caaf6de84 @ushadow committed Aug 11, 2011
View
7 .gitignore
@@ -1,4 +1,9 @@
bin
*.so
.settings
-data
+data/*
+!data/.gitkeep
+config/*
+!config/.gitkeep
+lib/*
+!lib/.gitkeep
View
1 config/.gitkeep
@@ -0,0 +1 @@
+
View
1 data/.gitkeep
@@ -0,0 +1 @@
+
View
1 lib/.gitkeep
@@ -0,0 +1 @@
+
View
53 src/edu/mit/yingyin/tabletop/CalibrationExample.java
@@ -1,23 +1,28 @@
package edu.mit.yingyin.tabletop;
-import java.util.List;
-
-import javax.vecmath.Point2f;
-
-import static com.googlecode.javacv.cpp.opencv_core.CV_32FC1;
-import static com.googlecode.javacv.cpp.opencv_core.CV_32FC2;
import static com.googlecode.javacv.cpp.opencv_calib3d.cvFindExtrinsicCameraParams2;
-import static com.googlecode.javacv.cpp.opencv_calib3d.cvRodrigues2;
import static com.googlecode.javacv.cpp.opencv_calib3d.cvFindHomography;
-import static com.googlecode.javacv.cpp.opencv_imgproc.cvUndistortPoints;
+import static com.googlecode.javacv.cpp.opencv_calib3d.cvRodrigues2;
+import static com.googlecode.javacv.cpp.opencv_core.CV_32FC1;
+import static com.googlecode.javacv.cpp.opencv_core.CV_32FC2;
import static com.googlecode.javacv.cpp.opencv_core.cvGEMM;
import static com.googlecode.javacv.cpp.opencv_core.cvTranspose;
+import static com.googlecode.javacv.cpp.opencv_imgproc.cvUndistortPoints;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.vecmath.Point2f;
+
+import rywang.util.ObjectIO;
import com.googlecode.javacv.cpp.opencv_core.CvMat;
public class CalibrationExample {
+
public enum CalibMethod {Extrinsic, Homography, Distortion};
+ private static final long serialVersionUID = 8128132501879730224L;
private static final float[][] INTRINSIC_MATRIX = {
{(float)5.9421434211923247e+02, 0, (float)3.3930780975300314e+02},
{0, (float)5.9104053696870778e+02, (float)2.4273913761751615e+02},
@@ -141,23 +146,31 @@ private Point2f imageToDisplayCoords2Homography(Point2f imagePoint) {
}
/**
- * Calculates the average error between the converted display coordinates from
- * the image coordinates and the actual display coordinates.
+ * Calculates and prints the average error between the converted display
+ * coordinates from the image coordinates and the actual display coordinates.
*
* @param displayCoords list of actaul display coordinates.
* @param imageCoords list of corresponding image coordinates of the same size
* as displayCoords.
- * @return average of squared L2 distance between converted and actual display
- * coordinates.
*/
- public float imageToDisplayCoordsError(List<Point2f> displayCoords,
+ public void printImageToDisplayCoordsErrors(List<Point2f> displayCoords,
List<Point2f> imageCoords) {
float error = 0;
- for (int i = 0; i < displayCoords.size(); i++) {
+ float xError = 0;
+ float yError = 0;
+ int numPoints = displayCoords.size();
+ for (int i = 0; i < numPoints; i++) {
Point2f converted = imageToDisplayCoords(imageCoords.get(i));
- error += converted.distanceSquared(displayCoords.get(i));
+ Point2f display = displayCoords.get(i);
+ error += converted.distanceSquared(display);
+ xError += (converted.x - display.x) * (converted.x - display.x);
+ yError += (converted.y - display.y) * (converted.y - display.y);
}
- return error / displayCoords.size();
+ System.out.println("X-axis average error = " +
+ Math.sqrt(xError / numPoints));
+ System.out.println("Y-axis average error = " +
+ Math.sqrt(yError / numPoints));
+ System.out.println("Average error = " + Math.sqrt(error / numPoints));
}
public void release() {
@@ -196,6 +209,14 @@ public String toString() {
return sb.toString();
}
+ public void saveObject(String fileName) {
+ try {
+ ObjectIO.writeObject(this, fileName);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
/**
* Requires objectPoints.size = imagePoints.size
* @param objectPoints
View
104 src/edu/mit/yingyin/tabletop/app/CalibrationApp.java
@@ -1,35 +1,44 @@
package edu.mit.yingyin.tabletop.app;
+import java.awt.Point;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.Properties;
import java.util.Scanner;
import javax.imageio.ImageIO;
import javax.vecmath.Point2f;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionBuilder;
-
import edu.mit.yingyin.calib.CalibView;
import edu.mit.yingyin.calib.GeoCalibModel;
import edu.mit.yingyin.tabletop.CalibrationExample;
import edu.mit.yingyin.tabletop.CalibrationExample.CalibMethod;
import edu.mit.yingyin.tabletop.OpenNIWrapper;
-import edu.mit.yingyin.util.CommandLineOptions;
import edu.mit.yingyin.util.FileUtil;
public class CalibrationApp {
- private static class CalibrationController extends KeyAdapter {
+ private class CalibrationController extends KeyAdapter {
public void keyPressed(KeyEvent ke) {
switch (ke.getKeyCode()) {
case KeyEvent.VK_Q:
case KeyEvent.VK_ESCAPE:
+ if (calibModel != null) {
+ List<Point2f> points = new ArrayList<Point2f>(
+ calibModel.getImagePoints().size());
+ for (Point p : calibModel.getImagePoints())
+ points.add(new Point2f(p.x, p.y));
+ if (isScrnCoord)
+ screenPoints = points;
+ else cameraPoints = points;
+ calibrate();
+ }
System.exit(0);
break;
default: break;
@@ -41,47 +50,41 @@ public static void main(String args[]) {
new CalibrationApp(args);
}
+ private boolean isScrnCoord = true;
private List<Point2f> screenPoints;
private List<Point2f> cameraPoints;
private List<Point2f> screenPointsTest;
private List<Point2f> cameraPointsTest;
+ private GeoCalibModel calibModel;
+ private CalibMethod calibMethod = CalibMethod.Extrinsic;
+ private String calibMethodStr;
+ private String savePath;
@SuppressWarnings("static-access")
public CalibrationApp(String args[]) {
- // Raw depth image.
- Option camDepthImgOption = OptionBuilder.withLongOpt("cam-depth-image").
- hasArg().create();
- Option camPtsOption = OptionBuilder.withLongOpt("cam-points").hasArg().
- create();
- Option camPtsTestOption = OptionBuilder.withLongOpt("cam-points-t").
- hasArg().create();
- Option scrnImgOption = OptionBuilder.withLongOpt("screen-image").hasArg().
- create();
- Option screenPtsOption = OptionBuilder.withLongOpt("screen-points").
- hasArg().create();
- Option screenPtsTestOption = OptionBuilder.withLongOpt("screen-points-t").
- hasArg().create();
-
- CommandLineOptions.addOption(camDepthImgOption);
- CommandLineOptions.addOption(screenPtsOption);
- CommandLineOptions.addOption(scrnImgOption);
- CommandLineOptions.addOption(camPtsOption);
- CommandLineOptions.addOption(camPtsTestOption);
- CommandLineOptions.addOption(screenPtsTestOption);
-
- CommandLineOptions.parse(args);
+ Properties config = new Properties();
+ FileInputStream in = null;
+ try {
+ in = new FileInputStream(
+ "./config/calibration.config");
+ config.load(in);
+ in.close();
+ } catch (FileNotFoundException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
- String camImgPath = CommandLineOptions.getOptionValue("cam-depth-image",
- null);
- String scrnImagePath = CommandLineOptions.getOptionValue("screen-image",
- null);
- String screenPtsPath = CommandLineOptions.getOptionValue("screen-points",
- null);
- String camPtsPath = CommandLineOptions.getOptionValue("cam-points", null);
- String camPtsTestPath = CommandLineOptions.getOptionValue("cam-points-t",
- null);
- String screenPtsTestPath = CommandLineOptions.getOptionValue(
- "screen-points-t", null);
+ String camImgPath = config.getProperty("cam-depth-image", null);
+ String scrnImagePath = config.getProperty("screen-image", null);
+ String screenPtsPath = config.getProperty("screen-points", null);
+ String camPtsPath = config.getProperty("cam-points", null);
+ String camPtsTestPath = config.getProperty("cam-points-t", null);
+ String screenPtsTestPath = config.getProperty("screen-points-t", null);
+ calibMethodStr = config.getProperty("calib-method", "extrinsic");
+ savePath = config.getProperty("save", null);
if (screenPtsPath != null)
screenPoints = readPointsFromFile(screenPtsPath);
@@ -95,7 +98,12 @@ public CalibrationApp(String args[]) {
if (camPtsTestPath != null)
cameraPointsTest = readPointsFromFile(camPtsTestPath);
- boolean isScrnCoord = true;
+ if (calibMethodStr.equals("homography"))
+ calibMethod = calibMethod.Homography;
+ else if (calibMethodStr.equals("distortion"))
+ calibMethod = CalibMethod.Distortion;
+ else calibMethod = calibMethod.Extrinsic;
+
BufferedImage image = null;
String ptsFileName = null;
@@ -121,8 +129,8 @@ public CalibrationApp(String args[]) {
System.exit(-1);
}
}
- CalibView view = new CalibView(
- new GeoCalibModel(image, ptsFileName, isScrnCoord));
+ calibModel = new GeoCalibModel(image, ptsFileName, isScrnCoord);
+ CalibView view = new CalibView(calibModel);
view.addKeyListener(new CalibrationController());
view.showView();
} else {
@@ -149,18 +157,18 @@ public CalibrationApp(String args[]) {
private void calibrate() {
if (screenPoints != null && !screenPoints.isEmpty() &&
cameraPoints != null && !cameraPoints.isEmpty()) {
+ System.out.println("Calibration method: " + calibMethodStr);
CalibrationExample example =
- new CalibrationExample(screenPoints, cameraPoints,
- CalibMethod.Extrinsic);
+ new CalibrationExample(screenPoints, cameraPoints, calibMethod);
System.out.println(example.toString());
- System.out.println("Average reprojection squared error: " +
- example.imageToDisplayCoordsError(screenPoints, cameraPoints));
+ System.out.println("Average reprojection errors in pixels:");
+ example.printImageToDisplayCoordsErrors(screenPoints, cameraPoints);
if (screenPointsTest != null && !screenPointsTest.isEmpty() &&
cameraPointsTest != null && !cameraPointsTest.isEmpty()) {
- System.out.println("Average test squared error: " +
- example.imageToDisplayCoordsError(screenPointsTest,
- cameraPointsTest));
+ System.out.println("Average test squared error:");
+ example.printImageToDisplayCoordsErrors(screenPointsTest,
+ cameraPointsTest);
}
example.release();
}

0 comments on commit a1912f2

Please sign in to comment.
Something went wrong with that request. Please try again.