preparing for matereal distribution.
@@ -1,5 +1,5 @@ | ||
1 | 1 | Webcam capture package - capture |
2 | -Copyright (C) 2009 Jun KATO | |
2 | +Copyright (C) 2010 Jun KATO | |
3 | 3 | |
4 | 4 | The contents of this file are subject to the Mozilla Public License Version |
5 | 5 | 1.1 (the "License"); you may not use this file except in compliance with |
@@ -15,7 +15,7 @@ | ||
15 | 15 | |
16 | 16 | The Initial Developer of the Original Code is Jun KATO. |
17 | 17 | Portions created by the Initial Developer are |
18 | -Copyright (C) 2009 Jun KATO. All Rights Reserved. | |
18 | +Copyright (C) 2010 Jun KATO. All Rights Reserved. | |
19 | 19 | |
20 | 20 | Contributor(s): Jun KATO |
21 | 21 |
@@ -12,13 +12,13 @@ | ||
12 | 12 | <!-- #### (2) where are the jar files located that are required for compiling |
13 | 13 | your library such as e.g. core.jar ? edit location. #### --> |
14 | 14 | |
15 | - <property name="libraryClasspath" location="../lib"/> | |
15 | + <property name="libraryClasspath" location="../lib/p5"/> | |
16 | 16 | <path id="library-classpath"> |
17 | 17 | <fileset dir="${libraryClasspath}" > |
18 | 18 | <!-- #### (3) add the jar files that are required for compiling. edit name. |
19 | 19 | for more include files. duplicate <include name="" /> #### --> |
20 | 20 | <include name="core.jar"/> |
21 | - <include name="dsj/dsj.jar"/> | |
21 | + <include name="../dsj/dsj.jar"/> | |
22 | 22 | </fileset> |
23 | 23 | </path> |
24 | 24 |
@@ -61,8 +61,8 @@ | ||
61 | 61 | |
62 | 62 | <!-- #### (14) where can the source code be found? edit value. #### --> |
63 | 63 | <property name="source:host" value="matereal" /> |
64 | - <property name="source:url" value="http://sourceforge.jp/projects/matereal/" /> | |
65 | - <property name="source:repository" value="http://sourceforge.jp/projects/matereal/svn/view/capture/trunk/?root=matereal" /> | |
64 | + <property name="source:url" value="http://mr.digitalmuseum.jp/" /> | |
65 | + <property name="source:repository" value="http://matereal.googlecode.com/svn/capture/trunk/" /> | |
66 | 66 | |
67 | 67 | |
68 | 68 |
@@ -173,32 +173,37 @@ | ||
173 | 173 | parent.die("No devices with available pins found."); |
174 | 174 | return; |
175 | 175 | } |
176 | + pin = null; | |
177 | + float fps = 30.0f; | |
178 | + float currentFps = Float.MAX_VALUE; | |
176 | 179 | for (DSPinInfo p : pins) { |
177 | - final DSMediaType[] fs = p.getFormats(); | |
178 | 180 | |
179 | - // 動作モード数が多いものが使えるピン(たぶん) | |
180 | - if (formats == null || formats.length < fs.length) { | |
181 | - pin = p; | |
182 | - formats = fs; | |
181 | + // Set the first pin as default. | |
182 | + if (pin == null) pin = p; | |
183 | + | |
184 | + // Capture YUY2 and RGB none-compressed images by default. | |
185 | + formats = p.getFormats(); | |
186 | + for (int i = 0; i < formats.length; i ++) { | |
187 | + final DSMediaType format = formats[i]; | |
188 | + if (format.getWidth() == width && | |
189 | + format.getHeight() == height && | |
190 | + (format.getSubType() == DSMediaType.VST_YUY2 || | |
191 | + format.getSubType() == DSMediaType.VST_RGB24)) { | |
192 | + if (Math.abs(fps - format.getFrameRate()) < Math.abs(fps - currentFps)) { | |
193 | + pin = p; | |
194 | + p.setPreferredFormat(i); | |
195 | + currentFps = format.getFrameRate(); | |
196 | + } | |
197 | + break; | |
198 | + } | |
183 | 199 | } |
184 | - } | |
185 | - | |
186 | - // ピンがサポートするモードのうち | |
187 | - // | |
188 | - // ・指定された解像度に合致する | |
189 | - // ・YUVあるいはRGBで画像を取得できる | |
190 | - // | |
191 | - // ものを取得し、動作モードに指定 | |
192 | - for (int i = 0; i < formats.length; i ++) { | |
193 | - final DSMediaType format = formats[i]; | |
194 | - if ((format.getSubType() == DSMediaType.VST_YUY2 || | |
195 | - format.getSubType() == DSMediaType.VST_RGB24) && | |
196 | - requestWidth == format.getWidth() && | |
197 | - requestHeight == format.getHeight()) { | |
198 | - pin.setPreferredFormat(i); | |
200 | + if (pin != null && (int) currentFps == (int) fps) { | |
199 | 201 | break; |
200 | 202 | } |
201 | 203 | } |
204 | + if (pin == null) { | |
205 | + parent.die("No suitable pin to capture was found for filter:"+dsFilter); | |
206 | + } | |
202 | 207 | |
203 | 208 | // キャプチャを始める |
204 | 209 | dsCapture = new DSCapture( |
@@ -1,4 +1,4 @@ | ||
1 | -<?xml version="1.0" encoding="Shift_JIS"?> | |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | 2 | |
3 | 3 | <project name="capture" default="jar" basedir="."> |
4 | 4 | <!-- time stamp --> |
@@ -8,55 +8,55 @@ | ||
8 | 8 | |
9 | 9 | <!-- ****Properties**** --> |
10 | 10 | <!-- Software version --> |
11 | - <property name="version" value="0.1" /> | |
11 | + <property name="capture-version" value="1.0.0" /> | |
12 | 12 | |
13 | 13 | <!-- Dependent class pathes --> |
14 | - <property name="classpath" value="lib/dsj/dsj.jar;lib/jmf/jmf.jar;lib/qtj/QTJava.zip" /> | |
14 | + <property name="capture-classpath" value="lib/dsj/dsj.jar;lib/jmf/jmf.jar;lib/qtj/QTJava.zip" /> | |
15 | 15 | |
16 | 16 | <!-- Source directory --> |
17 | - <property name="src.dir" value="src" /> | |
17 | + <property name="capture-src.dir" value="src" /> | |
18 | 18 | |
19 | 19 | <!-- Classes destination directory --> |
20 | - <property name="classes.dir" value="bin" /> | |
20 | + <property name="capture-classes.dir" value="bin" /> | |
21 | 21 | |
22 | 22 | <!-- Javadoc destination --> |
23 | - <property name="javadoc.dir" value="docs" /> | |
23 | + <property name="capture-javadoc.dir" value="docs" /> | |
24 | 24 | |
25 | 25 | <!-- jar file name --> |
26 | - <property name="jar.name" value="capture-${version}.jar" /> | |
26 | + <property name="capture-jar.name" value="capture-${capture-version}.jar" /> | |
27 | 27 | |
28 | 28 | <!-- ****Targets**** --> |
29 | 29 | <!-- jar --> |
30 | 30 | <target name="jar" depends="compile"> |
31 | - <jar jarfile="${jar.name}"> | |
32 | - <fileset dir="${classes.dir}" includes="**/*.class" /> | |
33 | - <fileset dir="${src.dir}" includes="**/*.java" /> | |
31 | + <jar jarfile="${capture-jar.name}"> | |
32 | + <fileset dir="${capture-classes.dir}" includes="**/*.class" /> | |
33 | + <fileset dir="${capture-src.dir}" includes="**/*.java" /> | |
34 | 34 | </jar> |
35 | 35 | </target> |
36 | 36 | |
37 | 37 | <!-- Compile --> |
38 | 38 | <target name="compile"> |
39 | - <mkdir dir="${classes.dir}" /> | |
40 | - <javac srcdir="${src.dir}" destdir="${classes.dir}" classpath="${classpath}" /> | |
39 | + <mkdir dir="${capture-classes.dir}" /> | |
40 | + <javac srcdir="${capture-src.dir}" destdir="${capture-classes.dir}" classpath="${capture-classpath}" /> | |
41 | 41 | </target> |
42 | 42 | |
43 | 43 | <!-- Javadoc --> |
44 | 44 | <target name="javadoc"> |
45 | - <javadoc sourcepath="${src.dir}" | |
46 | - destdir="${javadoc.dir}" | |
45 | + <javadoc sourcepath="${capture-src.dir}" | |
46 | + destdir="${capture-javadoc.dir}" | |
47 | 47 | packagenames="jp.digitalmuseum.*" |
48 | 48 | charset="UTF-8" |
49 | 49 | encoding="UTF-8" |
50 | 50 | docencoding="UTF-8" |
51 | 51 | locale="en" |
52 | - classpath="${classpath}" | |
52 | + classpath="${capture-classpath}" | |
53 | 53 | bottom="Copyright by Jun KATO (arc@dmz) at http://matereal.sourceforge.jp/" /> |
54 | 54 | </target> |
55 | 55 | |
56 | 56 | <!-- Cleaning --> |
57 | 57 | <target name="clean"> |
58 | - <delete dir="${classes.dir}" /> | |
59 | - <delete dir="${javadoc.dir}" /> | |
60 | - <delete file="${jar.name}" /> | |
58 | + <delete dir="${capture-classes.dir}" /> | |
59 | + <delete dir="${capture-javadoc.dir}" /> | |
60 | + <delete file="${capture-jar.name}" /> | |
61 | 61 | </target> |
62 | 62 | </project> |
\ No newline at end of file |
@@ -1,120 +0,0 @@ | ||
1 | -<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
2 | -<project default="create_package"> | |
3 | - | |
4 | - <property name="matereal.zip.basedir" value="matereal-full/" /> | |
5 | - <property name="matereal.zip.name" value="matereal-0.1-full.zip" /> | |
6 | - <property name="matereal.jar.name" value="${matereal.zip.basedir}matereal-0.1-full.jar" /> | |
7 | - <property name="matereal.jar.main" value="TestCamera" /> | |
8 | - | |
9 | - <property name="lib.dir" value="lib/" /> | |
10 | - | |
11 | - <property name="matereal.dir" value="matereal/" /> | |
12 | - <property name="matereal.lib" value="matereal-0.1.jar" /> | |
13 | - | |
14 | - <property name="capture.dir" value="capture/" /> | |
15 | - <property name="capture.lib" value="capture-0.1.jar" /> | |
16 | - | |
17 | - <property name="connector.dir" value="connector/" /> | |
18 | - <property name="connector.lib" value="connector-0.1.jar" /> | |
19 | - | |
20 | - <property name="napkit.dir" value="napkit/" /> | |
21 | - <property name="napkit.lib" value="napkit-0.2.jar" /> | |
22 | - | |
23 | - <property name="bluecove.dir" value="bluecove/" /> | |
24 | - <property name="bluecove.version" value="2.1.0" /> | |
25 | - <property name="bluecove.lib" value="bluecove-${bluecove.version}.jar" /> | |
26 | - <property name="bluecove" value="${bluecove.dir}${bluecove.lib}" /> | |
27 | - <property name="bluecove-without-jnilibs" value="bluecove-${bluecove.version}-without-jnilibs.jar" /> | |
28 | - | |
29 | - <property name="rxtxlib.dir" value="rxtx-2.1-7-bins-r2/" /> | |
30 | - <property name="rxtxlib.lib" value="RXTXcomm.jar" /> | |
31 | - | |
32 | - <property name="classpath" value="${bluecove-without-jnilibs} ${rxtxlib.lib}" /> | |
33 | - | |
34 | - <target name="build_napkit"> | |
35 | - <ant antfile="build.xml" target="jar" /> | |
36 | - <mkdir dir="${lib.dir}${napkit.dir}" /> | |
37 | - <copy file="${napkit.lib}" todir="${lib.dir}${napkit.dir}" /> | |
38 | - <copy file="LICENCE.txt" todir="${lib.dir}${napkit.dir}" /> | |
39 | - <copy file="README.txt" todir="${lib.dir}${napkit.dir}" /> | |
40 | - </target> | |
41 | - | |
42 | - <target name="unjar_matereals" depends="build_napkit"> | |
43 | - <mkdir dir="${lib.dir}${matereal.dir}bin" /> | |
44 | - <unjar src="${lib.dir}${matereal.dir}${matereal.lib}" dest="${lib.dir}${matereal.dir}bin" /> | |
45 | - <unjar src="${lib.dir}${capture.dir}${capture.lib}" dest="${lib.dir}${matereal.dir}bin" /> | |
46 | - <unjar src="${lib.dir}${connector.dir}${connector.lib}" dest="${lib.dir}${matereal.dir}bin" /> | |
47 | - <unjar src="${lib.dir}${napkit.dir}${napkit.lib}" dest="${lib.dir}${matereal.dir}bin" /> | |
48 | - </target> | |
49 | - | |
50 | - <target name="unjar_bluecove"> | |
51 | - <mkdir dir="${lib.dir}${bluecove.dir}bin" /> | |
52 | - <mkdir dir="${lib.dir}${bluecove.dir}native" /> | |
53 | - <unjar src="${lib.dir}${bluecove.dir}${bluecove.lib}" dest="${lib.dir}${bluecove.dir}bin"> | |
54 | - <patternset> | |
55 | - <exclude name="**/*.dll" /> | |
56 | - <exclude name="**/*.jnilib" /> | |
57 | - </patternset> | |
58 | - </unjar> | |
59 | - <unjar src="${lib.dir}${bluecove.dir}${bluecove.lib}" dest="${lib.dir}${bluecove.dir}native"> | |
60 | - <patternset> | |
61 | - <include name="**/*.dll" /> | |
62 | - <include name="**/*.jnilib" /> | |
63 | - </patternset> | |
64 | - </unjar> | |
65 | - </target> | |
66 | - | |
67 | - <target name="create_jar" depends="unjar_matereals, unjar_bluecove"> | |
68 | - <mkdir dir="${matereal.zip.basedir}" /> | |
69 | - <jar destfile="${lib.dir}${bluecove.dir}${bluecove-without-jnilibs}" basedir="${lib.dir}${bluecove.dir}bin" /> | |
70 | - <jar destfile="${matereal.jar.name}"> | |
71 | - <manifest> | |
72 | - <attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader" /> | |
73 | - <attribute name="Rsrc-Main-Class" value="${matereal.jar.main}" /> | |
74 | - <attribute name="Class-Path" value="." /> | |
75 | - <attribute name="Rsrc-Class-Path" value="./ ${classpath}" /> | |
76 | - </manifest> | |
77 | - <zipfileset src="${lib.dir}jar-in-jar-loader/jar-in-jar-loader.zip" /> | |
78 | - <fileset dir="${lib.dir}${matereal.dir}bin" excludes="sample/" /> | |
79 | - <zipfileset dir="${lib.dir}" prefix="lib"> | |
80 | - <exclude name="jar-in-jar-loader/*.zip" /> | |
81 | - | |
82 | - <exclude name="${matereal.dir}${matereal.lib}"/> | |
83 | - <exclude name="${capture.dir}${capture.lib}"/> | |
84 | - <exclude name="${connector.dir}${connector.lib}"/> | |
85 | - <exclude name="${napkit.dir}${napkit.lib}"/> | |
86 | - | |
87 | - <exclude name="${rxtxlib.dir}${rxtxlib.lib}"/> | |
88 | - <exclude name="${rxtxlib.dir}*.dll"/> | |
89 | - <exclude name="${rxtxlib.dir}*.jnilib"/> | |
90 | - <exclude name="${bluecove.dir}${bluecove.lib}"/> | |
91 | - <exclude name="${bluecove.dir}${bluecove-without-jnilibs}"/> | |
92 | - | |
93 | - <exclude name="${matereal.dir}bin/"/> | |
94 | - <exclude name="${bluecove.dir}bin/"/> | |
95 | - <exclude name="${bluecove.dir}native/"/> | |
96 | - | |
97 | - <exclude name="dsj/"/> | |
98 | - <exclude name="NyARToolkit-*/"/> | |
99 | - </zipfileset> | |
100 | - | |
101 | - <zipfileset dir="${lib.dir}${rxtxlib.dir}" includes="${rxtxlib.lib} *.dll *.jnilib" /> | |
102 | - <zipfileset dir="${lib.dir}${bluecove.dir}native" /> | |
103 | - <zipfileset dir="${lib.dir}${bluecove.dir}" includes="${bluecove-without-jnilibs}" /> | |
104 | - | |
105 | - </jar> | |
106 | - </target> | |
107 | - | |
108 | - <target name="create_package" depends="create_jar"> | |
109 | - <zip destfile="${matereal.zip.name}" basedir="${matereal.zip.basedir}" /> | |
110 | - </target> | |
111 | - | |
112 | - <target name="clean"> | |
113 | - <delete dir="${napkit.dir}" /> | |
114 | - <delete dir="${matereal.dir}bin" /> | |
115 | - <delete dir="${bluecove.dir}bin" /> | |
116 | - <delete dir="${bluecove.dir}native" /> | |
117 | - <delete file="${matereal.zip.basedir}${matereal.jar.name}" /> | |
118 | - <delete file="${matereal.zip.name}" /> | |
119 | - </target> | |
120 | -</project> | |
\ No newline at end of file |
@@ -1,17 +0,0 @@ | ||
1 | -NyARToolkit Application Toolkit - napkit | |
2 | -Copyright (C) 2009 Jun KATO | |
3 | - | |
4 | -This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. | |
5 | - | |
6 | -This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
7 | - | |
8 | -You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. | |
9 | - | |
10 | -NyARToolkit Application Toolkit - napkit | |
11 | -Copyright (C) 2009 Jun KATO | |
12 | - | |
13 | -このプログラムはフリーソフトウェアです。あなたはこれを、フリーソフトウェア財団によって発行されたGNU 一般公衆利用許諾書(バージョン3か、 それ以降のバージョンのうちどれか)が定める条件の下で再頒布または改変することができます。 | |
14 | - | |
15 | -このプログラムは有用であることを願って頒布されますが、*全くの無保証 *です。商業可能性の保証や特定目的への適合性は、言外に示されたものも 含め、全く存在しません。詳しくはGNU 一般公衆利用許諾書をご覧ください。 | |
16 | - | |
17 | -あなたはこのプログラムと共に、GNU 一般公衆利用許諾書のコピーを一部受け取っているはずです。もし受け取っていなければ、<http://www.gnu.org/licenses/> をご覧ください。 | |
\ No newline at end of file |
@@ -0,0 +1,17 @@ | ||
1 | +NyARToolkit Application Toolkit - napkit | |
2 | +Copyright (C) 2009-2010 Jun KATO | |
3 | + | |
4 | +This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. | |
5 | + | |
6 | +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
7 | + | |
8 | +You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. | |
9 | + | |
10 | +NyARToolkit Application Toolkit - napkit | |
11 | +Copyright (C) 2009-2010 Jun KATO | |
12 | + | |
13 | +このプログラムはフリーソフトウェアです。あなたはこれを、フリーソフトウェア財団によって発行されたGNU 一般公衆利用許諾書(バージョン3か、 それ以降のバージョンのうちどれか)が定める条件の下で再頒布または改変することができます。 | |
14 | + | |
15 | +このプログラムは有用であることを願って頒布されますが、*全くの無保証 *です。商業可能性の保証や特定目的への適合性は、言外に示されたものも 含め、全く存在しません。詳しくはGNU 一般公衆利用許諾書をご覧ください。 | |
16 | + | |
17 | +あなたはこのプログラムと共に、GNU 一般公衆利用許諾書のコピーを一部受け取っているはずです。もし受け取っていなければ、<http://www.gnu.org/licenses/> をご覧ください。 | |
\ No newline at end of file |
@@ -0,0 +1,2 @@ | ||
1 | +These marker patterns are generated with ARToolkit Patternmaker: | |
2 | +http://www.cs.utah.edu/gdc/projects/augmentedreality/ | |
\ No newline at end of file |
@@ -1,118 +0,0 @@ | ||
1 | -package sample; | |
2 | - | |
3 | -import java.awt.Color; | |
4 | - | |
5 | -import java.awt.Graphics; | |
6 | -import java.awt.Graphics2D; | |
7 | -import java.awt.Shape; | |
8 | -import java.awt.geom.Rectangle2D; | |
9 | -import java.util.Set; | |
10 | -import javax.swing.JFrame; | |
11 | - | |
12 | -import jp.digitalmuseum.mr.Matereal; | |
13 | -import jp.digitalmuseum.mr.entity.Entity; | |
14 | -import jp.digitalmuseum.mr.entity.EntityImpl; | |
15 | -import jp.digitalmuseum.mr.gui.DisposeOnCloseFrame; | |
16 | -import jp.digitalmuseum.mr.gui.ImageProviderPanel; | |
17 | -import jp.digitalmuseum.mr.gui.utils.EntityPainter; | |
18 | -import jp.digitalmuseum.mr.service.MarkerDetector; | |
19 | -import jp.digitalmuseum.mr.service.Camera; | |
20 | -import jp.digitalmuseum.napkit.NapDetectionResult; | |
21 | -import jp.digitalmuseum.napkit.NapMarker; | |
22 | -import jp.digitalmuseum.napkit.gui.TypicalMDCPane; | |
23 | -import jp.digitalmuseum.utils.ScreenPosition; | |
24 | -import jp.digitalmuseum.utils.ScreenRectangle; | |
25 | - | |
26 | -/** | |
27 | - * Run a marker detection and show results. | |
28 | - * | |
29 | - * @author Jun KATO | |
30 | - */ | |
31 | -public class Step2_PaintEntity { | |
32 | - | |
33 | - public static void main(String[] args) { | |
34 | - new Step2_PaintEntity(); | |
35 | - } | |
36 | - | |
37 | - public Step2_PaintEntity() { | |
38 | - | |
39 | - // Run a camera. | |
40 | - final Camera camera = new Camera(); | |
41 | - camera.start(); | |
42 | - | |
43 | - // Run a marker detector. | |
44 | - final MarkerDetector detector = new MarkerDetector(); | |
45 | - detector.loadCameraParameter("calib_qcam.dat"); | |
46 | - detector.start(); | |
47 | - | |
48 | - // Show a configuration window. | |
49 | - final JFrame configFrame = new DisposeOnCloseFrame(new TypicalMDCPane(detector)); | |
50 | - | |
51 | - // Detect a marker. | |
52 | - final NapMarker marker = new NapMarker("markers\\4x4_78.patt",45); | |
53 | - final Entity dummy = new EntityImpl("test") { | |
54 | - public void dispose() {} | |
55 | - public Shape getShape() { return new Rectangle2D.Double(-10, -10, 20, 20); } | |
56 | - }; | |
57 | - detector.put(marker, dummy); | |
58 | - | |
59 | - // Initialize a painter | |
60 | - final EntityPainter painter = new EntityPainter(); | |
61 | - | |
62 | - // Show detection results in real-time. | |
63 | - final DisposeOnCloseFrame frame = new DisposeOnCloseFrame( | |
64 | - new ImageProviderPanel(camera) { | |
65 | - private static final long serialVersionUID = 1L; | |
66 | - @Override public void paintComponent(Graphics g) { | |
67 | - super.paintComponent(g); | |
68 | - | |
69 | - // Get detected results. | |
70 | - final Set<NapDetectionResult> results = detector.getResults(); | |
71 | - | |
72 | - // Draw detected number of squares. | |
73 | - drawString(g, "detected: "+(results == null ? 0 : results.size()), | |
74 | - 10, getHeight()-10); | |
75 | - | |
76 | - // Draw each detected result. | |
77 | - for (final NapDetectionResult result : results) { | |
78 | - | |
79 | - // Draw corners | |
80 | - final ScreenRectangle corners = result.getSquare(); | |
81 | - corners.draw((Graphics2D) g, true); | |
82 | - | |
83 | - // Draw information for the square. | |
84 | - final ScreenPosition point = result.getPosition(); | |
85 | - g.drawLine(point.getX(), point.getY(), point.getX()+55, point.getY()+43); | |
86 | - g.drawRect(point.getX()+55, point.getY()+23, 200, 40); | |
87 | - drawString(g, "Confidence: "+result.getConfidence(), point.getX()+64, point.getY()+40); | |
88 | - drawString(g, "Position: "+point, point.getX()+64, point.getY()+56); | |
89 | - } | |
90 | - | |
91 | - // Paint a entity | |
92 | - painter.paint(g, dummy); | |
93 | - } | |
94 | - | |
95 | - /** | |
96 | - * Draw a string with 1px simple black border. | |
97 | - */ | |
98 | - private void drawString(Graphics g, String s, int x, int y) { | |
99 | - g.setColor(Color.black); | |
100 | - g.drawString(s, x+1, y); | |
101 | - g.drawString(s, x-1, y); | |
102 | - g.drawString(s, x, y-1); | |
103 | - g.drawString(s, x, y+1); | |
104 | - g.setColor(Color.orange); | |
105 | - g.drawString(s, x, y); | |
106 | - } | |
107 | - }) { | |
108 | - private static final long serialVersionUID = 1L; | |
109 | - @Override public void dispose() { | |
110 | - configFrame.dispose(); | |
111 | - super.dispose(); | |
112 | - Matereal.getInstance().dispose(); | |
113 | - } | |
114 | - }; | |
115 | - frame.setFrameSize(camera.getWidth(), camera.getHeight()); | |
116 | - frame.setResizable(false); | |
117 | - } | |
118 | -} |
@@ -0,0 +1,286 @@ | ||
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 BringItHere { | |
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 BringItHere(); | |
60 | + } | |
61 | + | |
62 | + public BringItHere() { | |
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 | +} |
@@ -1,3 +0,0 @@ | ||
1 | -BlueCove is licensed under Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0). The license allows linking and distributing commercial software with BlueCove. | |
2 | - | |
3 | -Please see http://bluecove.org/ for the licensing detail. | |
\ No newline at end of file |
@@ -1,36 +0,0 @@ | ||
1 | -jar-in-jar-loader.zip was generated automatically by Fat Jar Eclipse Plug-In | |
2 | -and includes One-JAR codes. | |
3 | -To get more information about Fat Jar, see http://fjep.sourceforge.net/ . | |
4 | - | |
5 | -/* | |
6 | - * One-JAR™ (http://www.simontuffs.com/one-jar). Copyright (c) 2004-2007, | |
7 | - * P. Simon Tuffs (simon@simontuffs.com). All rights reserved. | |
8 | - * | |
9 | - * Redistribution and use in source and binary forms, with or without | |
10 | - * modification, are permitted provided that the following conditions are met: | |
11 | - * | |
12 | - * Redistributions of source code must retain the above copyright notice, this | |
13 | - * list of conditions and the following disclaimer. | |
14 | - * | |
15 | - * Redistributions in binary form must reproduce the above copyright notice, | |
16 | - * this list of conditions and the following disclaimer in the documentation | |
17 | - * and/or other materials provided with the distribution. | |
18 | - * | |
19 | - * Neither the name of P. Simon Tuffs, nor the names of any contributors, | |
20 | - * nor the name One-JAR may be used to endorse or promote products derived | |
21 | - * from this software without specific prior written permission. | |
22 | - * | |
23 | - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
24 | - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
25 | - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
26 | - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
27 | - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
28 | - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
29 | - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
30 | - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
31 | - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
32 | - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
33 | - * POSSIBILITY OF SUCH DAMAGE. | |
34 | - * | |
35 | - * Including this file inside the built One-JAR file conforms with these terms. | |
36 | - */ | |
\ No newline at end of file |
@@ -1,232 +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.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 | -} |
@@ -17,18 +17,11 @@ | ||
17 | 17 | import jp.digitalmuseum.mr.entity.Entity; |
18 | 18 | import jp.digitalmuseum.mr.entity.Mini; |
19 | 19 | import jp.digitalmuseum.mr.entity.PhysicalBox; |
20 | -import jp.digitalmuseum.mr.entity.PhysicalCylinder; | |
21 | -import jp.digitalmuseum.mr.entity.Robot; | |
22 | 20 | import jp.digitalmuseum.mr.gui.DisposeOnCloseFrame; |
23 | 21 | import jp.digitalmuseum.mr.gui.ImageProviderPanel; |
24 | 22 | import jp.digitalmuseum.mr.gui.utils.EntityPainter; |
25 | 23 | 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 | 24 | import jp.digitalmuseum.mr.resource.WheelsController; |
30 | -import jp.digitalmuseum.mr.service.CoordProvider; | |
31 | -import jp.digitalmuseum.mr.service.LocationProvider; | |
32 | 25 | import jp.digitalmuseum.mr.service.MarkerDetector; |
33 | 26 | import jp.digitalmuseum.mr.service.Camera; |
34 | 27 | import jp.digitalmuseum.mr.task.Push; |
@@ -37,21 +30,18 @@ | ||
37 | 30 | import jp.digitalmuseum.napkit.NapDetectionResult; |
38 | 31 | import jp.digitalmuseum.napkit.NapMarker; |
39 | 32 | import jp.digitalmuseum.napkit.gui.TypicalMDCPane; |
40 | -import jp.digitalmuseum.utils.Location; | |
41 | 33 | import jp.digitalmuseum.utils.Position; |
42 | 34 | import jp.digitalmuseum.utils.ScreenPosition; |
43 | 35 | |
44 | 36 | /** |
45 | - * Run a marker detection and show results. | |
37 | + * Bring it here! | |
38 | + * Test of assigning a task to a robot. | |
46 | 39 | * |
47 | 40 | * @author Jun KATO |
48 | 41 | */ |
49 | 42 | public class BringItHere { |
50 | - private final static boolean REAL = false; | |
51 | - private Robot robot; | |
52 | - private Entity[] entities; | |
53 | - private CoordProvider coordProvider; | |
54 | - private LocationProvider locationProvider; | |
43 | + private Camera camera; | |
44 | + private MarkerDetector detector; | |
55 | 45 | private VectorFieldTask push; |
56 | 46 | private ScreenPosition goal = null; |
57 | 47 |
@@ -61,81 +51,48 @@ | ||
61 | 51 | |
62 | 52 | public BringItHere() { |
63 | 53 | |
64 | - final JFrame configFrame; | |
65 | - final MarkerDetector detector; | |
66 | - if (REAL) { | |
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(); | |
67 | 68 | |
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; | |
69 | + // Run a marker detector. | |
70 | + detector = new MarkerDetector(); | |
71 | + detector.loadCameraParameter("calib_qcam.dat"); | |
72 | + detector.start(); | |
84 | 73 | |
85 | - // Run a marker detector. | |
86 | - detector = new MarkerDetector(); | |
87 | - detector.loadCameraParameter("calib_qcam.dat"); | |
88 | - detector.start(); | |
89 | - locationProvider = detector; | |
74 | + // Show a configuration window. | |
75 | + final JFrame configFrame = new DisposeOnCloseFrame(new TypicalMDCPane( | |
76 | + detector)); | |
90 | 77 | |
91 | - // Show a configuration window. | |
92 | - configFrame = new DisposeOnCloseFrame(new TypicalMDCPane(detector)); | |
78 | + // Initialize a robot. | |
79 | + final Mini robot = new Mini("Mini", "btspp://000666015818"); | |
93 | 80 | |
94 | - // Instantiate a robot. | |
95 | - robot = new Mini("Mini", "btspp://000666015818"); | |
81 | + // Initialize 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); | |
96 | 86 | |
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 | 87 | // Show detection results in real-time. |
132 | - final ImageProviderPanel panel = new ImageProviderPanel(coordProvider) { | |
88 | + final ImageProviderPanel panel = new ImageProviderPanel(camera) { | |
133 | 89 | 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); | |
90 | + private transient final VectorFieldPainter vectorFieldPainter = | |
91 | + new VectorFieldPainter(5); | |
92 | + private transient final EntityPainter entityPainter = | |
93 | + new EntityPainter(0.5); | |
94 | + private transient final Stroke stroke = | |
95 | + new BasicStroke(5); | |
139 | 96 | private transient final AlphaComposite alphaComp = AlphaComposite |
140 | 97 | .getInstance(AlphaComposite.SRC_OVER, .3f); |
141 | 98 | private transient final AlphaComposite alphaComp2 = AlphaComposite |
@@ -146,7 +103,6 @@ | ||
146 | 103 | super.paintComponent(g); |
147 | 104 | final Graphics2D g2 = (Graphics2D) g; |
148 | 105 | g2.translate(getOffsetX(), getOffsetY()); |
149 | - | |
150 | 106 | final Composite comp = g2.getComposite(); |
151 | 107 | |
152 | 108 | // Draw vectors. |
@@ -153,74 +109,67 @@ | ||
153 | 109 | g2.setComposite(alphaComp); |
154 | 110 | g.setColor(Color.blue); |
155 | 111 | vectorFieldPainter.paint(push, g2); |
156 | - g2.setComposite(comp); | |
112 | + g2.setComposite(alphaComp2); | |
113 | + g2.setColor(Color.black); | |
114 | + g2.fillRect(0, 0, getWidth(), 35); | |
157 | 115 | |
158 | 116 | // Draw entities. |
159 | - g.setColor(Color.green); | |
117 | + g2.setColor(Color.green); | |
160 | 118 | for (Entity e : entities) { |
161 | 119 | entityPainter.paint(g2, e); |
162 | 120 | } |
163 | 121 | entityPainter.paint(g2, robot); |
164 | 122 | |
165 | - int detected; | |
166 | - if (REAL) { | |
167 | - // Get detected results. | |
168 | - final Set<NapDetectionResult> results = detector | |
169 | - .getResults(); | |
170 | - detected = results.size(); | |
123 | + // Get detected results. | |
124 | + final Set<NapDetectionResult> results = detector.getResults(); | |
171 | 125 | |
172 | - // Draw each detected result. | |
173 | - for (final NapDetectionResult result : results) { | |
126 | + // Draw each detected result. | |
127 | + for (final NapDetectionResult result : results) { | |
174 | 128 | |
175 | - // Draw corners | |
176 | - g.setColor(Color.orange); | |
177 | - detector.paint(g2, result); | |
129 | + // Draw corners | |
130 | + g2.setColor(Color.orange); | |
131 | + detector.paint(g2, result); | |
178 | 132 | |
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 | - } | |
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); | |
191 | 143 | } |
192 | 144 | |
193 | 145 | // Draw status. |
194 | - g2.setComposite(alphaComp2); | |
195 | - g2.setColor(Color.black); | |
196 | - g2.fillRect(0, 0, coordProvider.getWidth(), 35); | |
197 | 146 | g2.setComposite(comp); |
198 | - g.drawLine(0, 35, coordProvider.getWidth(), 35); | |
199 | - g.setColor(Color.white); | |
147 | + g2.drawLine(0, 35, getWidth(), 35); | |
148 | + g2.setColor(Color.white); | |
200 | 149 | if (goal == null) { |
201 | - g.drawString("Click to set the destination.", 10, 30); | |
150 | + g2.drawString("Click to set the destination.", 10, 30); | |
202 | 151 | } else { |
203 | - if (push != null && !push.isFinished()) { | |
204 | - g.drawString("Status: " + push, 10, 30); | |
152 | + if (push != null) { | |
153 | + g2.drawString("Status: " + push, 10, 30); | |
205 | 154 | } else { |
206 | - g.drawString("Status: Stopped", 10, 30); | |
155 | + g2.drawString("Status: Stopped", 10, 30); | |
207 | 156 | } |
208 | 157 | Stroke s = g2.getStroke(); |
209 | 158 | g2.setStroke(stroke); |
210 | - g.setColor(Color.black); | |
211 | - g.drawLine(goal.getX() - 5, goal.getY() - 5, | |
159 | + g2.setColor(Color.black); | |
160 | + g2.drawLine(goal.getX() - 5, goal.getY() - 5, | |
212 | 161 | goal.getX() + 5, goal.getY() + 5); |
213 | - g.drawLine(goal.getX() - 5, goal.getY() + 5, | |
162 | + g2.drawLine(goal.getX() - 5, goal.getY() + 5, | |
214 | 163 | goal.getX() + 5, goal.getY() - 5); |
215 | 164 | g2.setStroke(s); |
216 | 165 | } |
217 | 166 | |
218 | - if (REAL) { | |
219 | - // Draw detected number of squares. | |
220 | - g.setColor(Color.cyan); | |
221 | - g2.drawString("detected: " + detected, | |
222 | - 10, getHeight() - 10); | |
223 | - } | |
167 | + // Draw detected number of squares. | |
168 | + g2.setColor(Color.cyan); | |
169 | + g2.drawString("detected: " | |
170 | + + (results == null ? 0 : results.size()), 10, | |
171 | + getHeight() - 10); | |
172 | + g2.dispose(); | |
224 | 173 | } |
225 | 174 | }; |
226 | 175 |
@@ -244,7 +193,7 @@ | ||
244 | 193 | // Push the clicked object to the goal. |
245 | 194 | final Entity entity = getClickedEntity(x, y); |
246 | 195 | if (entity != null && entity != robot) { |
247 | - push = new Push(entity, coordProvider.screenToReal(goal)); | |
196 | + push = new Push(entity, camera.screenToReal(goal)); | |
248 | 197 | if (push.assign(robot)) |
249 | 198 | push.start(); |
250 | 199 | } |
@@ -257,14 +206,12 @@ | ||
257 | 206 | |
258 | 207 | @Override |
259 | 208 | public void dispose() { |
260 | - if (REAL) { | |
261 | - configFrame.dispose(); | |
262 | - } | |
209 | + configFrame.dispose(); | |
263 | 210 | super.dispose(); |
264 | 211 | Matereal.getInstance().dispose(); |
265 | 212 | } |
266 | 213 | }; |
267 | - frame.setFrameSize(coordProvider.getWidth(), coordProvider.getHeight()); | |
214 | + frame.setFrameSize(camera.getWidth(), camera.getHeight()); | |
268 | 215 | } |
269 | 216 | |
270 | 217 | /** |
@@ -275,9 +222,9 @@ | ||
275 | 222 | * @return Clicked entity |
276 | 223 | */ |
277 | 224 | private Entity getClickedEntity(int x, int y) { |
278 | - Position p = coordProvider.screenToReal(new ScreenPosition(x, y)); | |
225 | + Position p = camera.screenToReal(new ScreenPosition(x, y)); | |
279 | 226 | for (Entity e : Matereal.getInstance().getEntities()) { |
280 | - if (locationProvider.contains(e, p)) { | |
227 | + if (detector.contains(e, p)) { | |
281 | 228 | return e; |
282 | 229 | } |
283 | 230 | } |
@@ -0,0 +1,136 @@ | ||
1 | +import java.awt.BasicStroke; | |
2 | +import java.awt.Color; | |
3 | +import java.awt.Graphics; | |
4 | +import java.awt.Graphics2D; | |
5 | +import java.awt.Shape; | |
6 | +import java.awt.Stroke; | |
7 | +import java.awt.geom.Rectangle2D; | |
8 | +import java.util.Set; | |
9 | +import javax.swing.JFrame; | |
10 | +import javax.swing.JOptionPane; | |
11 | + | |
12 | +import jp.digitalmuseum.capture.VideoCaptureFactoryImpl; | |
13 | +import jp.digitalmuseum.mr.Matereal; | |
14 | +import jp.digitalmuseum.mr.entity.Entity; | |
15 | +import jp.digitalmuseum.mr.entity.EntityImpl; | |
16 | +import jp.digitalmuseum.mr.gui.DisposeOnCloseFrame; | |
17 | +import jp.digitalmuseum.mr.gui.ImageProviderPanel; | |
18 | +import jp.digitalmuseum.mr.gui.utils.EntityPainter; | |
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 marker detection and show its results. | |
28 | + * | |
29 | + * @author Jun KATO | |
30 | + */ | |
31 | +public class DetectMarkerAndPaintEntity { | |
32 | + | |
33 | + public static void main(String[] args) { | |
34 | + new DetectMarkerAndPaintEntity(); | |
35 | + } | |
36 | + | |
37 | + public DetectMarkerAndPaintEntity() { | |
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_150.patt", 45); | |
64 | + final Entity dummy = new EntityImpl("test") { | |
65 | + public Shape getShape() { return new Rectangle2D.Double(-10, -10, 20, 20); } | |
66 | + }; | |
67 | + detector.put(marker, dummy); | |
68 | + | |
69 | + // Initialize a painter | |
70 | + final EntityPainter painter = new EntityPainter(); | |
71 | + | |
72 | + // Show detection results in real-time. | |
73 | + final DisposeOnCloseFrame frame = new DisposeOnCloseFrame( | |
74 | + new ImageProviderPanel(camera) { | |
75 | + private static final long serialVersionUID = 1L; | |
76 | + private transient Stroke stroke; | |
77 | + @Override public void paintComponent(Graphics g) { | |
78 | + super.paintComponent(g); | |
79 | + final Graphics2D g2 = (Graphics2D) g; | |
80 | + if (stroke == null) { | |
81 | + stroke = new BasicStroke(5); | |
82 | + } | |
83 | + g2.setStroke(stroke); | |
84 | + g2.translate(getOffsetX(), getOffsetY()); | |
85 | + | |
86 | + // Get detected results. | |
87 | + final Set<NapDetectionResult> results = detector.getResults(); | |
88 | + | |
89 | + // Draw each detected result. | |
90 | + for (final NapDetectionResult result : results) { | |
91 | + | |
92 | + // Draw corners | |
93 | + g2.setColor(Color.orange); | |
94 | + detector.paint(g2, result); | |
95 | + | |
96 | + // Draw information for the square. | |
97 | + g2.setColor(Color.cyan); | |
98 | + final ScreenPosition point = result.getPosition(); | |
99 | + g2.drawLine(point.getX(), point.getY(), point.getX()+55, point.getY()+43); | |
100 | + g2.drawRect(point.getX()+55, point.getY()+23, 200, 40); | |
101 | + drawString(g2, "Confidence: "+result.getConfidence(), point.getX()+64, point.getY()+40); | |
102 | + drawString(g2, "Position: "+point, point.getX()+64, point.getY()+56); | |
103 | + } | |
104 | + | |
105 | + // Paint a entity | |
106 | + painter.paint(g2, dummy); | |
107 | + | |
108 | + // Draw detected number of squares. | |
109 | + drawString(g2, "detected: "+(results == null ? 0 : results.size()), | |
110 | + 10, getHeight()-10); | |
111 | + g2.dispose(); | |
112 | + } | |
113 | + | |
114 | + /** | |
115 | + * Draw a string with 1px simple black border. | |
116 | + */ | |
117 | + private void drawString(Graphics g, String s, int x, int y) { | |
118 | + g.setColor(Color.black); | |
119 | + g.drawString(s, x+1, y); | |
120 | + g.drawString(s, x-1, y); | |
121 | + g.drawString(s, x, y-1); | |
122 | + g.drawString(s, x, y+1); | |
123 | + g.setColor(Color.cyan); | |
124 | + g.drawString(s, x, y); | |
125 | + } | |
126 | + }) { | |
127 | + private static final long serialVersionUID = 1L; | |
128 | + @Override public void dispose() { | |
129 | + configFrame.dispose(); | |
130 | + super.dispose(); | |
131 | + Matereal.getInstance().dispose(); | |
132 | + } | |
133 | + }; | |
134 | + frame.setFrameSize(camera.getWidth(), camera.getHeight()); | |
135 | + } | |
136 | +} |
@@ -1,7 +1,4 @@ | ||
1 | - | |
2 | - | |
3 | 1 | import java.awt.BasicStroke; |
4 | - | |
5 | 2 | import java.awt.Color; |
6 | 3 | import java.awt.Graphics; |
7 | 4 | import java.awt.Graphics2D; |
@@ -20,11 +17,11 @@ | ||
20 | 17 | import jp.digitalmuseum.mr.service.Camera; |
21 | 18 | import jp.digitalmuseum.napkit.NapDetectionResult; |
22 | 19 | import jp.digitalmuseum.napkit.NapMarker; |
23 | -import jp.digitalmuseum.napkit.gui.TypicalMDCPane; | |
20 | +import jp.digitalmuseum.napkit.gui.MarkerDetectorPanel; | |
24 | 21 | import jp.digitalmuseum.utils.ScreenPosition; |
25 | 22 | |
26 | 23 | /** |
27 | - * Run a marker detection and show results. | |
24 | + * Run marker detection and show its results. | |
28 | 25 | * |
29 | 26 | * @author Jun KATO |
30 | 27 | */ |
@@ -57,11 +54,11 @@ | ||
57 | 54 | detector.start(); |
58 | 55 | |
59 | 56 | // Show a configuration window. |
60 | - final JFrame configFrame = new DisposeOnCloseFrame(new TypicalMDCPane(detector)); | |
57 | + final JFrame configFrame = new DisposeOnCloseFrame(new MarkerDetectorPanel(detector)); | |
61 | 58 | |
62 | 59 | // Detect a marker. |
63 | - final NapMarker marker = new NapMarker("markers\\4x4_35.patt",120); | |
64 | - final Entity dummy = new EntityImpl("test"); | |
60 | + final NapMarker marker = new NapMarker("markers\\4x4_150.patt", 120); | |
61 | + final Entity dummy = new EntityImpl("dummy"); | |
65 | 62 | detector.put(marker, dummy); |
66 | 63 | |
67 | 64 | // Show detection results in real-time. |
@@ -85,11 +82,11 @@ | ||
85 | 82 | for (final NapDetectionResult result : results) { |
86 | 83 | |
87 | 84 | // Draw corners |
88 | - g.setColor(Color.orange); | |
85 | + g2.setColor(Color.orange); | |
89 | 86 | detector.paint(g2, result); |
90 | 87 | |
91 | 88 | // Draw information for the square. |
92 | - g.setColor(Color.cyan); | |
89 | + g2.setColor(Color.cyan); | |
93 | 90 | final ScreenPosition point = result.getPosition(); |
94 | 91 | g2.drawLine(point.getX(), point.getY(), point.getX()+55, point.getY()+43); |
95 | 92 | g2.drawRect(point.getX()+55, point.getY()+23, 200, 40); |
@@ -100,6 +97,7 @@ | ||
100 | 97 | // Draw detected number of squares. |
101 | 98 | drawString(g2, "detected: "+(results == null ? 0 : results.size()), |
102 | 99 | 10, getHeight()-10); |
100 | + g2.dispose(); | |
103 | 101 | } |
104 | 102 | |
105 | 103 | /** |
@@ -115,7 +115,7 @@ | ||
115 | 115 | if (task != null) { |
116 | 116 | task.stop(); |
117 | 117 | } |
118 | - move = new Move(camera.screenToReal(goal)); | |
118 | + move = new Move(destination); | |
119 | 119 | if (move.assign(robot)) { |
120 | 120 | move.start(); |
121 | 121 | } |
@@ -8,17 +8,17 @@ | ||
8 | 8 | |
9 | 9 | <!-- ****Properties**** --> |
10 | 10 | <!-- Software version --> |
11 | - <property name="version" value="0.2" /> | |
12 | - <property name="version-matereal" value="0.1" /> | |
13 | - <property name="version-capture" value="0.1" /> | |
14 | - <property name="version-connector" value="0.1" /> | |
11 | + <property name="version" value="1.0.0" /> | |
12 | + <property name="version-matereal" value="1.0.0" /> | |
13 | + <property name="version-capture" value="1.0.0" /> | |
14 | + <property name="version-connector" value="1.0.0" /> | |
15 | 15 | |
16 | 16 | <!-- Dependent class pathes --> |
17 | - <property name="matereal" value="lib/matereal/matereal-${version-matereal}.jar"/> | |
18 | - <property name="matereal-utils" value="lib/matereal/matereal-utils-${version-matereal}.jar"/> | |
19 | - <property name="capture" value="lib/capture/capture-${version-capture}.jar" /> | |
20 | - <property name="connector" value="lib/connector/connector-${version-connector}.jar"/> | |
21 | - <property name="classpath" value="bin;${matereal};${capture};${connector}" /> | |
17 | + <property name="matereal" value="../matereal/dist/lib/matereal-${version-matereal}.jar"/> | |
18 | + <property name="matereal-utils" value="../matereal/dist/lib/matereal-utils-${version-matereal}.jar"/> | |
19 | + <property name="capture" value="../lib/capture/capture-${version-capture}.jar" /> | |
20 | + <property name="connector" value="../lib/connector/connector-${version-connector}.jar"/> | |
21 | + <property name="classpath" value="${matereal};${capture};${connector}" /> | |
22 | 22 | |
23 | 23 | <!-- Source directory --> |
24 | 24 | <property name="src.dir" value="src" /> |
@@ -48,8 +48,7 @@ | ||
48 | 48 | <!-- Compile --> |
49 | 49 | <target name="compile"> |
50 | 50 | <mkdir dir="${classes.dir}" /> |
51 | - <javac srcdir="${nyar.dir}" destdir="${classes.dir}" encoding="UTF-8" /> | |
52 | - <javac srcdir="${src.dir}" destdir="${classes.dir}" classpath="${classpath}" encoding="UTF-8" /> | |
51 | + <javac srcdir="${nyar.dir};${src.dir}" destdir="${classes.dir}" classpath="${classpath}" encoding="UTF-8" /> | |
53 | 52 | </target> |
54 | 53 | |
55 | 54 | <!-- Extract --> |
@@ -1,5 +1,5 @@ | ||
1 | 1 | connector |
2 | -Copyright (C) 2009 Jun KATO | |
2 | +Copyright (C) 2010 Jun KATO | |
3 | 3 | |
4 | 4 | The contents of this file are subject to the Mozilla Public License Version |
5 | 5 | 1.1 (the "License"); you may not use this file except in compliance with |
@@ -15,7 +15,7 @@ | ||
15 | 15 | |
16 | 16 | The Initial Developer of the Original Code is Jun KATO. |
17 | 17 | Portions created by the Initial Developer are |
18 | -Copyright (C) 2009 Jun KATO. All Rights Reserved. | |
18 | +Copyright (C) 2010 Jun KATO. All Rights Reserved. | |
19 | 19 | |
20 | 20 | Contributor(s): Jun KATO |
21 | 21 |
@@ -8,59 +8,59 @@ | ||
8 | 8 | |
9 | 9 | <!-- ****Properties**** --> |
10 | 10 | <!-- Software version --> |
11 | - <property name="version" value="0.1" /> | |
11 | + <property name="connector-version" value="1.0.0" /> | |
12 | 12 | |
13 | 13 | <!-- Dependent class pathes --> |
14 | - <property name="bluecove" value="lib/bluecove/bluecove-2.1.0.jar" /> | |
15 | - <property name="rxtxlib" value="lib/rxtx-2.1-7-bins-r2/RXTXcomm.jar" /> | |
16 | - <property name="classpath" value="${bluecove};${rxtxlib}" /> | |
14 | + <property name="connector-bluecove" value="lib/connector/connector-2.1.0.jar" /> | |
15 | + <property name="connector-rxtxlib" value="lib/rxtx-2.1-7-bins-r2/RXTXcomm.jar" /> | |
16 | + <property name="connector-classpath" value="${connector-bluecove};${connector-rxtxlib}" /> | |
17 | 17 | |
18 | 18 | <!-- Source directory --> |
19 | - <property name="src.dir" value="src" /> | |
19 | + <property name="connector-src.dir" value="src" /> | |
20 | 20 | |
21 | 21 | <!-- Classes destination directory --> |
22 | - <property name="classes.dir" value="bin" /> | |
22 | + <property name="connector-classes.dir" value="bin" /> | |
23 | 23 | |
24 | 24 | <!-- Javadoc destination --> |
25 | - <property name="javadoc.dir" value="docs" /> | |
25 | + <property name="connector-javadoc.dir" value="docs" /> | |
26 | 26 | |
27 | 27 | <!-- jar file name --> |
28 | - <property name="jar.name" value="connector-${version}.jar" /> | |
28 | + <property name="connector-jar.name" value="connector-${connector-version}.jar" /> | |
29 | 29 | |
30 | 30 | <!-- ****Targets**** --> |
31 | 31 | <!-- jar --> |
32 | 32 | <target name="jar" depends="compile"> |
33 | - <jar jarfile="${jar.name}"> | |
34 | - <fileset dir="${classes.dir}" includes="**/*.class" /> | |
35 | - <fileset dir="${src.dir}" includes="**/*.java **/*.properties" /> | |
33 | + <jar jarfile="${connector-jar.name}"> | |
34 | + <fileset dir="${connector-classes.dir}" includes="**/*.class" /> | |
35 | + <fileset dir="${connector-src.dir}" includes="**/*.java **/*.properties" /> | |
36 | 36 | </jar> |
37 | 37 | </target> |
38 | 38 | |
39 | 39 | <!-- Compile --> |
40 | 40 | <target name="compile"> |
41 | - <mkdir dir="${classes.dir}" /> | |
42 | - <javac srcdir="${src.dir}" destdir="${classes.dir}" | |
43 | - classpath="${classpath}" | |
41 | + <mkdir dir="${connector-classes.dir}" /> | |
42 | + <javac srcdir="${connector-src.dir}" destdir="${connector-classes.dir}" | |
43 | + classpath="${connector-classpath}" | |
44 | 44 | encoding="UTF-8" /> |
45 | 45 | </target> |
46 | 46 | |
47 | 47 | <!-- Javadoc --> |
48 | 48 | <target name="javadoc"> |
49 | - <javadoc sourcepath="${src.dir}" | |
50 | - destdir="${javadoc.dir}" | |
49 | + <javadoc sourcepath="${connector-src.dir}" | |
50 | + destdir="${connector-javadoc.dir}" | |
51 | 51 | packagenames="jp.digitalmuseum.*" |
52 | 52 | charset="UTF-8" |
53 | 53 | encoding="UTF-8" |
54 | 54 | docencoding="UTF-8" |
55 | 55 | locale="en" |
56 | - classpath="${classpath}" | |
56 | + classpath="${connector-classpath}" | |
57 | 57 | bottom="Copyright by Jun KATO (arc@dmz) at http://matereal.sourceforge.jp/" /> |
58 | 58 | </target> |
59 | 59 | |
60 | 60 | <!-- Cleaning --> |
61 | 61 | <target name="clean"> |
62 | - <delete dir="${classes.dir}" /> | |
63 | - <delete dir="${javadoc.dir}" /> | |
64 | - <delete file="${jar.name}" /> | |
62 | + <delete dir="${connector-classes.dir}" /> | |
63 | + <delete dir="${connector-javadoc.dir}" /> | |
64 | + <delete file="${connector-jar.name}" /> | |
65 | 65 | </target> |
66 | 66 | </project> |
\ No newline at end of file |