Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added display of arm joint.

  • Loading branch information...
commit 15f7631ef545c77a5c4df299e6f30fe5e85e1ff7 1 parent c276d21
@ushadow authored
View
45 src/edu/mit/yingyin/tabletop/models/Forelimb.java
@@ -22,34 +22,43 @@ public ValConfiPair(T v, float c) {
}
}
- private List<ValConfiPair<Point3f>> fingertips;
+ /**
+ * Fingertip locations in the image coordinate.
+ */
+ private List<ValConfiPair<Point3f>> fingertipsI;
/**
- * Can be null.
+ * Arm joint location in the world coordinate. Can be null.
*/
- private Point3f armJoint;
+ private Point3f armJointW;
+
+ private Point3f armJointI;
public List<Point3f> filteredFingertips = new ArrayList<Point3f>();
- public Forelimb(List<ValConfiPair<Point3f>> fingertips, Point3f armJoint) {
- if (fingertips == null) {
- fingertips = new ArrayList<ValConfiPair<Point3f>>();
+ public Forelimb(List<ValConfiPair<Point3f>> fingertipsI, List<Point3f> armJoints) {
+ if (fingertipsI == null) {
+ fingertipsI = new ArrayList<ValConfiPair<Point3f>>();
+ }
+ this.fingertipsI = fingertipsI;
+
+ if (armJoints != null && armJoints.size() >= 2) {
+ this.armJointI = armJoints.get(0);
+ this.armJointW = armJoints.get(1);
}
- this.fingertips = fingertips;
- this.armJoint = armJoint;
}
public Forelimb(Forelimb other) {
- armJoint = new Point3f(other.armJoint);
- fingertips.clear();
- for (ValConfiPair<Point3f> p : other.fingertips) {
- fingertips.add(new ValConfiPair<Point3f>(
+ armJointW = new Point3f(other.armJointW);
+ fingertipsI.clear();
+ for (ValConfiPair<Point3f> p : other.fingertipsI) {
+ fingertipsI.add(new ValConfiPair<Point3f>(
new Point3f(p.value), p.confidence));
}
}
public List<Point3f> getFingertips() {
List<Point3f> res = new ArrayList<Point3f>();
- for (ValConfiPair<Point3f> p : fingertips) {
+ for (ValConfiPair<Point3f> p : fingertipsI) {
if (p.confidence > 0.5)
res.add(new Point3f(p.value));
}
@@ -57,6 +66,14 @@ public Forelimb(Forelimb other) {
}
public int numFingertips() {
- return fingertips.size();
+ return fingertipsI.size();
}
+
+ /**
+ * @return the 3D position of the arm joint in the image coordinate. Can be null.
+ */
+ public Point3f armJointI() {
+ if (armJointI == null)
+ return null;
+ return new Point3f(armJointI); }
}
View
39 src/edu/mit/yingyin/tabletop/models/ForelimbModelEstimator.java
@@ -81,8 +81,8 @@ private void findFingertipsConvexityDefects(ProcessPacket packet) {
}
}
}
- Point3f armJoint = findArmJoint(packet, ff.armJointRegion);
- Forelimb forelimb = new Forelimb(fingertips, armJoint);
+ List<Point3f> armJoints = findArmJoint(packet, ff.armJointRegion);
+ Forelimb forelimb = new Forelimb(fingertips, armJoints);
packet.forelimbs.add(forelimb);
}
}
@@ -193,8 +193,8 @@ public void extractFingertipsConvexHull(ProcessPacket packet) {
new Point3f(C.x, C.y, z), 1));
}
}
- Point3f armJoint = findArmJoint(packet, ff.armJointRegion);
- Forelimb forelimb = new Forelimb(fingertips, armJoint);
+ List<Point3f> armJoints = findArmJoint(packet, ff.armJointRegion);
+ Forelimb forelimb = new Forelimb(fingertips, armJoints);
packet.forelimbs.add(forelimb);
}
}
@@ -273,9 +273,9 @@ private void thinningHands(ProcessPacket packet) {
fingertips.add(new ValConfiPair<Point3f>(
new Point3f(finger.get(finger.size() - 1)), 1));
}
- Point3f armJoint = findArmJoint(packet, ff.armJointRegion);
+ List<Point3f> armJoints = findArmJoint(packet, ff.armJointRegion);
- Forelimb forelimb = new Forelimb(fingertips, armJoint);
+ Forelimb forelimb = new Forelimb(fingertips, armJoints);
packet.forelimbs.add(forelimb);
}
}
@@ -345,14 +345,18 @@ private boolean isSinglePixel(byte[][] pixels, int i, int j) {
}
/**
- * Finds the center of the arm joint of a forelimb.
+ * Finds the center of the arm joint of a forelimb in the image and the in the world coordinates.
* @param packet
* @param rect
- * @return the 3D location of the arm joint or null if there is an exception.
+ * @return a list of 3D points. The first point is the 3D location of the arm joint in the image,
+ * and the 2nd one is the location in the world coordinate. The list is empty if the arm joint
+ * cannot be found.
*/
- private Point3f findArmJoint(ProcessPacket packet, CvRect rect) {
+ private List<Point3f> findArmJoint(ProcessPacket packet, CvRect rect) {
+ List<Point3f> res = new ArrayList<Point3f>(2);
+
if (rect == null)
- return null;
+ return res;
try {
HandTrackingEngine engine = HandTrackingEngine.instance();
@@ -369,6 +373,15 @@ private Point3f findArmJoint(ProcessPacket packet, CvRect rect) {
if (list.size() == 0)
return null;
+ float imagex = 0, imagey = 0, imagez = 0;
+ for (Point3D point : list) {
+ imagex += point.getX();
+ imagey += point.getY();
+ imagez += point.getZ();
+ }
+
+ res.add(new Point3f(imagex / list.size(), imagey / list.size(), imagez / list.size()));
+
Point3D[] points = new Point3D[list.size()];
list.toArray(points);
Point3D[] converted = engine.convertProjectiveToRealWorld(points);
@@ -378,12 +391,10 @@ private Point3f findArmJoint(ProcessPacket packet, CvRect rect) {
centery += point.getY();
centerz += point.getZ();
}
- return new Point3f(centerx / list.size(), centery / list.size(),
- centerz / list.size());
+ res.add(new Point3f(centerx / list.size(), centery / list.size(), centerz / list.size()));
} catch (GeneralException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
- return null;
+ return res;
}
}
View
11 src/edu/mit/yingyin/tabletop/views/ProcessPacketView.java
@@ -283,12 +283,19 @@ private void showAnalysisImage(ProcessPacket packet) {
}
// Shows unfiltered fingertips.
- if (toggleMap.get(Toggles.SHOW_FINGERTIP))
- for (Forelimb forelimb : packet.forelimbs)
+ if (toggleMap.get(Toggles.SHOW_FINGERTIP)) {
+ for (Forelimb forelimb : packet.forelimbs) {
for (Point3f p : forelimb.getFingertips()) {
cvCircle(analysisImage, new CvPoint((int)p.x, (int)p.y),
4, CvScalar.GREEN, -1, 8, 0);
}
+ Point3f armJoint = forelimb.armJointI();
+ if (armJoint != null) {
+ cvCircle(analysisImage, new CvPoint((int)armJoint.x, (int)armJoint.y), 4, CvScalar.CYAN, -1,
+ 8, 0);
+ }
+ }
+ }
frames[0].showImage(analysisImage);
}
Please sign in to comment.
Something went wrong with that request. Please try again.