• R/O
  • SSH
  • HTTPS

matereal: 提交


Commit MetaInfo

修订版198 (tree)
时间2010-11-12 09:54:36
作者arc

Log Message

managing code.

更改概述

  • modified: napkit/trunk/.classpath (diff)
  • delete: napkit/trunk/src.sample.old/sample/Step2_RunDetectMarker.java
  • delete: napkit/trunk/lib/dsj
  • delete: napkit/trunk/lib/capture/LICENSE.txt
  • delete: napkit/trunk/lib/capture/capture-0.1.jar
  • delete: napkit/trunk/lib/capture/README.txt
  • delete: napkit/trunk/lib/capture
  • delete: napkit/trunk/lib/matereal/README.txt
  • delete: napkit/trunk/lib/matereal/matereal-utils-0.1.jar
  • delete: napkit/trunk/lib/matereal/LICENSE.txt
  • delete: napkit/trunk/lib/matereal/matereal-0.1.jar
  • delete: napkit/trunk/lib/matereal
  • delete: napkit/trunk/lib/rxtx-2.1-7-bins-r2/README.txt
  • delete: napkit/trunk/lib/rxtx-2.1-7-bins-r2/RXTXcomm.jar
  • delete: napkit/trunk/lib/rxtx-2.1-7-bins-r2/rxtxParallel.dll
  • delete: napkit/trunk/lib/rxtx-2.1-7-bins-r2/rxtxSerial.dll
  • delete: napkit/trunk/lib/rxtx-2.1-7-bins-r2/LICENSE.txt
  • delete: napkit/trunk/lib/rxtx-2.1-7-bins-r2/librxtxSerial.jnilib
  • delete: napkit/trunk/lib/rxtx-2.1-7-bins-r2
  • delete: napkit/trunk/lib/connector/LICENSE.txt
  • delete: napkit/trunk/lib/connector/connector-0.1.jar
  • delete: napkit/trunk/lib/connector/README.txt
  • delete: napkit/trunk/lib/connector
  • delete: napkit/trunk/src.sample/BringItHereDual.java
  • modified: napkit/trunk/src.sample/BringItHere.java (diff)
  • added: napkit/trunk/src.sample/BringItHereReal.java (diff)
  • added: napkit/trunk/src.sample/DetectMarker.java (diff)

差异

--- napkit/trunk/src.sample.old/sample/Step2_RunDetectMarker.java (revision 197)
+++ napkit/trunk/src.sample.old/sample/Step2_RunDetectMarker.java (nonexistent)
@@ -1,127 +0,0 @@
1-package sample;
2-
3-import java.awt.BasicStroke;
4-
5-import java.awt.Color;
6-import java.awt.Graphics;
7-import java.awt.Graphics2D;
8-import java.awt.Stroke;
9-import java.util.Set;
10-import javax.swing.JFrame;
11-import javax.swing.JOptionPane;
12-
13-import jp.digitalmuseum.capture.VideoCaptureFactoryImpl;
14-import jp.digitalmuseum.mr.Matereal;
15-import jp.digitalmuseum.mr.entity.Entity;
16-import jp.digitalmuseum.mr.entity.EntityImpl;
17-import jp.digitalmuseum.mr.gui.DisposeOnCloseFrame;
18-import jp.digitalmuseum.mr.gui.ImageProviderPanel;
19-import jp.digitalmuseum.mr.service.MarkerDetector;
20-import jp.digitalmuseum.mr.service.Camera;
21-import jp.digitalmuseum.napkit.NapDetectionResult;
22-import jp.digitalmuseum.napkit.NapMarker;
23-import jp.digitalmuseum.napkit.gui.TypicalMDCPane;
24-import jp.digitalmuseum.utils.ScreenPosition;
25-
26-/**
27- * Run a marker detection and show results.
28- *
29- * @author Jun KATO
30- */
31-public class Step2_RunDetectMarker {
32-
33- public static void main(String[] args) {
34- new Step2_RunDetectMarker();
35- }
36-
37- public Step2_RunDetectMarker() {
38-
39- // Run a camera.
40- // Let users select a device to capture images.
41- final String identifier = (String) JOptionPane.showInputDialog(null,
42- "Select a device to capture images.", "Device list",
43- JOptionPane.QUESTION_MESSAGE, null, new VideoCaptureFactoryImpl()
44- .queryIdentifiers(), null);
45- Camera camera;
46- if ((identifier != null) && (identifier.length() > 0)) {
47- camera = new Camera(identifier);
48- } else {
49- camera = new Camera();
50- }
51- camera.setSize(800, 600);
52- camera.start();
53-
54- // Run a marker detector.
55- final MarkerDetector detector = new MarkerDetector();
56- detector.loadCameraParameter("calib_qcam.dat");
57- detector.start();
58-
59- // Show a configuration window.
60- final JFrame configFrame = new DisposeOnCloseFrame(new TypicalMDCPane(detector));
61-
62- // Detect a marker.
63- final NapMarker marker = new NapMarker("markers\\4x4_35.patt",120);
64- final Entity dummy = new EntityImpl("test");
65- detector.put(marker, dummy);
66-
67- // Show detection results in real-time.
68- final DisposeOnCloseFrame frame = new DisposeOnCloseFrame(
69- new ImageProviderPanel(camera) {
70- private static final long serialVersionUID = 1L;
71- private transient Stroke stroke;
72- @Override public void paintComponent(Graphics g) {
73- super.paintComponent(g);
74- final Graphics2D g2 = (Graphics2D) g;
75- if (stroke == null) {
76- stroke = new BasicStroke(5);
77- }
78- g2.setStroke(stroke);
79- g2.translate(getOffsetX(), getOffsetY());
80-
81- // Get detected results.
82- final Set<NapDetectionResult> results = detector.getResults();
83-
84- // Draw each detected result.
85- for (final NapDetectionResult result : results) {
86-
87- // Draw corners
88- g.setColor(Color.orange);
89- detector.paint(g2, result);
90-
91- // Draw information for the square.
92- g.setColor(Color.cyan);
93- final ScreenPosition point = result.getPosition();
94- g2.drawLine(point.getX(), point.getY(), point.getX()+55, point.getY()+43);
95- g2.drawRect(point.getX()+55, point.getY()+23, 200, 40);
96- drawString(g2, "Confidence: "+result.getConfidence(), point.getX()+64, point.getY()+40);
97- drawString(g2, "Position: "+point, point.getX()+64, point.getY()+56);
98- }
99-
100- // Draw detected number of squares.
101- drawString(g2, "detected: "+(results == null ? 0 : results.size()),
102- 10, getHeight()-10);
103- }
104-
105- /**
106- * Draw a string with 1px simple black border.
107- */
108- private void drawString(Graphics g, String s, int x, int y) {
109- g.setColor(Color.black);
110- g.drawString(s, x+1, y);
111- g.drawString(s, x-1, y);
112- g.drawString(s, x, y-1);
113- g.drawString(s, x, y+1);
114- g.setColor(Color.cyan);
115- g.drawString(s, x, y);
116- }
117- }) {
118- private static final long serialVersionUID = 1L;
119- @Override public void dispose() {
120- configFrame.dispose();
121- super.dispose();
122- Matereal.getInstance().dispose();
123- }
124- };
125- frame.setFrameSize(camera.getWidth(), camera.getHeight());
126- }
127-}
--- napkit/trunk/lib/capture/README.txt (revision 197)
+++ napkit/trunk/lib/capture/README.txt (nonexistent)
@@ -1,65 +0,0 @@
1-Webcam capture package - capture
2-Copyright (C) 2009 Jun KATO
3-
4-version 0.1
5-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6-
7-Webcam capture package, or simply "capture", is a simple
8-package for capturing real-time images using webcams.
9-It uses
10- - DirectShow for Windows
11- - QuickTime for Mac OSX
12- - Java Media Framework (Video4Linux) for Linux
13-to capture images.
14-
15-"capture" is distributed under MPL 1.1/GPL 2.0/LGPL 2.1 triple
16-license. Please read LICENSE.txt for the detail.
17-You can get the source code by extracting capture.jar.
18-
19-This toolkit works well with "napkit" which can detect
20-position and rotation of ARToolKit markers in captured images.
21-Please see http://matereal.sourceforge.jp/ for details.
22-
23-
24-=== How to use ===
25-
26-== Windows
27-
28-To use this toolkit on Windows (in other words, when capturing
29-images with DirectShow), you will need "DirectShow for Java",
30-a wrapper library of DirectShow for Java developed by humatic.
31-Note that you are assumed to agree with its license when you
32-use its function.
33-The library and its license documents are available at:
34-http://www.humatic.de/htools/dsj.htm
35-
36-When you get dsj.jar and dsj.dll in the library,
37-please place it under the directory where Java VM can find.
38-
39-== Mac OSX (or Windows with WinVDIG)
40-
41-To use this toolkit on Mac OSX (in other words, when capturing
42-images with QuickTime), you will need "QuickTime for Java",
43-a wrapper library of QuickTime for Java developed by Apple.
44-
45-The library is installed by default in the case of Mac OSX,
46-so nothing is needed for using this library.
47-When you use Windows, you must install QuickTime Player and
48-WinVDIG before using this function.
49-
50-To learn about WinVDIG, please ask Google:
51-http://www.google.co.jp/search?q=winvdig
52-
53-== Linux (or to whom loves Java Media Framework)
54-
55-To use this toolkit on Linux (in other words, when capturing
56-images with Java Media Framework), you will need
57-"Java Media Framework" installed on your computer.
58-
59-To learn about Java Media Framework, please see:
60-http://java.sun.com/javase/technologies/desktop/media/jmf/
61-
62-
63-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
64-http://matereal.sourceforge.jp/
65-arc (at) digitalmuseum.jp
\ No newline at end of file
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/trunk/lib/capture/LICENSE.txt (revision 197)
+++ napkit/trunk/lib/capture/LICENSE.txt (nonexistent)
@@ -1,32 +0,0 @@
1-Webcam capture package - capture
2-Copyright (C) 2009 Jun KATO
3-
4-The contents of this file are subject to the Mozilla Public License Version
5-1.1 (the "License"); you may not use this file except in compliance with
6-the License. You may obtain a copy of the License at
7-http://www.mozilla.org/MPL/
8-
9-Software distributed under the License is distributed on an "AS IS" basis,
10-WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11-for the specific language governing rights and limitations under the
12-License.
13-
14-The Original Code is capture.
15-
16-The Initial Developer of the Original Code is Jun KATO.
17-Portions created by the Initial Developer are
18-Copyright (C) 2009 Jun KATO. All Rights Reserved.
19-
20-Contributor(s): Jun KATO
21-
22-Alternatively, the contents of this file may be used under the terms of
23-either of the GNU General Public License Version 2 or later (the "GPL"),
24-or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25-in which case the provisions of the GPL or the LGPL are applicable instead
26-of those above. If you wish to allow use of your version of this file only
27-under the terms of either the GPL or the LGPL, and not to allow others to
28-use your version of this file under the terms of the MPL, indicate your
29-decision by deleting the provisions above and replace them with the notice
30-and other provisions required by the GPL or the LGPL. If you do not delete
31-the provisions above, a recipient may use your version of this file under
32-the terms of any one of the MPL, the GPL or the LGPL.
\ No newline at end of file
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/trunk/lib/matereal/LICENSE.txt (revision 197)
+++ napkit/trunk/lib/matereal/LICENSE.txt (nonexistent)
@@ -1,32 +0,0 @@
1-matereal
2-Copyright (C) 2009 Jun KATO
3-
4-The contents of this file are subject to the Mozilla Public License Version
5-1.1 (the "License"); you may not use this file except in compliance with
6-the License. You may obtain a copy of the License at
7-http://www.mozilla.org/MPL/
8-
9-Software distributed under the License is distributed on an "AS IS" basis,
10-WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11-for the specific language governing rights and limitations under the
12-License.
13-
14-The Original Code is matereal.
15-
16-The Initial Developer of the Original Code is Jun KATO.
17-Portions created by the Initial Developer are
18-Copyright (C) 2009 Jun KATO. All Rights Reserved.
19-
20-Contributor(s): Jun KATO
21-
22-Alternatively, the contents of this file may be used under the terms of
23-either of the GNU General Public License Version 2 or later (the "GPL"),
24-or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25-in which case the provisions of the GPL or the LGPL are applicable instead
26-of those above. If you wish to allow use of your version of this file only
27-under the terms of either the GPL or the LGPL, and not to allow others to
28-use your version of this file under the terms of the MPL, indicate your
29-decision by deleting the provisions above and replace them with the notice
30-and other provisions required by the GPL or the LGPL. If you do not delete
31-the provisions above, a recipient may use your version of this file under
32-the terms of any one of the MPL, the GPL or the LGPL.
\ No newline at end of file
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/trunk/lib/matereal/README.txt (revision 197)
+++ napkit/trunk/lib/matereal/README.txt (nonexistent)
@@ -1,32 +0,0 @@
1-matereal
2-Copyright (C) 2009 Jun KATO
3-
4-version alpha
5-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6-
7-"matereal" is a Java toolkit that allows to operate home-robots
8-easily.
9-
10-This library is distributed under MPL 1.1/GPL 2.0/LGPL 2.1
11-triple license. Please read LICENSE.txt for the detail.
12-You can get the source code by extracting matereal.jar.
13-
14-This library includes whole distribution of Webcam capture
15-package, or simply "capture" for capturing images with webcams.
16-"capture" is developed by the same author and distributed under
17-the same license with this library.
18-
19-"napkit" is required when you want to know position and
20-rotation of robots and other physical entities in your
21-application by detecting ARToolKit markers in webcam-captured
22-images. "napkit" is distributed under GNU GPLv3
23-Please see http://matereal.sourceforge.jp/ for details.
24-
25-BlueCove is used for bluetooth connection. It is developed at
26-http://bluecove.org/ and distributed under Apache License,
27-Version 2.0.
28-
29-
30-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31-http://matereal.sourceforge.jp/
32-arc (at) digitalmuseum.jp
\ No newline at end of file
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/trunk/lib/rxtx-2.1-7-bins-r2/LICENSE.txt (revision 197)
+++ napkit/trunk/lib/rxtx-2.1-7-bins-r2/LICENSE.txt (nonexistent)
@@ -1,2 +0,0 @@
1-RXTXcomm.jar and rxtx* are distributed under LGPL v 2.1 + Linking Over Controlled Interface license.
2-Please see http://users.frii.com/jarvi/rxtx/license.html for the licensing detail.
\ No newline at end of file
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/trunk/lib/rxtx-2.1-7-bins-r2/README.txt (revision 197)
+++ napkit/trunk/lib/rxtx-2.1-7-bins-r2/README.txt (nonexistent)
@@ -1,3 +0,0 @@
1-*.dll are native libraries for Windows. *.jnilib is a native library for Mac OSX.
2-If you are using Linux, download RXTXlib and use the appropriate binary within it.
3-Please see http://rxtx.qbang.org/wiki/ for the detailed usage guide.
\ No newline at end of file
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/trunk/lib/connector/LICENSE.txt (revision 197)
+++ napkit/trunk/lib/connector/LICENSE.txt (nonexistent)
@@ -1,32 +0,0 @@
1-connector
2-Copyright (C) 2009 Jun KATO
3-
4-The contents of this file are subject to the Mozilla Public License Version
5-1.1 (the "License"); you may not use this file except in compliance with
6-the License. You may obtain a copy of the License at
7-http://www.mozilla.org/MPL/
8-
9-Software distributed under the License is distributed on an "AS IS" basis,
10-WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11-for the specific language governing rights and limitations under the
12-License.
13-
14-The Original Code is connector.
15-
16-The Initial Developer of the Original Code is Jun KATO.
17-Portions created by the Initial Developer are
18-Copyright (C) 2009 Jun KATO. All Rights Reserved.
19-
20-Contributor(s): Jun KATO
21-
22-Alternatively, the contents of this file may be used under the terms of
23-either of the GNU General Public License Version 2 or later (the "GPL"),
24-or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25-in which case the provisions of the GPL or the LGPL are applicable instead
26-of those above. If you wish to allow use of your version of this file only
27-under the terms of either the GPL or the LGPL, and not to allow others to
28-use your version of this file under the terms of the MPL, indicate your
29-decision by deleting the provisions above and replace them with the notice
30-and other provisions required by the GPL or the LGPL. If you do not delete
31-the provisions above, a recipient may use your version of this file under
32-the terms of any one of the MPL, the GPL or the LGPL.
\ No newline at end of file
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/trunk/lib/connector/README.txt (revision 197)
+++ napkit/trunk/lib/connector/README.txt (nonexistent)
@@ -1,25 +0,0 @@
1-connector
2-Copyright (C) 2009 Jun KATO
3-
4-version alpha
5-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6-
7-"connector" is a simple wrapper package for connecting Java VM
8-to external devices through TCP/IP, Serial and Parallel,
9-Bluetooth Serial Port Profile.
10-
11-This library is distributed under MPL 1.1/GPL 2.0/LGPL 2.1
12-triple license. Please read LICENSE.txt for the detail.
13-You can get the source code by extracting connector.jar.
14-
15-RXTXlib is used for Serial and Parallel connections. It is
16-developed at http://rxtx.qbang.org/wiki/ and distributed under
17-LGPL v 2.1 + Linking Over Controlled Interface.
18-
19-BlueCove is used for bluetooth connection. It is developed at
20-http://bluecove.org/ and distributed under Apache License,
21-Version 2.0.
22-
23-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
24-http://matereal.sourceforge.jp/
25-arc (at) digitalmuseum.jp
\ No newline at end of file
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/trunk/src.sample/BringItHereDual.java (revision 197)
+++ napkit/trunk/src.sample/BringItHereDual.java (nonexistent)
@@ -1,286 +0,0 @@
1-import java.awt.BasicStroke;
2-
3-import java.awt.AlphaComposite;
4-import java.awt.Color;
5-import java.awt.Composite;
6-import java.awt.Graphics;
7-import java.awt.Graphics2D;
8-import java.awt.Stroke;
9-import java.awt.event.MouseAdapter;
10-import java.awt.event.MouseEvent;
11-import java.util.Set;
12-import javax.swing.JFrame;
13-import javax.swing.JOptionPane;
14-
15-import jp.digitalmuseum.capture.VideoCaptureFactoryImpl;
16-import jp.digitalmuseum.mr.Matereal;
17-import jp.digitalmuseum.mr.entity.Entity;
18-import jp.digitalmuseum.mr.entity.Mini;
19-import jp.digitalmuseum.mr.entity.PhysicalBox;
20-import jp.digitalmuseum.mr.entity.PhysicalCylinder;
21-import jp.digitalmuseum.mr.entity.Robot;
22-import jp.digitalmuseum.mr.gui.DisposeOnCloseFrame;
23-import jp.digitalmuseum.mr.gui.ImageProviderPanel;
24-import jp.digitalmuseum.mr.gui.utils.EntityPainter;
25-import jp.digitalmuseum.mr.gui.utils.VectorFieldPainter;
26-import jp.digitalmuseum.mr.hakoniwa.Hakoniwa;
27-import jp.digitalmuseum.mr.hakoniwa.HakoniwaBox;
28-import jp.digitalmuseum.mr.hakoniwa.HakoniwaRobot;
29-import jp.digitalmuseum.mr.resource.WheelsController;
30-import jp.digitalmuseum.mr.service.CoordProvider;
31-import jp.digitalmuseum.mr.service.LocationProvider;
32-import jp.digitalmuseum.mr.service.MarkerDetector;
33-import jp.digitalmuseum.mr.service.Camera;
34-import jp.digitalmuseum.mr.task.Push;
35-import jp.digitalmuseum.mr.task.Task;
36-import jp.digitalmuseum.mr.task.VectorFieldTask;
37-import jp.digitalmuseum.napkit.NapDetectionResult;
38-import jp.digitalmuseum.napkit.NapMarker;
39-import jp.digitalmuseum.napkit.gui.TypicalMDCPane;
40-import jp.digitalmuseum.utils.Location;
41-import jp.digitalmuseum.utils.Position;
42-import jp.digitalmuseum.utils.ScreenPosition;
43-
44-/**
45- * Run a marker detection and show results.
46- *
47- * @author Jun KATO
48- */
49-public class BringItHereDual {
50- private final static boolean REAL = false;
51- private Robot robot;
52- private Entity[] entities;
53- private CoordProvider coordProvider;
54- private LocationProvider locationProvider;
55- private VectorFieldTask push;
56- private ScreenPosition goal = null;
57-
58- public static void main(String[] args) {
59- new BringItHereDual();
60- }
61-
62- public BringItHereDual() {
63-
64- final JFrame configFrame;
65- final MarkerDetector detector;
66- if (REAL) {
67-
68- // Run a camera.
69- // Let users select a device to capture images.
70- final String identifier = (String) JOptionPane.showInputDialog(
71- null, "Select a device to capture images.", "Device list",
72- JOptionPane.QUESTION_MESSAGE, null,
73- new VideoCaptureFactoryImpl().queryIdentifiers(), null);
74- final Camera camera;
75- if ((identifier != null) && (identifier.length() > 0)) {
76- camera = new Camera(identifier);
77- } else {
78- camera = new Camera();
79- }
80- camera.setSize(800, 600);
81- camera.setRealSize(80, 60);
82- camera.start();
83- coordProvider = camera;
84-
85- // Run a marker detector.
86- detector = new MarkerDetector();
87- detector.loadCameraParameter("calib_qcam.dat");
88- detector.start();
89- locationProvider = detector;
90-
91- // Show a configuration window.
92- configFrame = new DisposeOnCloseFrame(new TypicalMDCPane(detector));
93-
94- // Instantiate a robot.
95- robot = new Mini("Mini", "btspp://000666015818");
96-
97- // Instantiate boxes.
98- entities = new Entity[2];
99- entities[0] = new PhysicalCylinder("My cup", 3);
100- entities[1] = new PhysicalBox("My box", 10, 8);
101- detector.put(new NapMarker("markers\\4x4_35.patt", 5.5),
102- entities[0]);
103- detector.put(new NapMarker("markers\\4x4_78.patt", 5.5),
104- entities[1]);
105- detector.put(new NapMarker("markers\\4x4_907.patt", 5.5), robot);
106- }
107-
108- else {
109-
110- // Run a hakoniwa.
111- Hakoniwa hakoniwa = new Hakoniwa();
112- hakoniwa.start();
113- coordProvider = hakoniwa;
114- locationProvider = hakoniwa;
115-
116- robot = new HakoniwaRobot("Hakoniwa robot", new Location(hakoniwa
117- .getRealWidth() / 2, hakoniwa.getRealHeight() / 2,
118- -Math.PI * 3 / 4));
119- entities = new Entity[5];
120- double x = hakoniwa.getRealWidth() / 2;
121- double y = hakoniwa.getRealHeight() / 2;
122- double r = 200;
123- for (int i = 0; i < entities.length; i++) {
124- double theta = Math.PI * i / (entities.length - 1);
125- entities[i] = new HakoniwaBox("Box " + i, x + Math.cos(theta)
126- * r, y - Math.sin(theta) * r, 20 * (i + 1),
127- 15 * (i + 1), theta);
128- }
129- }
130-
131- // Show detection results in real-time.
132- final ImageProviderPanel panel = new ImageProviderPanel(coordProvider) {
133- private static final long serialVersionUID = 1L;
134- private transient final VectorFieldPainter vectorFieldPainter = new VectorFieldPainter(
135- REAL ? 0.5 : 20);
136- private transient final EntityPainter entityPainter = new EntityPainter(
137- 0.5);
138- private transient final Stroke stroke = new BasicStroke(5);
139- private transient final AlphaComposite alphaComp = AlphaComposite
140- .getInstance(AlphaComposite.SRC_OVER, .3f);
141- private transient final AlphaComposite alphaComp2 = AlphaComposite
142- .getInstance(AlphaComposite.SRC_OVER, .7f);
143-
144- @Override
145- public void paintComponent(Graphics g) {
146- super.paintComponent(g);
147- final Graphics2D g2 = (Graphics2D) g;
148- g2.translate(getOffsetX(), getOffsetY());
149-
150- final Composite comp = g2.getComposite();
151-
152- // Draw vectors.
153- g2.setComposite(alphaComp);
154- g.setColor(Color.blue);
155- vectorFieldPainter.paint(push, g2);
156- g2.setComposite(comp);
157-
158- // Draw entities.
159- g.setColor(Color.green);
160- for (Entity e : entities) {
161- entityPainter.paint(g2, e);
162- }
163- entityPainter.paint(g2, robot);
164-
165- int detected;
166- if (REAL) {
167- // Get detected results.
168- final Set<NapDetectionResult> results = detector
169- .getResults();
170- detected = results.size();
171-
172- // Draw each detected result.
173- for (final NapDetectionResult result : results) {
174-
175- // Draw corners
176- g.setColor(Color.orange);
177- detector.paint(g2, result);
178-
179- // Draw information for the square.
180- g.setColor(Color.cyan);
181- final ScreenPosition point = result.getPosition();
182- g2.drawLine(point.getX(), point.getY(),
183- point.getX() + 55, point.getY() + 43);
184- g2.drawRect(point.getX() + 55, point.getY() + 23, 200,
185- 40);
186- g2.drawString("Confidence: " + result.getConfidence(),
187- point.getX() + 64, point.getY() + 40);
188- g2.drawString("Position: " + point, point.getX() + 64,
189- point.getY() + 56);
190- }
191- }
192-
193- // Draw status.
194- g2.setComposite(alphaComp2);
195- g2.setColor(Color.black);
196- g2.fillRect(0, 0, coordProvider.getWidth(), 35);
197- g2.setComposite(comp);
198- g.drawLine(0, 35, coordProvider.getWidth(), 35);
199- g.setColor(Color.white);
200- if (goal == null) {
201- g.drawString("Click to set the destination.", 10, 30);
202- } else {
203- if (push != null && !push.isFinished()) {
204- g.drawString("Status: " + push, 10, 30);
205- } else {
206- g.drawString("Status: Stopped", 10, 30);
207- }
208- Stroke s = g2.getStroke();
209- g2.setStroke(stroke);
210- g.setColor(Color.black);
211- g.drawLine(goal.getX() - 5, goal.getY() - 5,
212- goal.getX() + 5, goal.getY() + 5);
213- g.drawLine(goal.getX() - 5, goal.getY() + 5,
214- goal.getX() + 5, goal.getY() - 5);
215- g2.setStroke(s);
216- }
217-
218- if (REAL) {
219- // Draw detected number of squares.
220- g.setColor(Color.cyan);
221- g2.drawString("detected: " + detected,
222- 10, getHeight() - 10);
223- }
224- }
225- };
226-
227- // Bring the clicked object to the location in front of the user.
228- panel.addMouseListener(new MouseAdapter() {
229- @Override
230- public void mouseReleased(MouseEvent e) {
231-
232- // Stop the previously assigned task.
233- final Task task = robot.getAssignedTask(WheelsController.class);
234- if (task != null)
235- task.stop();
236-
237- // Set the goal position.
238- final int x = e.getX(), y = e.getY();
239- if (goal == null) {
240- goal = new ScreenPosition(x, y);
241- return;
242- }
243-
244- // Push the clicked object to the goal.
245- final Entity entity = getClickedEntity(x, y);
246- if (entity != null && entity != robot) {
247- push = new Push(entity, coordProvider.screenToReal(goal));
248- if (push.assign(robot))
249- push.start();
250- }
251- }
252-
253- });
254-
255- final DisposeOnCloseFrame frame = new DisposeOnCloseFrame(panel) {
256- private static final long serialVersionUID = 1L;
257-
258- @Override
259- public void dispose() {
260- if (REAL) {
261- configFrame.dispose();
262- }
263- super.dispose();
264- Matereal.getInstance().dispose();
265- }
266- };
267- frame.setFrameSize(coordProvider.getWidth(), coordProvider.getHeight());
268- }
269-
270- /**
271- * Get clicked entity.
272- *
273- * @param x
274- * @param y
275- * @return Clicked entity
276- */
277- private Entity getClickedEntity(int x, int y) {
278- Position p = coordProvider.screenToReal(new ScreenPosition(x, y));
279- for (Entity e : Matereal.getInstance().getEntities()) {
280- if (locationProvider.contains(e, p)) {
281- return e;
282- }
283- }
284- return null;
285- }
286-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- napkit/trunk/src.sample/BringItHere.java (revision 197)
+++ napkit/trunk/src.sample/BringItHere.java (revision 198)
@@ -18,11 +18,17 @@
1818 import jp.digitalmuseum.mr.entity.Mini;
1919 import jp.digitalmuseum.mr.entity.PhysicalBox;
2020 import jp.digitalmuseum.mr.entity.PhysicalCylinder;
21+import jp.digitalmuseum.mr.entity.Robot;
2122 import jp.digitalmuseum.mr.gui.DisposeOnCloseFrame;
2223 import jp.digitalmuseum.mr.gui.ImageProviderPanel;
2324 import jp.digitalmuseum.mr.gui.utils.EntityPainter;
2425 import jp.digitalmuseum.mr.gui.utils.VectorFieldPainter;
26+import jp.digitalmuseum.mr.hakoniwa.Hakoniwa;
27+import jp.digitalmuseum.mr.hakoniwa.HakoniwaBox;
28+import jp.digitalmuseum.mr.hakoniwa.HakoniwaRobot;
2529 import jp.digitalmuseum.mr.resource.WheelsController;
30+import jp.digitalmuseum.mr.service.CoordProvider;
31+import jp.digitalmuseum.mr.service.LocationProvider;
2632 import jp.digitalmuseum.mr.service.MarkerDetector;
2733 import jp.digitalmuseum.mr.service.Camera;
2834 import jp.digitalmuseum.mr.task.Push;
@@ -31,6 +37,7 @@
3137 import jp.digitalmuseum.napkit.NapDetectionResult;
3238 import jp.digitalmuseum.napkit.NapMarker;
3339 import jp.digitalmuseum.napkit.gui.TypicalMDCPane;
40+import jp.digitalmuseum.utils.Location;
3441 import jp.digitalmuseum.utils.Position;
3542 import jp.digitalmuseum.utils.ScreenPosition;
3643
@@ -40,8 +47,11 @@
4047 * @author Jun KATO
4148 */
4249 public class BringItHere {
43- private Camera camera;
44- private MarkerDetector detector;
50+ private final static boolean REAL = false;
51+ private Robot robot;
52+ private Entity[] entities;
53+ private CoordProvider coordProvider;
54+ private LocationProvider locationProvider;
4555 private VectorFieldTask push;
4656 private ScreenPosition goal = null;
4757
@@ -51,44 +61,78 @@
5161
5262 public BringItHere() {
5363
54- // Run a camera.
55- // Let users select a device to capture images.
56- final String identifier = (String) JOptionPane.showInputDialog(null,
57- "Select a device to capture images.", "Device list",
58- JOptionPane.QUESTION_MESSAGE, null,
59- new VideoCaptureFactoryImpl().queryIdentifiers(), null);
60- if ((identifier != null) && (identifier.length() > 0)) {
61- camera = new Camera(identifier);
62- } else {
63- camera = new Camera();
64+ final JFrame configFrame;
65+ final MarkerDetector detector;
66+ if (REAL) {
67+
68+ // Run a camera.
69+ // Let users select a device to capture images.
70+ final String identifier = (String) JOptionPane.showInputDialog(
71+ null, "Select a device to capture images.", "Device list",
72+ JOptionPane.QUESTION_MESSAGE, null,
73+ new VideoCaptureFactoryImpl().queryIdentifiers(), null);
74+ final Camera camera;
75+ if ((identifier != null) && (identifier.length() > 0)) {
76+ camera = new Camera(identifier);
77+ } else {
78+ camera = new Camera();
79+ }
80+ camera.setSize(800, 600);
81+ camera.setRealSize(80, 60);
82+ camera.start();
83+ coordProvider = camera;
84+
85+ // Run a marker detector.
86+ detector = new MarkerDetector();
87+ detector.loadCameraParameter("calib_qcam.dat");
88+ detector.start();
89+ locationProvider = detector;
90+
91+ // Show a configuration window.
92+ configFrame = new DisposeOnCloseFrame(new TypicalMDCPane(detector));
93+
94+ // Instantiate a robot.
95+ robot = new Mini("Mini", "btspp://000666015818");
96+
97+ // Instantiate boxes.
98+ entities = new Entity[2];
99+ entities[0] = new PhysicalCylinder("My cup", 3);
100+ entities[1] = new PhysicalBox("My box", 10, 8);
101+ detector.put(new NapMarker("markers\\4x4_35.patt", 5.5),
102+ entities[0]);
103+ detector.put(new NapMarker("markers\\4x4_78.patt", 5.5),
104+ entities[1]);
105+ detector.put(new NapMarker("markers\\4x4_907.patt", 5.5), robot);
64106 }
65- camera.setSize(800, 600);
66- camera.setRealSize(80, 60);
67- camera.start();
68107
69- // Run a marker detector.
70- detector = new MarkerDetector();
71- detector.loadCameraParameter("calib_qcam.dat");
72- detector.start();
108+ else {
73109
74- // Show a configuration window.
75- final JFrame configFrame = new DisposeOnCloseFrame(new TypicalMDCPane(
76- detector));
110+ // Run a hakoniwa.
111+ Hakoniwa hakoniwa = new Hakoniwa();
112+ hakoniwa.start();
113+ coordProvider = hakoniwa;
114+ locationProvider = hakoniwa;
77115
78- // Instantiate a robot.
79- final Mini robot = new Mini("Mini", "btspp://000666015818");
116+ robot = new HakoniwaRobot("Hakoniwa robot", new Location(hakoniwa
117+ .getRealWidth() / 2, hakoniwa.getRealHeight() / 2,
118+ -Math.PI * 3 / 4));
119+ entities = new Entity[5];
120+ double x = hakoniwa.getRealWidth() / 2;
121+ double y = hakoniwa.getRealHeight() / 2;
122+ double r = 200;
123+ for (int i = 0; i < entities.length; i++) {
124+ double theta = Math.PI * i / (entities.length - 1);
125+ entities[i] = new HakoniwaBox("Box " + i, x + Math.cos(theta)
126+ * r, y - Math.sin(theta) * r, 20 * (i + 1),
127+ 15 * (i + 1), theta);
128+ }
129+ }
80130
81- // Instantiate boxes.
82- final Entity[] entities = new Entity[1];
83- entities[0] = new PhysicalBox("Milk chocolate", 10, 8);
84- detector.put(new NapMarker("markers\\4x4_35.patt", 5.5), entities[0]);
85- detector.put(new NapMarker("markers\\4x4_907.patt", 5.5), robot);
86-
87131 // Show detection results in real-time.
88- final ImageProviderPanel panel = new ImageProviderPanel(camera) {
132+ final ImageProviderPanel panel = new ImageProviderPanel(coordProvider) {
89133 private static final long serialVersionUID = 1L;
90134 private transient final VectorFieldPainter vectorFieldPainter = new VectorFieldPainter(
91- 5);
135+ REAL ? 0.5 : 20);
92136 private transient final EntityPainter entityPainter = new EntityPainter(
93137 0.5);
94138 private transient final Stroke stroke = new BasicStroke(5);
@@ -109,9 +153,7 @@
109153 g2.setComposite(alphaComp);
110154 g.setColor(Color.blue);
111155 vectorFieldPainter.paint(push, g2);
112- g2.setComposite(alphaComp2);
113- g2.setColor(Color.black);
114- g2.fillRect(0, 0, getWidth(), 35);
156+ g2.setComposite(comp);
115157
116158 // Draw entities.
117159 g.setColor(Color.green);
@@ -120,36 +162,45 @@
120162 }
121163 entityPainter.paint(g2, robot);
122164
123- // Get detected results.
124- final Set<NapDetectionResult> results = detector.getResults();
165+ int detected;
166+ if (REAL) {
167+ // Get detected results.
168+ final Set<NapDetectionResult> results = detector
169+ .getResults();
170+ detected = results.size();
125171
126- // Draw each detected result.
127- for (final NapDetectionResult result : results) {
172+ // Draw each detected result.
173+ for (final NapDetectionResult result : results) {
128174
129- // Draw corners
130- g.setColor(Color.orange);
131- detector.paint(g2, result);
175+ // Draw corners
176+ g.setColor(Color.orange);
177+ detector.paint(g2, result);
132178
133- // Draw information for the square.
134- g.setColor(Color.cyan);
135- final ScreenPosition point = result.getPosition();
136- g2.drawLine(point.getX(), point.getY(), point.getX() + 55,
137- point.getY() + 43);
138- g2.drawRect(point.getX() + 55, point.getY() + 23, 200, 40);
139- g2.drawString("Confidence: " + result.getConfidence(),
140- point.getX() + 64, point.getY() + 40);
141- g2.drawString("Position: " + point, point.getX() + 64,
142- point.getY() + 56);
179+ // Draw information for the square.
180+ g.setColor(Color.cyan);
181+ final ScreenPosition point = result.getPosition();
182+ g2.drawLine(point.getX(), point.getY(),
183+ point.getX() + 55, point.getY() + 43);
184+ g2.drawRect(point.getX() + 55, point.getY() + 23, 200,
185+ 40);
186+ g2.drawString("Confidence: " + result.getConfidence(),
187+ point.getX() + 64, point.getY() + 40);
188+ g2.drawString("Position: " + point, point.getX() + 64,
189+ point.getY() + 56);
190+ }
143191 }
144192
145193 // Draw status.
194+ g2.setComposite(alphaComp2);
195+ g2.setColor(Color.black);
196+ g2.fillRect(0, 0, coordProvider.getWidth(), 35);
146197 g2.setComposite(comp);
147- g.drawLine(0, 35, getWidth(), 35);
198+ g.drawLine(0, 35, coordProvider.getWidth(), 35);
148199 g.setColor(Color.white);
149200 if (goal == null) {
150201 g.drawString("Click to set the destination.", 10, 30);
151202 } else {
152- if (push != null) {
203+ if (push != null && !push.isFinished()) {
153204 g.drawString("Status: " + push, 10, 30);
154205 } else {
155206 g.drawString("Status: Stopped", 10, 30);
@@ -164,11 +215,12 @@
164215 g2.setStroke(s);
165216 }
166217
167- // Draw detected number of squares.
168- g.setColor(Color.cyan);
169- g2.drawString("detected: "
170- + (results == null ? 0 : results.size()), 10,
171- getHeight() - 10);
218+ if (REAL) {
219+ // Draw detected number of squares.
220+ g.setColor(Color.cyan);
221+ g2.drawString("detected: " + detected,
222+ 10, getHeight() - 10);
223+ }
172224 }
173225 };
174226
@@ -192,7 +244,7 @@
192244 // Push the clicked object to the goal.
193245 final Entity entity = getClickedEntity(x, y);
194246 if (entity != null && entity != robot) {
195- push = new Push(entity, camera.screenToReal(goal));
247+ push = new Push(entity, coordProvider.screenToReal(goal));
196248 if (push.assign(robot))
197249 push.start();
198250 }
@@ -205,12 +257,14 @@
205257
206258 @Override
207259 public void dispose() {
208- configFrame.dispose();
260+ if (REAL) {
261+ configFrame.dispose();
262+ }
209263 super.dispose();
210264 Matereal.getInstance().dispose();
211265 }
212266 };
213- frame.setFrameSize(camera.getWidth(), camera.getHeight());
267+ frame.setFrameSize(coordProvider.getWidth(), coordProvider.getHeight());
214268 }
215269
216270 /**
@@ -221,9 +275,9 @@
221275 * @return Clicked entity
222276 */
223277 private Entity getClickedEntity(int x, int y) {
224- Position p = camera.screenToReal(new ScreenPosition(x, y));
278+ Position p = coordProvider.screenToReal(new ScreenPosition(x, y));
225279 for (Entity e : Matereal.getInstance().getEntities()) {
226- if (detector.contains(e, p)) {
280+ if (locationProvider.contains(e, p)) {
227281 return e;
228282 }
229283 }
--- napkit/trunk/src.sample/BringItHereReal.java (nonexistent)
+++ napkit/trunk/src.sample/BringItHereReal.java (revision 198)
@@ -0,0 +1,232 @@
1+import java.awt.BasicStroke;
2+
3+import java.awt.AlphaComposite;
4+import java.awt.Color;
5+import java.awt.Composite;
6+import java.awt.Graphics;
7+import java.awt.Graphics2D;
8+import java.awt.Stroke;
9+import java.awt.event.MouseAdapter;
10+import java.awt.event.MouseEvent;
11+import java.util.Set;
12+import javax.swing.JFrame;
13+import javax.swing.JOptionPane;
14+
15+import jp.digitalmuseum.capture.VideoCaptureFactoryImpl;
16+import jp.digitalmuseum.mr.Matereal;
17+import jp.digitalmuseum.mr.entity.Entity;
18+import jp.digitalmuseum.mr.entity.Mini;
19+import jp.digitalmuseum.mr.entity.PhysicalBox;
20+import jp.digitalmuseum.mr.entity.PhysicalCylinder;
21+import jp.digitalmuseum.mr.gui.DisposeOnCloseFrame;
22+import jp.digitalmuseum.mr.gui.ImageProviderPanel;
23+import jp.digitalmuseum.mr.gui.utils.EntityPainter;
24+import jp.digitalmuseum.mr.gui.utils.VectorFieldPainter;
25+import jp.digitalmuseum.mr.resource.WheelsController;
26+import jp.digitalmuseum.mr.service.MarkerDetector;
27+import jp.digitalmuseum.mr.service.Camera;
28+import jp.digitalmuseum.mr.task.Push;
29+import jp.digitalmuseum.mr.task.Task;
30+import jp.digitalmuseum.mr.task.VectorFieldTask;
31+import jp.digitalmuseum.napkit.NapDetectionResult;
32+import jp.digitalmuseum.napkit.NapMarker;
33+import jp.digitalmuseum.napkit.gui.TypicalMDCPane;
34+import jp.digitalmuseum.utils.Position;
35+import jp.digitalmuseum.utils.ScreenPosition;
36+
37+/**
38+ * Run a marker detection and show results.
39+ *
40+ * @author Jun KATO
41+ */
42+public class BringItHereReal {
43+ private Camera camera;
44+ private MarkerDetector detector;
45+ private VectorFieldTask push;
46+ private ScreenPosition goal = null;
47+
48+ public static void main(String[] args) {
49+ new BringItHereReal();
50+ }
51+
52+ public BringItHereReal() {
53+
54+ // Run a camera.
55+ // Let users select a device to capture images.
56+ final String identifier = (String) JOptionPane.showInputDialog(null,
57+ "Select a device to capture images.", "Device list",
58+ JOptionPane.QUESTION_MESSAGE, null,
59+ new VideoCaptureFactoryImpl().queryIdentifiers(), null);
60+ if ((identifier != null) && (identifier.length() > 0)) {
61+ camera = new Camera(identifier);
62+ } else {
63+ camera = new Camera();
64+ }
65+ camera.setSize(800, 600);
66+ camera.setRealSize(80, 60);
67+ camera.start();
68+
69+ // Run a marker detector.
70+ detector = new MarkerDetector();
71+ detector.loadCameraParameter("calib_qcam.dat");
72+ detector.start();
73+
74+ // Show a configuration window.
75+ final JFrame configFrame = new DisposeOnCloseFrame(new TypicalMDCPane(
76+ detector));
77+
78+ // Instantiate a robot.
79+ final Mini robot = new Mini("Mini", "btspp://000666015818");
80+
81+ // Instantiate boxes.
82+ final Entity[] entities = new Entity[1];
83+ entities[0] = new PhysicalBox("Milk chocolate", 10, 8);
84+ detector.put(new NapMarker("markers\\4x4_35.patt", 5.5), entities[0]);
85+ detector.put(new NapMarker("markers\\4x4_907.patt", 5.5), robot);
86+
87+ // Show detection results in real-time.
88+ final ImageProviderPanel panel = new ImageProviderPanel(camera) {
89+ private static final long serialVersionUID = 1L;
90+ private transient final VectorFieldPainter vectorFieldPainter = new VectorFieldPainter(
91+ 5);
92+ private transient final EntityPainter entityPainter = new EntityPainter(
93+ 0.5);
94+ private transient final Stroke stroke = new BasicStroke(5);
95+ private transient final AlphaComposite alphaComp = AlphaComposite
96+ .getInstance(AlphaComposite.SRC_OVER, .3f);
97+ private transient final AlphaComposite alphaComp2 = AlphaComposite
98+ .getInstance(AlphaComposite.SRC_OVER, .7f);
99+
100+ @Override
101+ public void paintComponent(Graphics g) {
102+ super.paintComponent(g);
103+ final Graphics2D g2 = (Graphics2D) g;
104+ g2.translate(getOffsetX(), getOffsetY());
105+
106+ final Composite comp = g2.getComposite();
107+
108+ // Draw vectors.
109+ g2.setComposite(alphaComp);
110+ g.setColor(Color.blue);
111+ vectorFieldPainter.paint(push, g2);
112+ g2.setComposite(alphaComp2);
113+ g2.setColor(Color.black);
114+ g2.fillRect(0, 0, getWidth(), 35);
115+
116+ // Draw entities.
117+ g.setColor(Color.green);
118+ for (Entity e : entities) {
119+ entityPainter.paint(g2, e);
120+ }
121+ entityPainter.paint(g2, robot);
122+
123+ // Get detected results.
124+ final Set<NapDetectionResult> results = detector.getResults();
125+
126+ // Draw each detected result.
127+ for (final NapDetectionResult result : results) {
128+
129+ // Draw corners
130+ g.setColor(Color.orange);
131+ detector.paint(g2, result);
132+
133+ // Draw information for the square.
134+ g.setColor(Color.cyan);
135+ final ScreenPosition point = result.getPosition();
136+ g2.drawLine(point.getX(), point.getY(), point.getX() + 55,
137+ point.getY() + 43);
138+ g2.drawRect(point.getX() + 55, point.getY() + 23, 200, 40);
139+ g2.drawString("Confidence: " + result.getConfidence(),
140+ point.getX() + 64, point.getY() + 40);
141+ g2.drawString("Position: " + point, point.getX() + 64,
142+ point.getY() + 56);
143+ }
144+
145+ // Draw status.
146+ g2.setComposite(comp);
147+ g.drawLine(0, 35, getWidth(), 35);
148+ g.setColor(Color.white);
149+ if (goal == null) {
150+ g.drawString("Click to set the destination.", 10, 30);
151+ } else {
152+ if (push != null) {
153+ g.drawString("Status: " + push, 10, 30);
154+ } else {
155+ g.drawString("Status: Stopped", 10, 30);
156+ }
157+ Stroke s = g2.getStroke();
158+ g2.setStroke(stroke);
159+ g.setColor(Color.black);
160+ g.drawLine(goal.getX() - 5, goal.getY() - 5,
161+ goal.getX() + 5, goal.getY() + 5);
162+ g.drawLine(goal.getX() - 5, goal.getY() + 5,
163+ goal.getX() + 5, goal.getY() - 5);
164+ g2.setStroke(s);
165+ }
166+
167+ // Draw detected number of squares.
168+ g.setColor(Color.cyan);
169+ g2.drawString("detected: "
170+ + (results == null ? 0 : results.size()), 10,
171+ getHeight() - 10);
172+ }
173+ };
174+
175+ // Bring the clicked object to the location in front of the user.
176+ panel.addMouseListener(new MouseAdapter() {
177+ @Override
178+ public void mouseReleased(MouseEvent e) {
179+
180+ // Stop the previously assigned task.
181+ final Task task = robot.getAssignedTask(WheelsController.class);
182+ if (task != null)
183+ task.stop();
184+
185+ // Set the goal position.
186+ final int x = e.getX(), y = e.getY();
187+ if (goal == null) {
188+ goal = new ScreenPosition(x, y);
189+ return;
190+ }
191+
192+ // Push the clicked object to the goal.
193+ final Entity entity = getClickedEntity(x, y);
194+ if (entity != null && entity != robot) {
195+ push = new Push(entity, camera.screenToReal(goal));
196+ if (push.assign(robot))
197+ push.start();
198+ }
199+ }
200+
201+ });
202+
203+ final DisposeOnCloseFrame frame = new DisposeOnCloseFrame(panel) {
204+ private static final long serialVersionUID = 1L;
205+
206+ @Override
207+ public void dispose() {
208+ configFrame.dispose();
209+ super.dispose();
210+ Matereal.getInstance().dispose();
211+ }
212+ };
213+ frame.setFrameSize(camera.getWidth(), camera.getHeight());
214+ }
215+
216+ /**
217+ * Get clicked entity.
218+ *
219+ * @param x
220+ * @param y
221+ * @return Clicked entity
222+ */
223+ private Entity getClickedEntity(int x, int y) {
224+ Position p = camera.screenToReal(new ScreenPosition(x, y));
225+ for (Entity e : Matereal.getInstance().getEntities()) {
226+ if (detector.contains(e, p)) {
227+ return e;
228+ }
229+ }
230+ return null;
231+ }
232+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
--- napkit/trunk/src.sample/DetectMarker.java (nonexistent)
+++ napkit/trunk/src.sample/DetectMarker.java (revision 198)
@@ -0,0 +1,127 @@
1+
2+
3+import java.awt.BasicStroke;
4+
5+import java.awt.Color;
6+import java.awt.Graphics;
7+import java.awt.Graphics2D;
8+import java.awt.Stroke;
9+import java.util.Set;
10+import javax.swing.JFrame;
11+import javax.swing.JOptionPane;
12+
13+import jp.digitalmuseum.capture.VideoCaptureFactoryImpl;
14+import jp.digitalmuseum.mr.Matereal;
15+import jp.digitalmuseum.mr.entity.Entity;
16+import jp.digitalmuseum.mr.entity.EntityImpl;
17+import jp.digitalmuseum.mr.gui.DisposeOnCloseFrame;
18+import jp.digitalmuseum.mr.gui.ImageProviderPanel;
19+import jp.digitalmuseum.mr.service.MarkerDetector;
20+import jp.digitalmuseum.mr.service.Camera;
21+import jp.digitalmuseum.napkit.NapDetectionResult;
22+import jp.digitalmuseum.napkit.NapMarker;
23+import jp.digitalmuseum.napkit.gui.TypicalMDCPane;
24+import jp.digitalmuseum.utils.ScreenPosition;
25+
26+/**
27+ * Run a marker detection and show results.
28+ *
29+ * @author Jun KATO
30+ */
31+public class DetectMarker {
32+
33+ public static void main(String[] args) {
34+ new DetectMarker();
35+ }
36+
37+ public DetectMarker() {
38+
39+ // Run a camera.
40+ // Let users select a device to capture images.
41+ final String identifier = (String) JOptionPane.showInputDialog(null,
42+ "Select a device to capture images.", "Device list",
43+ JOptionPane.QUESTION_MESSAGE, null, new VideoCaptureFactoryImpl()
44+ .queryIdentifiers(), null);
45+ Camera camera;
46+ if ((identifier != null) && (identifier.length() > 0)) {
47+ camera = new Camera(identifier);
48+ } else {
49+ camera = new Camera();
50+ }
51+ camera.setSize(800, 600);
52+ camera.start();
53+
54+ // Run a marker detector.
55+ final MarkerDetector detector = new MarkerDetector();
56+ detector.loadCameraParameter("calib_qcam.dat");
57+ detector.start();
58+
59+ // Show a configuration window.
60+ final JFrame configFrame = new DisposeOnCloseFrame(new TypicalMDCPane(detector));
61+
62+ // Detect a marker.
63+ final NapMarker marker = new NapMarker("markers\\4x4_35.patt",120);
64+ final Entity dummy = new EntityImpl("test");
65+ detector.put(marker, dummy);
66+
67+ // Show detection results in real-time.
68+ final DisposeOnCloseFrame frame = new DisposeOnCloseFrame(
69+ new ImageProviderPanel(camera) {
70+ private static final long serialVersionUID = 1L;
71+ private transient Stroke stroke;
72+ @Override public void paintComponent(Graphics g) {
73+ super.paintComponent(g);
74+ final Graphics2D g2 = (Graphics2D) g;
75+ if (stroke == null) {
76+ stroke = new BasicStroke(5);
77+ }
78+ g2.setStroke(stroke);
79+ g2.translate(getOffsetX(), getOffsetY());
80+
81+ // Get detected results.
82+ final Set<NapDetectionResult> results = detector.getResults();
83+
84+ // Draw each detected result.
85+ for (final NapDetectionResult result : results) {
86+
87+ // Draw corners
88+ g.setColor(Color.orange);
89+ detector.paint(g2, result);
90+
91+ // Draw information for the square.
92+ g.setColor(Color.cyan);
93+ final ScreenPosition point = result.getPosition();
94+ g2.drawLine(point.getX(), point.getY(), point.getX()+55, point.getY()+43);
95+ g2.drawRect(point.getX()+55, point.getY()+23, 200, 40);
96+ drawString(g2, "Confidence: "+result.getConfidence(), point.getX()+64, point.getY()+40);
97+ drawString(g2, "Position: "+point, point.getX()+64, point.getY()+56);
98+ }
99+
100+ // Draw detected number of squares.
101+ drawString(g2, "detected: "+(results == null ? 0 : results.size()),
102+ 10, getHeight()-10);
103+ }
104+
105+ /**
106+ * Draw a string with 1px simple black border.
107+ */
108+ private void drawString(Graphics g, String s, int x, int y) {
109+ g.setColor(Color.black);
110+ g.drawString(s, x+1, y);
111+ g.drawString(s, x-1, y);
112+ g.drawString(s, x, y-1);
113+ g.drawString(s, x, y+1);
114+ g.setColor(Color.cyan);
115+ g.drawString(s, x, y);
116+ }
117+ }) {
118+ private static final long serialVersionUID = 1L;
119+ @Override public void dispose() {
120+ configFrame.dispose();
121+ super.dispose();
122+ Matereal.getInstance().dispose();
123+ }
124+ };
125+ frame.setFrameSize(camera.getWidth(), camera.getHeight());
126+ }
127+}
Show on old repository browser