--- /dev/null
+ 234 235 240 233 240 234 240 235 240 237 240 238 240 240 240 232
+ 229 240 240 240 240 240 240 240 240 240 240 240 240 240 240 228
+ 227 240 240 240 240 240 240 240 240 240 240 240 240 240 240 239
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 236 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 234 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 236 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 231 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 229 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 225 149 240 240 186 216 225 174 240 240 240 237 238 240 240 240
+ 150 107 238 231 75 208 115 147 238 228 223 226 237 180 226 240
+ 150 62 181 213 62 187 113 169 197 72 29 237 120 50 53 207
+ 149 63 47 78 53 184 113 101 142 5 150 150 45 217 186 83
+ 121 84 220 222 58 180 121 92 128 109 237 124 155 232 161 64
+ 149 71 240 240 76 210 98 109 122 108 240 129 51 119 161 155
+ 149 186 240 240 98 219 135 152 207 191 236 227 152 77 175 209
+ 235 235 240 233 240 234 240 235 240 236 240 238 240 240 240 240
+ 229 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 227 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 236 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 234 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 236 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 232 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 229 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 225 156 240 240 186 216 225 186 240 240 240 240 240 240 240 240
+ 150 117 240 231 72 206 115 162 240 232 223 237 240 180 226 240
+ 150 74 187 213 51 184 103 168 197 78 29 237 120 50 53 216
+ 144 77 51 74 61 184 106 101 142 5 150 152 52 217 186 85
+ 117 89 219 219 65 184 121 92 128 100 236 125 156 240 170 73
+ 148 71 240 240 76 210 109 109 121 99 240 137 51 120 166 164
+ 140 186 240 240 98 220 150 156 207 192 236 230 152 77 176 212
+ 234 235 240 233 240 234 240 235 240 236 240 238 240 240 240 233
+ 229 240 240 240 240 240 240 240 240 240 240 240 240 240 240 239
+ 227 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 234 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 232 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 235 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 232 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 228 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 225 156 240 240 182 212 225 180 240 240 240 240 240 240 240 240
+ 150 116 238 228 66 205 115 151 238 236 225 240 240 180 226 240
+ 156 84 186 211 47 184 109 170 200 92 30 240 120 50 53 216
+ 147 83 51 73 50 184 106 110 148 17 151 150 45 217 186 85
+ 127 98 219 219 58 179 109 101 128 107 237 125 155 240 163 72
+ 155 86 240 240 76 201 85 108 121 95 232 137 51 118 153 155
+ 149 189 240 240 98 220 141 154 206 178 235 230 152 77 175 209
+
+ 232 228 239 240 240 240 240 240 240 240 240 207 83 64 155 209
+ 240 240 240 240 240 240 240 240 240 240 226 53 186 161 161 175
+ 240 240 240 240 240 240 240 240 240 240 180 50 217 232 119 77
+ 240 240 240 240 240 240 240 240 240 238 237 120 45 155 51 152
+ 238 240 240 240 240 240 240 240 240 237 226 237 150 124 129 227
+ 240 240 240 240 240 240 240 240 240 240 223 29 150 237 240 236
+ 237 240 240 240 240 240 240 240 240 240 228 72 5 109 108 191
+ 240 240 240 240 240 240 240 240 240 240 238 197 142 128 122 207
+ 235 240 240 240 240 240 240 240 240 174 147 169 101 92 109 152
+ 240 240 240 240 240 240 240 240 240 225 115 113 113 121 98 135
+ 234 240 240 240 240 240 240 240 240 216 208 187 184 180 210 219
+ 240 240 240 240 240 240 240 240 240 186 75 62 53 58 76 98
+ 233 240 240 240 240 240 240 240 240 240 231 213 78 222 240 240
+ 240 240 240 240 240 240 240 240 240 240 238 181 47 220 240 240
+ 235 240 240 240 240 240 240 240 240 149 107 62 63 84 71 186
+ 234 229 227 240 236 234 236 231 229 225 150 150 149 121 149 149
+ 240 240 240 240 240 240 240 240 240 240 240 216 85 73 164 212
+ 240 240 240 240 240 240 240 240 240 240 226 53 186 170 166 176
+ 240 240 240 240 240 240 240 240 240 240 180 50 217 240 120 77
+ 240 240 240 240 240 240 240 240 240 240 240 120 52 156 51 152
+ 238 240 240 240 240 240 240 240 240 240 237 237 152 125 137 230
+ 240 240 240 240 240 240 240 240 240 240 223 29 150 236 240 236
+ 236 240 240 240 240 240 240 240 240 240 232 78 5 100 99 192
+ 240 240 240 240 240 240 240 240 240 240 240 197 142 128 121 207
+ 235 240 240 240 240 240 240 240 240 186 162 168 101 92 109 156
+ 240 240 240 240 240 240 240 240 240 225 115 103 106 121 109 150
+ 234 240 240 240 240 240 240 240 240 216 206 184 184 184 210 220
+ 240 240 240 240 240 240 240 240 240 186 72 51 61 65 76 98
+ 233 240 240 240 240 240 240 240 240 240 231 213 74 219 240 240
+ 240 240 240 240 240 240 240 240 240 240 240 187 51 219 240 240
+ 235 240 240 240 240 240 240 240 240 156 117 74 77 89 71 186
+ 235 229 227 240 236 234 236 232 229 225 150 150 144 117 148 140
+ 233 239 240 240 240 240 240 240 240 240 240 216 85 72 155 209
+ 240 240 240 240 240 240 240 240 240 240 226 53 186 163 153 175
+ 240 240 240 240 240 240 240 240 240 240 180 50 217 240 118 77
+ 240 240 240 240 240 240 240 240 240 240 240 120 45 155 51 152
+ 238 240 240 240 240 240 240 240 240 240 240 240 150 125 137 230
+ 240 240 240 240 240 240 240 240 240 240 225 30 151 237 232 235
+ 236 240 240 240 240 240 240 240 240 240 236 92 17 107 95 178
+ 240 240 240 240 240 240 240 240 240 240 238 200 148 128 121 206
+ 235 240 240 240 240 240 240 240 240 180 151 170 110 101 108 154
+ 240 240 240 240 240 240 240 240 240 225 115 109 106 109 85 141
+ 234 240 240 240 240 240 240 240 240 212 205 184 184 179 201 220
+ 240 240 240 240 240 240 240 240 240 182 66 47 50 58 76 98
+ 233 240 240 240 240 240 240 240 240 240 228 211 73 219 240 240
+ 240 240 240 240 240 240 240 240 240 240 238 186 51 219 240 240
+ 235 240 240 240 240 240 240 240 240 156 116 84 83 98 86 189
+ 234 229 227 240 234 232 235 232 228 225 150 156 147 127 155 149
+
+ 209 175 77 152 227 236 191 207 152 135 219 98 240 240 186 149
+ 155 161 119 51 129 240 108 122 109 98 210 76 240 240 71 149
+ 64 161 232 155 124 237 109 128 92 121 180 58 222 220 84 121
+ 83 186 217 45 150 150 5 142 101 113 184 53 78 47 63 149
+ 207 53 50 120 237 29 72 197 169 113 187 62 213 181 62 150
+ 240 226 180 237 226 223 228 238 147 115 208 75 231 238 107 150
+ 240 240 240 238 237 240 240 240 174 225 216 186 240 240 149 225
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 229
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 231
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 236
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 234
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 236
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 239 240 240 240 240 240 240 240 240 240 240 240 240 240 240 227
+ 228 240 240 240 240 240 240 240 240 240 240 240 240 240 240 229
+ 232 240 240 240 238 240 237 240 235 240 234 240 233 240 235 234
+ 212 176 77 152 230 236 192 207 156 150 220 98 240 240 186 140
+ 164 166 120 51 137 240 99 121 109 109 210 76 240 240 71 148
+ 73 170 240 156 125 236 100 128 92 121 184 65 219 219 89 117
+ 85 186 217 52 152 150 5 142 101 106 184 61 74 51 77 144
+ 216 53 50 120 237 29 78 197 168 103 184 51 213 187 74 150
+ 240 226 180 240 237 223 232 240 162 115 206 72 231 240 117 150
+ 240 240 240 240 240 240 240 240 186 225 216 186 240 240 156 225
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 229
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 232
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 236
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 234
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 236
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 227
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 229
+ 240 240 240 240 238 240 236 240 235 240 234 240 233 240 235 235
+ 209 175 77 152 230 235 178 206 154 141 220 98 240 240 189 149
+ 155 153 118 51 137 232 95 121 108 85 201 76 240 240 86 155
+ 72 163 240 155 125 237 107 128 101 109 179 58 219 219 98 127
+ 85 186 217 45 150 151 17 148 110 106 184 50 73 51 83 147
+ 216 53 50 120 240 30 92 200 170 109 184 47 211 186 84 156
+ 240 226 180 240 240 225 236 238 151 115 205 66 228 238 116 150
+ 240 240 240 240 240 240 240 240 180 225 212 182 240 240 156 225
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 228
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 232
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 235
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 232
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 234
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 227
+ 239 240 240 240 240 240 240 240 240 240 240 240 240 240 240 229
+ 233 240 240 240 238 240 236 240 235 240 234 240 233 240 235 234
+
+ 149 149 121 149 150 150 225 229 231 236 234 236 240 227 229 234
+ 186 71 84 63 62 107 149 240 240 240 240 240 240 240 240 235
+ 240 240 220 47 181 238 240 240 240 240 240 240 240 240 240 240
+ 240 240 222 78 213 231 240 240 240 240 240 240 240 240 240 233
+ 98 76 58 53 62 75 186 240 240 240 240 240 240 240 240 240
+ 219 210 180 184 187 208 216 240 240 240 240 240 240 240 240 234
+ 135 98 121 113 113 115 225 240 240 240 240 240 240 240 240 240
+ 152 109 92 101 169 147 174 240 240 240 240 240 240 240 240 235
+ 207 122 128 142 197 238 240 240 240 240 240 240 240 240 240 240
+ 191 108 109 5 72 228 240 240 240 240 240 240 240 240 240 237
+ 236 240 237 150 29 223 240 240 240 240 240 240 240 240 240 240
+ 227 129 124 150 237 226 237 240 240 240 240 240 240 240 240 238
+ 152 51 155 45 120 237 238 240 240 240 240 240 240 240 240 240
+ 77 119 232 217 50 180 240 240 240 240 240 240 240 240 240 240
+ 175 161 161 186 53 226 240 240 240 240 240 240 240 240 240 240
+ 209 155 64 83 207 240 240 240 240 240 240 240 240 239 228 232
+ 140 148 117 144 150 150 225 229 232 236 234 236 240 227 229 235
+ 186 71 89 77 74 117 156 240 240 240 240 240 240 240 240 235
+ 240 240 219 51 187 240 240 240 240 240 240 240 240 240 240 240
+ 240 240 219 74 213 231 240 240 240 240 240 240 240 240 240 233
+ 98 76 65 61 51 72 186 240 240 240 240 240 240 240 240 240
+ 220 210 184 184 184 206 216 240 240 240 240 240 240 240 240 234
+ 150 109 121 106 103 115 225 240 240 240 240 240 240 240 240 240
+ 156 109 92 101 168 162 186 240 240 240 240 240 240 240 240 235
+ 207 121 128 142 197 240 240 240 240 240 240 240 240 240 240 240
+ 192 99 100 5 78 232 240 240 240 240 240 240 240 240 240 236
+ 236 240 236 150 29 223 240 240 240 240 240 240 240 240 240 240
+ 230 137 125 152 237 237 240 240 240 240 240 240 240 240 240 238
+ 152 51 156 52 120 240 240 240 240 240 240 240 240 240 240 240
+ 77 120 240 217 50 180 240 240 240 240 240 240 240 240 240 240
+ 176 166 170 186 53 226 240 240 240 240 240 240 240 240 240 240
+ 212 164 73 85 216 240 240 240 240 240 240 240 240 240 240 240
+ 149 155 127 147 156 150 225 228 232 235 232 234 240 227 229 234
+ 189 86 98 83 84 116 156 240 240 240 240 240 240 240 240 235
+ 240 240 219 51 186 238 240 240 240 240 240 240 240 240 240 240
+ 240 240 219 73 211 228 240 240 240 240 240 240 240 240 240 233
+ 98 76 58 50 47 66 182 240 240 240 240 240 240 240 240 240
+ 220 201 179 184 184 205 212 240 240 240 240 240 240 240 240 234
+ 141 85 109 106 109 115 225 240 240 240 240 240 240 240 240 240
+ 154 108 101 110 170 151 180 240 240 240 240 240 240 240 240 235
+ 206 121 128 148 200 238 240 240 240 240 240 240 240 240 240 240
+ 178 95 107 17 92 236 240 240 240 240 240 240 240 240 240 236
+ 235 232 237 151 30 225 240 240 240 240 240 240 240 240 240 240
+ 230 137 125 150 240 240 240 240 240 240 240 240 240 240 240 238
+ 152 51 155 45 120 240 240 240 240 240 240 240 240 240 240 240
+ 77 118 240 217 50 180 240 240 240 240 240 240 240 240 240 240
+ 175 153 163 186 53 226 240 240 240 240 240 240 240 240 240 240
+ 209 155 72 85 216 240 240 240 240 240 240 240 240 240 239 233
+
--- /dev/null
+ARToolkit Java class library NyARToolkit.\r
+Copyright (C)2008 R.Iizuka\r
+\r
+This program is free software; you can redistribute it and/or\r
+modify it under the terms of the GNU General Public License\r
+as published by the Free Software Foundation; either version 2\r
+of the License, or (at your option) any later version.\r
+\r
+This program is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+GNU General Public License for more details.\r
+\r
+You should have received a copy of the GNU General Public License\r
+along with this program; if not, write to the Free Software\r
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
+\r
+ \r
+\r
+Java版 ARToolkit クラスライブラリ NyARToolkit\r
+Copyright (C)2008 R.Iizuka\r
+\r
+このプログラムはフリーソフトウェアです。あなたはこれを、フリーソフトウェ\r
+ア財団によって発行された GNU 一般公衆利用許諾契約書(バージョン2か、希\r
+望によってはそれ以降のバージョンのうちどれか)の定める条件の下で再頒布\r
+または改変することができます。\r
+\r
+このプログラムは有用であることを願って頒布されますが、*全くの無保証* \r
+です。商業可能性の保証や特定の目的への適合性は、言外に示されたものも含\r
+め全く存在しません。詳しくはGNU 一般公衆利用許諾契約書をご覧ください。\r
+ \r
+あなたはこのプログラムと共に、GNU 一般公衆利用許諾契約書の複製物を一部\r
+受け取ったはずです。もし受け取っていなければ、フリーソフトウェア財団ま\r
+で請求してください(宛先は the Free Software Foundation, Inc., 59\r
+Temple Place, Suite 330, Boston, MA 02111-1307 USA)。
\ No newline at end of file
--- /dev/null
+準備中です。ゴメンネ\r
+\r
+Not ready.
\ No newline at end of file
--- /dev/null
+ARToolkit Java class library NyARToolkit.\r
+Copyright (C)2008 R.Iizuka\r
+\r
+version Alpha 0.5.20080329.0\r
+\r
+http://nyatla.jp/\r
+airmail(at)ebony.plala.or.jp\r
+--------------------------------------------------\r
+\r
+\r
+\r
+\r
+・NyARToolkit\r
+\r
+NyARToolkitは、nativeなコードを一切使用しない、Pure Javaのみで\r
+構成されたARToolkitクラスライブラリです。\r
+\r
+ARToolkit 2.72.0をベースに構築されています。\r
+\r
+J2SEでのみ動作を確認しました。\r
+J2MEやMIDP2.0にはそのうち対応します。\r
+\r
+\r
+\r
+\r
+・基本構成\r
+\r
++----------------------------\r
+| Application |\r
++-------+-------+-----------+\r
+|NyARJMF| NyJogl| |\r
++-------+-------+ |\r
+| JMF | JOGL |NyARToolkit|\r
++-------+-------+ |\r
+|Camera | 3D | |\r
+----------------------------+\r
+\r
+映像キャプチャにはJMFを使用し、3D描画にはJoglを使用しています。\r
+NyARJMFとNyJoglは、これらのエクステンションをApplicationやNyARToolKit\r
+から使いやすくするためのラッパーです。\r
+\r
+これらとNyARToolkitは完全に分離していますので、入力・出力ともに容易に\r
+差し替えが出来ると思います。\r
+\r
+\r
+\r
+\r
+・サンプルなど\r
+\r
+動作させる前に、JMFとJOGLをインストールしてください。\r
+動作確認したバージョンと入手先はこちらです。\r
+\r
+JMF JavaTM Media Framework 2.1.1e\r
+http://java.sun.com/products/java-media/jmf/index.jsp\r
+\r
+jogl-1.1.1-pre-20080328-windows-i586.zip\r
+https://jogl.dev.java.net/\r
+\r
+\r
+サンプルは以下のディレクトリにあります。\r
+\r
+./src\r
+NyARToolkitのEclipseプロジェクトがあります。\r
+jp.nyatla.nyartoolkit.sampleパッケージに、Rawイメージから\r
+変換行列を求めるサンプルがあります。\r
+\r
+./sample\r
+NyARToolkitのアプリケーションサンプルEclipseプロジェクトがあります。\r
+NyARJMFにはビデオキャプチャの試験プログラムと、マーカー検出プログラムがあります。\r
+NyARJOGLにはARToolkitのsimpleLite相当のサンプルがあります。\r
+\r
+NyARJMFのプロジェクトはNyARToolKitに依存し、NyARJOGLのプロジェクトはNyARToolKit\r
+とNyARJMFに依存しています。\r
+zipを展開すると多分参照関係が壊れてますので、再設定してください。\r
+\r
+\r
+\r
+\r
+・NyARToolkitとオリジナルの差分\r
+\r
+オリジナルと演算結果に互換性がありますが、関数構成を再設計した\r
+ため、関数名や関数コールの手順の互換性がほとんどありません。\r
+\r
+クラスは関数機能毎にまとめた作りになっていますので、オリジナルの\r
+コード読んだことがあれば、なんとなく判ると思います。\r
+\r
+\r
+\r
+\r
+・足りない機能等\r
+\r
+マーカーのセーブ機能と、複数マーカーの認識機能が未実装です。\r
+\r
+今後実装していきます。\r
+\r
+\r
+\r
+\r
+・ライセンス\r
+GPLです。詳しくはLICENCE.txtをみてください。\r
+\r
+\r
+\r
+\r
+・お願い\r
+\r
+NyARToolkitを使って面白いものが出来たら、是非教えてください。\r
+\r
+それと強制では有りませんが、NyARToolkitを使った感想などを\r
+送ってくれると、今後の励みになります。\r
+\r
+\r
+\r
+\r
+ではでは、楽しく遊んでくださいネ。\r
+\r
+2008.03.29 R.Iizuka@nyatla.jp\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+ <classpathentry path="" kind="src"/>\r
+ <classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>\r
+ <classpathentry path="C:/Program Files/JMF2.1.1e/lib/jmf.jar" kind="lib"/>\r
+ <classpathentry path="/NyARToolkit" combineaccessrules="false" kind="src"/>\r
+ <classpathentry path="" kind="output"/>\r
+</classpath>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+ <name>NyARJMF</name>\r
+ <comment></comment>\r
+ <projects>\r
+ </projects>\r
+ <buildSpec>\r
+ <buildCommand>\r
+ <name>org.eclipse.jdt.core.javabuilder</name>\r
+ <arguments>\r
+ </arguments>\r
+ </buildCommand>\r
+ </buildSpec>\r
+ <natures>\r
+ <nature>org.eclipse.jdt.core.javanature</nature>\r
+ </natures>\r
+</projectDescription>\r
--- /dev/null
+/**
+ * VFMキャプチャテストプログラム
+ * (c)2008 R.iizuka
+ * airmail@ebony.plala.or.jp
+ * http://nyatla.jp/
+ */
+import javax.media.*;
+
+import javax.media.util.BufferToImage;
+import javax.media.format.*;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.jmf.*;
+import java.awt.*;
+
+
+
+public class JmfCaptureTest extends Frame implements JmfCaptureListener{
+ public JmfCaptureTest() throws NyARException
+ {
+ setTitle("JmfCaptureTest");
+ setBounds(0,0,320+64,240+64);
+ capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXCEL_FORMAT_RGB);
+ capture.setCaptureListener(this);
+ }
+
+
+
+ private JmfCameraCapture capture;
+ public void onUpdateBuffer(Buffer i_buffer)
+ {
+ BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());
+ Image img=b2i.createImage(i_buffer);
+ Graphics g = getGraphics();
+ g.drawImage(img, 32, 32,this);
+ }
+ private void startCapture()
+ {
+ try{
+ capture.start();
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+ public static void main(String[] args) {
+ try{
+ JmfCaptureTest mainwin = new JmfCaptureTest();
+ mainwin.setVisible(true);
+ mainwin.startCapture();
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ }
+
+}
--- /dev/null
+/**
+ * VFM+ARToolkitテストプログラム
+ * カメラから取り込んだデータからマーカーを検出して、一致度と変換行列を表示します。
+ * (c)2008 R.iizuka
+ * airmail(at)ebony.plala.or.jp
+ * http://nyatla.jp/
+ */
+import javax.media.*;
+
+import javax.media.util.BufferToImage;
+import javax.media.format.*;
+
+import jp.nyatla.nyartoolkit.NyARException;
+import jp.nyatla.nyartoolkit.jmf.*;
+
+import java.awt.*;
+
+import jp.nyatla.nyartoolkit.core.*;
+import jp.nyatla.nyartoolkit.detector.*;
+import jp.nyatla.nyartoolkit.core.raster.*;
+
+
+
+
+
+public class NyarToolkitLinkTest extends Frame implements JmfCaptureListener
+{
+ private final String CARCODE_FILE ="../../Data/patt.hiro";
+ private final String PARAM_FILE ="../../Data/camera_para.dat";
+ private JmfCameraCapture capture;
+ NyARSingleDetectMarker nya;
+
+ public NyarToolkitLinkTest() throws NyARException,NyARException
+ {
+ setTitle("JmfCaptureTest");
+ setBounds(0,0,320+64,240+64);
+ //キャプチャの準備
+ capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXCEL_FORMAT_RGB);
+ capture.setCaptureListener(this);
+
+ //NyARToolkitの準備
+ NyARParam ar_param=new NyARParam();
+ NyARCode ar_code =new NyARCode(16,16);
+ ar_param.loadFromARFile(PARAM_FILE);
+ ar_param.changeSize(320,240);
+ nya=new NyARSingleDetectMarker(ar_param,ar_code,80.0);
+ ar_code.LoadFromARFile(CARCODE_FILE);
+ }
+
+
+
+ public void onUpdateBuffer(Buffer i_buffer)
+ {
+ try{
+ //キャプチャしたイメージを加工
+ BufferToImage b2i=new BufferToImage((VideoFormat)i_buffer.getFormat());
+ Image img=b2i.createImage(i_buffer);
+ Graphics g = getGraphics();
+ NyARRaster_RGB ra=NyARRaster_RGB.wrap((byte[])i_buffer.getData(), 320, 240);
+ //i_buffer.
+ boolean is_marker_exist=nya.detectMarkerLite(ra,100);
+
+ double[][] atm=null;
+ if(is_marker_exist){
+ //変換行列を取得
+ atm=nya.getTransmationMatrix().getArray();
+ }
+ //情報を画面に書く
+ g.drawImage(img, 32, 32,this);
+ if(is_marker_exist){
+ g.drawString("マーカー検出:"+nya.getConfidence(),32,50);
+ for(int i=0;i<3;i++){
+ for(int i2=0;i2<4;i2++){
+ g.drawString("["+i+"]["+i2+"]"+atm[i][i2],32,50+(1+i2*3+i)*16);
+ }
+
+ }
+ }else{
+ g.drawString("マーカー未検出:",32,100);
+ }
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+
+
+
+ }
+ private void startCapture()
+ {
+ try{
+ capture.start();
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+ public static void main(String[] args) {
+ try{
+ NyarToolkitLinkTest mainwin = new NyarToolkitLinkTest();
+ mainwin.setVisible(true);
+ mainwin.startCapture();
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+
+ }
+
+}
--- /dev/null
+/**\r
+ * JMFお手軽キャプチャクラス\r
+ * (c)2008 R.Iizuka\r
+ * airmail@ebony.plala.or.jp\r
+ * http://nyatla.jp/\r
+ */\r
+package jp.nyatla.nyartoolkit.jmf;\r
+\r
+\r
+\r
+import javax.media.*;\r
+import javax.media.protocol.*;\r
+import javax.media.control.*;\r
+import javax.media.format.*;\r
+import java.awt.*;\r
+import java.util.*;\r
+import javax.media.protocol.DataSource;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+\r
+\r
+\r
+\r
+\r
+public class JmfCameraCapture\r
+{\r
+ private JmfCaptureListener capture_listener;\r
+ private DataSource jmf_data_source;\r
+ private MonitorStream jmf_monitor_stream;\r
+ private Processor jmf_processor;\r
+ private VideoFormat jmf_video_format;\r
+ \r
+ private Buffer read_buf=new Buffer();\r
+ public static final String PIXCEL_FORMAT_RGB="RGB";\r
+ public JmfCameraCapture(int i_width,int i_height,float i_rate,String i_pixcel_format)\r
+ {\r
+ String encoding = i_pixcel_format;//comboEncoding.getSelectedItem();\r
+ Dimension size = new Dimension(i_width,i_height);\r
+ jmf_video_format = new VideoFormat(encoding, size, Format.NOT_SPECIFIED,null,i_rate);\r
+ }\r
+ public javax.media.Buffer readBuffer() throws NyARException\r
+ {\r
+ if(jmf_monitor_stream==null){\r
+ throw new NyARException();\r
+ }\r
+ try{\r
+ jmf_monitor_stream.read(read_buf);\r
+ }catch(Exception e){\r
+ throw new NyARException(e);\r
+ }\r
+ return read_buf;\r
+ }\r
+ public void setCaptureListener(JmfCaptureListener i_listener) throws NyARException\r
+ {\r
+ if(jmf_processor!=null){\r
+ throw new NyARException();\r
+ }\r
+ capture_listener=i_listener;\r
+ \r
+ }\r
+ public void start() throws NyARException\r
+ {\r
+ \r
+ DataSource ds=getCaptureDS(jmf_video_format);\r
+ VideoFormat[] formats=new VideoFormat[]{new VideoFormat(null)};\r
+ ProcessorModel pm = new ProcessorModel(ds,formats,null);//, formats, ftd);\r
+ Processor processor;\r
+ try {\r
+ processor = Manager.createRealizedProcessor(pm);\r
+ } catch (Exception e){\r
+ // Make sure the capture devices are released\r
+ ds.disconnect();\r
+ throw new NyARException(e);\r
+ }\r
+ // Get the monitor control:\r
+ // Since there are more than one MonitorControl objects\r
+ // exported by the DataSource, we get the specific one\r
+ // that is also the MonitorStream object.\r
+ jmf_monitor_stream=(MonitorStream)ds.getControl("jmfsample.MonitorStream");\r
+ jmf_monitor_stream.setCaptureListener(capture_listener);\r
+ jmf_data_source=ds;\r
+ jmf_processor=processor;\r
+ jmf_processor.start();\r
+ }\r
+ public void stop()\r
+ {\r
+ jmf_processor.stop();\r
+ jmf_processor.close();\r
+ jmf_processor = null;\r
+ \r
+ }\r
+ protected void finalize()\r
+ {\r
+ if(jmf_processor!=null){\r
+ jmf_processor.stop();\r
+ jmf_processor.close();\r
+ jmf_processor = null;\r
+ }\r
+ }\r
+ private static DataSource getCaptureDS(VideoFormat vf) {\r
+ DataSource dsVideo = null;\r
+ DataSource ds = null;\r
+\r
+ // Create a capture DataSource for the video\r
+ // If there is no video capture device, then exit with null\r
+ if (vf != null) {\r
+ dsVideo = createDataSource(vf);\r
+ if (dsVideo == null)\r
+ return null;\r
+ }\r
+\r
+\r
+ // Create the monitoring datasource wrapper\r
+ if (dsVideo != null) {\r
+ dsVideo = new MonitorCDS(dsVideo);\r
+ return dsVideo;\r
+ }\r
+\r
+ // Merge the data sources, if both audio and video are available\r
+ try {\r
+ ds = Manager.createMergingDataSource(new DataSource[]{dsVideo});\r
+ } catch (IncompatibleSourceException ise){\r
+ return null;\r
+ }\r
+\r
+ return ds;\r
+ }\r
+\r
+ private static DataSource createDataSource(Format format) {\r
+ DataSource ds;\r
+ Vector devices;\r
+ CaptureDeviceInfo cdi;\r
+ MediaLocator ml;\r
+\r
+ // Find devices for format\r
+ devices = CaptureDeviceManager.getDeviceList(format);\r
+ if (devices.size() < 1) {\r
+ System.err.println("! No Devices for " + format);\r
+ return null;\r
+ }\r
+ // Pick the first device\r
+ cdi = (CaptureDeviceInfo) devices.elementAt(0);\r
+\r
+ ml = cdi.getLocator();\r
+\r
+ try {\r
+ ds = Manager.createDataSource(ml);\r
+ ds.connect();\r
+ if (ds instanceof CaptureDevice)\r
+ {\r
+ setCaptureFormat((CaptureDevice) ds, format);\r
+ }\r
+ } catch (Exception e) {\r
+ System.err.println(e);\r
+ return null;\r
+ }\r
+ return ds;\r
+ }\r
+\r
+ private static void setCaptureFormat(CaptureDevice cdev, Format format) {\r
+ FormatControl [] fcs = cdev.getFormatControls();\r
+ if (fcs.length < 1){\r
+ return;\r
+ }\r
+ FormatControl fc = fcs[0];\r
+ Format [] formats = fc.getSupportedFormats();\r
+ for (int i = 0; i < formats.length; i++) {\r
+ if (formats[i].matches(format)){\r
+ format = formats[i].intersects(format);\r
+ fc.setFormat(format);\r
+ break;\r
+ }\r
+ }\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/**\r
+ * JMFお手軽キャプチャ用リスナ\r
+ * (c)2008 R.Iizuka\r
+ * airmail@ebony.plala.or.jp\r
+ * http://nyatla.jp/\r
+ */\r
+package jp.nyatla.nyartoolkit.jmf;\r
+\r
+import javax.media.Buffer;\r
+\r
+public interface JmfCaptureListener{\r
+ public void onUpdateBuffer(Buffer i_buffer);\r
+ \r
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
+ * modify and redistribute this software in source and binary code form,
+ * provided that i) this copyright notice and license appear on all copies of
+ * the software; and ii) Licensee does not utilize the software in a manner
+ * which is disparaging to Sun.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
+ * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
+ * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
+ * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
+ * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
+ * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
+ * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
+ * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * This software is not designed or intended for use in on-line control of
+ * aircraft, air traffic, aircraft navigation or aircraft communications; or in
+ * the design, construction, operation or maintenance of any nuclear
+ * facility. Licensee represents and warrants that it will not use or
+ * redistribute the Software for such purposes.
+ */
+package jp.nyatla.nyartoolkit.jmf;
+
+
+import javax.media.*;
+import javax.media.protocol.*;
+import javax.media.control.*;
+
+import java.io.IOException;
+
+
+
+public class MonitorCDS extends PushBufferDataSource{
+
+ private PushBufferDataSource delegate = null;
+ private PushBufferStream [] delStreams = null;
+ private MonitorStream monitorStream = null;
+ private PushBufferStream [] monitorStreams = null;
+ boolean delStarted = false; // variable used by MonitorStream also
+ private Control [] controls;
+
+ public MonitorCDS(DataSource ds)
+ {
+ // Get the stream from the actual datasource
+ // and create a MonitorStream from it
+ // Export the MonitorControl interface of the MonitorStream
+ if (ds instanceof PushBufferDataSource)
+ {
+ delegate = (PushBufferDataSource) ds;
+ delStreams = delegate.getStreams();
+ monitorStream = new MonitorStream(delStreams[0], this);
+ monitorStreams = new PushBufferStream[] {monitorStream};
+ }
+ }
+
+ public Object [] getControls()
+ {
+ return controls;
+ }
+
+ public Object getControl(String value) {
+ if (value.equals("jmfsample.MonitorStream") || value.equals("javax.media.control.MonitorControl"))
+ return monitorStream;
+ else
+ return null;
+ }
+
+ public javax.media.CaptureDeviceInfo getCaptureDeviceInfo()
+ {
+ return ((CaptureDevice)delegate).getCaptureDeviceInfo();
+ }
+
+ public FormatControl[] getFormatControls()
+ {
+ return ((CaptureDevice)delegate).getFormatControls();
+ }
+
+ public String getContentType()
+ {
+ return delegate.getContentType();
+ }
+
+ public void connect() throws IOException
+ {
+ if (delegate == null)
+ throw new IOException("Incompatible DataSource");
+ // Delegate is already connected
+ }
+
+ public void disconnect()
+ {
+ monitorStream.setEnabled(false);
+ delegate.disconnect();
+ }
+
+ public synchronized void start() throws IOException
+ {
+ startDelegate();
+ delStarted = true;
+ }
+
+ public synchronized void stop() throws IOException
+ {
+ if (!monitorStream.isEnabled()) {
+ stopDelegate();
+ }
+ delStarted = false;
+ }
+
+ public Time getDuration()
+ {
+ return delegate.getDuration();
+ }
+
+ public PushBufferStream [] getStreams()
+ {
+ return monitorStreams;
+ }
+
+ void startDelegate() throws IOException
+ {
+ delegate.start();
+ }
+
+ void stopDelegate() throws IOException
+ {
+ delegate.stop();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 1996-2001 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
+ * modify and redistribute this software in source and binary code form,
+ * provided that i) this copyright notice and license appear on all copies of
+ * the software; and ii) Licensee does not utilize the software in a manner
+ * which is disparaging to Sun.
+ *
+ * This software is provided "AS IS," without a warranty of any kind. ALL
+ * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
+ * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
+ * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
+ * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
+ * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
+ * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
+ * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
+ * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ *
+ * This software is not designed or intended for use in on-line control of
+ * aircraft, air traffic, aircraft navigation or aircraft communications; or in
+ * the design, construction, operation or maintenance of any nuclear
+ * facility. Licensee represents and warrants that it will not use or
+ * redistribute the Software for such purposes.
+ */
+package jp.nyatla.nyartoolkit.jmf;
+
+
+
+import javax.media.*;
+import javax.media.protocol.*;
+
+import javax.media.util.BufferToImage;
+import java.io.IOException;
+import java.awt.*;
+
+public class MonitorStream implements PushBufferStream, BufferTransferHandler {
+
+ JmfCaptureListener img_listener;
+ PushBufferStream actual = null;
+ boolean dataAvailable = false;
+ boolean terminate = false;
+ boolean enabled = false;
+ Object bufferLock = new Object();
+ Buffer cbuffer = new Buffer();
+ BufferTransferHandler transferHandler = null;
+ Component component = null;
+ MonitorCDS cds;
+ BufferToImage bti = null;
+
+ MonitorStream(PushBufferStream actual, MonitorCDS cds) {
+ this.actual = actual;
+ actual.setTransferHandler(this);
+ this.cds = cds;
+ }
+
+ public javax.media.Format getFormat()
+ {
+ return actual.getFormat();
+ }
+ /**
+ * 非同期READ
+ */
+ public void read(Buffer buffer) throws IOException
+ {
+ // Wait for data to be available
+ // Doesn't get used much because the transferData
+ // call is made when data IS available. And most
+ // Processors/Players read the data in the same
+ // thread that called transferData, although that's
+ // not a safe assumption to make
+ if (!dataAvailable) {
+ synchronized (bufferLock) {
+ while (!dataAvailable && !terminate) {
+ try {
+ bufferLock.wait(100);
+ } catch (InterruptedException ie) {
+ }
+ }
+ }
+ }
+
+ if (dataAvailable) {
+ synchronized (bufferLock) {
+ // Copy the buffer attributes, but swap the data
+ // attributes so that no extra copy is made.
+ buffer.copy(cbuffer, true);
+ //dataAvailable = false;
+ }
+ }
+// return;
+ }
+ public void setCaptureListener(JmfCaptureListener i_listener)
+ {
+ img_listener=i_listener;
+ }
+
+ public void transferData(PushBufferStream pbs)
+ {
+ // Get the data from the original source stream
+ synchronized (bufferLock) {
+ try {
+ pbs.read(cbuffer);
+ } catch (IOException ioe) {
+ return;
+ }
+ dataAvailable = true;
+ bufferLock.notifyAll();
+ }
+ if(img_listener!=null){
+ img_listener.onUpdateBuffer(cbuffer);
+ }
+
+/*
+ // Display data if monitor is active
+ if (isEnabled()) {
+ if (bti == null) {
+ VideoFormat vf = (VideoFormat) cbuffer.getFormat();
+ bti = new BufferToImage(vf);
+ }
+ if (bti != null && component != null) {
+ Image im = bti.createImage(cbuffer);
+ Graphics g = component.getGraphics();
+ Dimension size = component.getSize();
+ if (g != null)
+ g.drawImage(im, 0, 0, component);
+ }
+ }
+*/
+ // Maybe synchronize this with setTransferHandler() ?
+ if (transferHandler != null && cds.delStarted)
+ transferHandler.transferData(this);
+ }
+
+ public void setTransferHandler(BufferTransferHandler transferHandler) {
+ this.transferHandler = transferHandler;
+ }
+
+ public boolean setEnabled(boolean value) {
+ enabled = value;
+ if (value == false) {
+ if (!cds.delStarted) {
+ try {
+ cds.stopDelegate();
+ } catch (IOException ioe) {
+ }
+ }
+ } else {
+ // Start the capture datasource if the monitor is enabled
+ try {
+ cds.startDelegate();
+ }catch (IOException ioe) {
+ }
+ }
+ return enabled;
+ }
+
+ public boolean isEnabled()
+ {
+ return enabled;
+ }
+
+
+
+ public float setPreviewFrameRate(float rate)
+ {
+ System.err.println("TODO");
+ return rate;
+ }
+
+ public ContentDescriptor getContentDescriptor()
+ {
+ return actual.getContentDescriptor();
+ }
+
+ public long getContentLength()
+ {
+ return actual.getContentLength();
+ }
+
+ public boolean endOfStream() {
+ return actual.endOfStream();
+ }
+
+ public Object [] getControls() {
+ return new Object[0];
+ }
+
+ public Object getControl(String str) {
+ return null;
+ }
+
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+ <classpathentry path="" kind="src"/>\r
+ <classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>\r
+ <classpathentry path="C:/Program Files/JMF2.1.1e/lib/jmf.jar" kind="lib"/>\r
+ <classpathentry path="C:/Program Files/Java/jogl/lib/gluegen-rt.jar" kind="lib"/>\r
+ <classpathentry path="C:/Program Files/Java/jogl/lib/jogl.jar" kind="lib"/>\r
+ <classpathentry path="/NyARJMF" combineaccessrules="false" kind="src"/>\r
+ <classpathentry path="/NyARToolkit" combineaccessrules="false" kind="src"/>\r
+ <classpathentry path="" kind="output"/>\r
+</classpath>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+ <name>NyARJOGL</name>\r
+ <comment></comment>\r
+ <projects>\r
+ </projects>\r
+ <buildSpec>\r
+ <buildCommand>\r
+ <name>org.eclipse.jdt.core.javabuilder</name>\r
+ <arguments>\r
+ </arguments>\r
+ </buildCommand>\r
+ </buildSpec>\r
+ <natures>\r
+ <nature>org.eclipse.jdt.core.javanature</nature>\r
+ </natures>\r
+</projectDescription>\r
--- /dev/null
+/**\r
+ * simpleLiteと同じようなテストプログラム\r
+ * マーカーの一致度の最低値をチェックするところを抜いたので、同じマーカーを大量に\r
+ * 検出すると面白いことになります。\r
+ * (c)2008 R.iizuka\r
+ * airmail(at)ebony.plala.or.jp\r
+ * http://nyatla.jp/\r
+ */\r
+import java.awt.event.WindowAdapter;\r
+import java.awt.event.WindowEvent;\r
+import java.awt.*;\r
+\r
+import javax.media.Buffer;\r
+\r
+import javax.media.opengl.GL;\r
+import javax.media.opengl.GLAutoDrawable;\r
+import javax.media.opengl.GLEventListener;\r
+import javax.media.opengl.GLCanvas;\r
+\r
+import com.sun.opengl.util.Animator;\r
+\r
+import jp.nyatla.nyartoolkit.core.NyARCode;\r
+\r
+import jp.nyatla.nyartoolkit.jmf.JmfCameraCapture;\r
+import jp.nyatla.nyartoolkit.jmf.JmfCaptureListener;\r
+import jp.nyatla.nyartoolkit.gutil.*;\r
+\r
+\r
+public class JavaSimpleLite implements GLEventListener,JmfCaptureListener\r
+{\r
+ private final String CARCODE_FILE ="../../Data/patt.hiro";\r
+ private final String PARAM_FILE ="../../Data/camera_para.dat";\r
+ \r
+ \r
+ private Animator animator;\r
+ private GLNyARRaster_RGB cap_image;\r
+ \r
+ private JmfCameraCapture capture;\r
+ private GL gl;\r
+ //NyARToolkit関係\r
+ private GLNyARSingleDetectMarker nya;\r
+ private GLNyARParam ar_param;\r
+ /**\r
+ * 立方体を書く\r
+ *\r
+ */\r
+ void drawCube()\r
+ {\r
+ // Colour cube data.\r
+ int polyList = 0;\r
+ float fSize = 0.5f;\r
+ int f, i; \r
+ float[][] cube_vertices=new float[][]{\r
+ {1.0f, 1.0f, 1.0f}, {1.0f, -1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {-1.0f, 1.0f, 1.0f},\r
+ {1.0f, 1.0f, -1.0f}, {1.0f, -1.0f, -1.0f}, {-1.0f, -1.0f, -1.0f}, {-1.0f, 1.0f, -1.0f}\r
+ };\r
+ float[][] cube_vertex_colors=new float[][]{\r
+ {1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 1.0f, 1.0f},\r
+ {1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}\r
+ };\r
+ int cube_num_faces = 6;\r
+ short[][] cube_faces =new short[][]{\r
+ {3, 2, 1, 0}, {2, 3, 7, 6}, {0, 1, 5, 4}, {3, 0, 4, 7}, {1, 2, 6, 5}, {4, 5, 6, 7}\r
+ };\r
+ \r
+ if (polyList==0) {\r
+ polyList = gl.glGenLists (1);\r
+ gl.glNewList(polyList, GL.GL_COMPILE);\r
+ gl.glBegin(GL.GL_QUADS);\r
+ for (f = 0; f < cube_num_faces; f++)\r
+ for (i = 0; i < 4; i++) {\r
+ gl.glColor3f (cube_vertex_colors[cube_faces[f][i]][0], cube_vertex_colors[cube_faces[f][i]][1], cube_vertex_colors[cube_faces[f][i]][2]);\r
+ gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);\r
+ }\r
+ gl.glEnd();\r
+ gl.glColor3f(0.0f, 0.0f, 0.0f);\r
+ for (f = 0; f < cube_num_faces; f++) {\r
+ gl.glBegin (GL.GL_LINE_LOOP);\r
+ for (i = 0; i < 4; i++)\r
+ gl.glVertex3f(cube_vertices[cube_faces[f][i]][0] * fSize, cube_vertices[cube_faces[f][i]][1] * fSize, cube_vertices[cube_faces[f][i]][2] * fSize);\r
+ gl.glEnd ();\r
+ }\r
+ gl.glEndList ();\r
+ }\r
+ \r
+ gl.glPushMatrix(); // Save world coordinate system.\r
+ gl.glTranslatef(0.0f, 0.0f, 0.5f); // Place base of cube on marker surface.\r
+ gl.glRotatef(0.0f, 0.0f, 0.0f, 1.0f); // Rotate about z axis.\r
+ gl.glDisable(GL.GL_LIGHTING); // Just use colours.\r
+ gl.glCallList(polyList); // Draw the cube.\r
+ gl.glPopMatrix(); // Restore world coordinate system.\r
+ \r
+ }\r
+ \r
+ \r
+ \r
+ public JavaSimpleLite()\r
+ {\r
+ Frame frame = new Frame("Java simpleLite with NyARToolkit");\r
+\r
+\r
+ // 3Dを描画するコンポーネント\r
+ GLCanvas canvas = new GLCanvas();\r
+ frame.add(canvas);\r
+ canvas.addGLEventListener(this);\r
+ frame.addWindowListener(new WindowAdapter() {\r
+ public void windowClosing(WindowEvent e) {\r
+ System.exit(0);\r
+ }\r
+ });\r
+\r
+ frame.setVisible(true);\r
+ Insets ins=frame.getInsets();\r
+ frame.setSize(320+ins.left+ins.right,240+ins.top+ins.bottom);\r
+ canvas.setBounds(ins.left,ins.top,320,240);\r
+ }\r
+\r
+ public void init(GLAutoDrawable drawable) {\r
+ gl = drawable.getGL();\r
+ gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);\r
+ //NyARToolkitの準備\r
+ try{\r
+ //キャプチャの準備\r
+ capture=new JmfCameraCapture(320,240,30f,JmfCameraCapture.PIXCEL_FORMAT_RGB);\r
+ capture.setCaptureListener(this);\r
+ capture.start();\r
+ //NyARToolkitの準備\r
+ ar_param=new GLNyARParam();\r
+ NyARCode ar_code =new NyARCode(16,16);\r
+ ar_param.loadFromARFile(PARAM_FILE);\r
+ ar_param.changeSize(320,240);\r
+ nya=new GLNyARSingleDetectMarker(ar_param,ar_code,80.0);\r
+ ar_code.LoadFromARFile(CARCODE_FILE);\r
+ //GL対応のRGBラスタオブジェクト\r
+ cap_image=new GLNyARRaster_RGB(gl,ar_param,320,240);\r
+\r
+ }catch(Exception e){\r
+ e.printStackTrace();\r
+ }\r
+ animator = new Animator(drawable);\r
+\r
+ animator.start();\r
+\r
+ }\r
+\r
+ public void reshape(GLAutoDrawable drawable,\r
+ int x, int y,\r
+ int width, int height)\r
+ {\r
+ float ratio = (float)height / (float)width;\r
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);\r
+ gl.glViewport(0, 0, width, height);\r
+\r
+ //視体積の設定\r
+ gl.glMatrixMode(GL.GL_PROJECTION);\r
+ gl.glLoadIdentity();\r
+ gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,\r
+ 5.0f, 40.0f);\r
+ //見る位置\r
+ gl.glMatrixMode(GL.GL_MODELVIEW);\r
+ gl.glLoadIdentity();\r
+ gl.glTranslatef(0.0f, 0.0f, -10.0f);\r
+ }\r
+\r
+ public void display(GLAutoDrawable drawable)\r
+ {\r
+ \r
+ try{\r
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear the buffers for new frame.\r
+ \r
+ \r
+ //キャプチャしたイメージを加工\r
+ Buffer b=capture.readBuffer();\r
+ //BufferToImage b2i=new BufferToImage((VideoFormat)b.getFormat());\r
+ if(b.getData()==null){\r
+ return;\r
+ }else{\r
+ //画像準備OK\r
+ }\r
+ //画像チェックしてマーカー探して、背景を書く\r
+ boolean is_marker_exist;\r
+ synchronized(cap_image){\r
+ is_marker_exist=nya.detectMarkerLite(cap_image,100);\r
+ //背景を書く\r
+ cap_image.glDispImage(1.0);\r
+ }\r
+ //あったら立方体を書く\r
+ if(is_marker_exist){\r
+ // Projection transformation.\r
+ gl.glMatrixMode(GL.GL_PROJECTION);\r
+ gl.glLoadMatrixd(ar_param.getCameraFrustumRH(),0);\r
+ gl.glMatrixMode(GL.GL_MODELVIEW);\r
+ // Viewing transformation.\r
+ gl.glLoadIdentity();\r
+ gl.glLoadMatrixd(nya.getCameraViewRH(),0);\r
+\r
+ \r
+ // All other lighting and geometry goes here.\r
+ drawCube();\r
+ }\r
+ }catch(Exception e){\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ public void onUpdateBuffer(Buffer i_buffer)\r
+ {\r
+ try{\r
+ synchronized(cap_image){\r
+ cap_image.setRawData((byte[])i_buffer.getData(), true);\r
+ }\r
+ }catch(Exception e){\r
+ e.printStackTrace();\r
+ } \r
+ }\r
+\r
+ public void displayChanged(GLAutoDrawable drawable,\r
+ boolean modeChanged,\r
+ boolean deviceChanged) {}\r
+\r
+ public static void main(String[] args) {\r
+ new JavaSimpleLite();\r
+ }\r
+}\r
+\r
--- /dev/null
+/**\r
+ * NyARParamにOpenGL向け関数を追加したもの\r
+ * (c)2008 R.iizuka\r
+ * airmail(at)ebony.plala.or.jp\r
+ * http://nyatla.jp/\r
+ */\r
+package jp.nyatla.nyartoolkit.gutil;\r
+\r
+import jp.nyatla.nyartoolkit.core.*;\r
+public class GLNyARParam extends NyARParam\r
+{\r
+ private double view_distance_min=0.1;//#define VIEW_DISTANCE_MIN 0.1 // Objects closer to the camera than this will not be displayed.\r
+ private double view_distance_max=100.0;//#define VIEW_DISTANCE_MAX 100.0 // Objects further away from the camera than this will not be displayed.\r
+ private double[] m_projection=null;\r
+ public void setViewDistanceMin(double i_new_value)\r
+ {\r
+ m_projection=null;//キャッシュ済変数初期化\r
+ view_distance_min=i_new_value;\r
+ }\r
+ public void setViewDistanceMax(double i_new_value)\r
+ {\r
+ m_projection=null;//キャッシュ済変数初期化\r
+ view_distance_max=i_new_value;\r
+ }\r
+ /**\r
+ * void arglCameraFrustumRH(const ARParam *cparam, const double focalmin, const double focalmax, GLdouble m_projection[16])\r
+ * 関数の置き換え\r
+ * @param focalmin\r
+ * @param focalmax\r
+ * @return\r
+ */\r
+ public double[] getCameraFrustumRH()\r
+ {\r
+ //既に値がキャッシュされていたらそれを使う\r
+ if(m_projection!=null){\r
+ return m_projection;\r
+ }\r
+ //無ければ計算\r
+ m_projection=new double[16];\r
+ NyARMat trans_mat=new NyARMat(3,4);\r
+ NyARMat icpara_mat=new NyARMat(3,4);\r
+ double[][] p=new double[3][3], q=new double[4][4];\r
+ int width, height;\r
+ int i, j;\r
+ \r
+ width = xsize;\r
+ height = ysize;\r
+ \r
+ decompMat(icpara_mat,trans_mat);\r
+\r
+ double[][] icpara=icpara_mat.getArray();\r
+ double[][] trans=trans_mat.getArray();\r
+ for (i = 0; i < 4; i++) {\r
+ icpara[1][i] = (height - 1)*(icpara[2][i]) - icpara[1][i];\r
+ }\r
+ \r
+ for(i = 0; i < 3; i++) {\r
+ for(j = 0; j < 3; j++) {\r
+ p[i][j] = icpara[i][j] / icpara[2][2];\r
+ }\r
+ }\r
+ q[0][0] = (2.0 * p[0][0] / (width - 1));\r
+ q[0][1] = (2.0 * p[0][1] / (width - 1));\r
+ q[0][2] = -((2.0 * p[0][2] / (width - 1)) - 1.0);\r
+ q[0][3] = 0.0;\r
+ \r
+ q[1][0] = 0.0;\r
+ q[1][1] = -(2.0 * p[1][1] / (height - 1));\r
+ q[1][2] = -((2.0 * p[1][2] / (height - 1)) - 1.0);\r
+ q[1][3] = 0.0;\r
+ \r
+ q[2][0] = 0.0;\r
+ q[2][1] = 0.0;\r
+ q[2][2] = (view_distance_max + view_distance_min)/(view_distance_min - view_distance_max);\r
+ q[2][3] = 2.0 * view_distance_max * view_distance_min / (view_distance_min - view_distance_max);\r
+ \r
+ q[3][0] = 0.0;\r
+ q[3][1] = 0.0;\r
+ q[3][2] = -1.0;\r
+ q[3][3] = 0.0;\r
+ \r
+ for (i = 0; i < 4; i++) { // Row.\r
+ // First 3 columns of the current row.\r
+ for (j = 0; j < 3; j++) { // Column.\r
+ m_projection[i + j*4] =\r
+ q[i][0] * trans[0][j] +\r
+ q[i][1] * trans[1][j] +\r
+ q[i][2] * trans[2][j];\r
+ }\r
+ // Fourth column of the current row.\r
+ m_projection[i + 3*4]=\r
+ q[i][0] * trans[0][3] +\r
+ q[i][1] * trans[1][3] +\r
+ q[i][2] * trans[2][3] +\r
+ q[i][3];\r
+ }\r
+ return m_projection;\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * NyARRaster_RGBにOpenGL向け関数を追加したもの\r
+ * (c)2008 R.iizuka\r
+ * airmail(at)ebony.plala.or.jp\r
+ * http://nyatla.jp/\r
+ */\r
+package jp.nyatla.nyartoolkit.gutil;\r
+\r
+import java.nio.ByteBuffer;\r
+import java.nio.IntBuffer;\r
+\r
+import javax.media.opengl.GL;\r
+import javax.media.opengl.glu.GLU;\r
+\r
+import jp.nyatla.nyartoolkit.core.NyARParam;\r
+import jp.nyatla.nyartoolkit.core.raster.NyARRaster_RGB;\r
+\r
+public class GLNyARRaster_RGB extends NyARRaster_RGB\r
+{\r
+ private NyARParam cparam;\r
+ private GL ref_gl;\r
+ private GLU glu;\r
+ public GLNyARRaster_RGB(GL i_ref_gl,NyARParam i_cparam,int i_width,int i_height)\r
+ {\r
+ width=i_width;\r
+ height=i_height;\r
+ cparam=i_cparam;\r
+ ref_gl=i_ref_gl;\r
+ glu=new GLU();\r
+ this.ref_buf=new byte[i_width*i_height*3];\r
+ }\r
+ public void setRawData(byte[] i_buf,boolean i_is_reverse)\r
+ {\r
+ if(i_is_reverse){\r
+ int length=width*3;\r
+ int src_idx=0;\r
+ int dest_idx=(height-1)*length;\r
+ for(int i=0;i<height;i++){\r
+ System.arraycopy(i_buf,src_idx,ref_buf,dest_idx,length);\r
+ src_idx+=length;\r
+ dest_idx-=length;\r
+ }\r
+ }else{\r
+ System.arraycopy(i_buf,0,ref_buf,0,this.ref_buf.length);\r
+ }\r
+ }\r
+ /**\r
+ * 保持してるイメージをGLに出力する。\r
+ * @param image\r
+ * @param zoom\r
+ */\r
+ public void glDispImage(double zoom)\r
+ {\r
+ IntBuffer texEnvModeSave=IntBuffer.allocate(1); \r
+ boolean lightingSave;\r
+ boolean depthTestSave;\r
+\r
+ // Prepare an orthographic projection, set camera position for 2D drawing, and save GL state.\r
+ ref_gl.glGetTexEnviv(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, texEnvModeSave); // Save GL texture environment mode.\r
+ if (texEnvModeSave.array()[0] != GL.GL_REPLACE){\r
+ ref_gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);\r
+ }\r
+ lightingSave = ref_gl.glIsEnabled(GL.GL_LIGHTING); // Save enabled state of lighting.\r
+ if (lightingSave == true){\r
+ ref_gl.glDisable(GL.GL_LIGHTING);\r
+ }\r
+ depthTestSave = ref_gl.glIsEnabled(GL.GL_DEPTH_TEST); // Save enabled state of depth test.\r
+ if (depthTestSave == true){\r
+ ref_gl.glDisable(GL.GL_DEPTH_TEST);\r
+ }\r
+ ref_gl.glMatrixMode(GL.GL_PROJECTION);\r
+ ref_gl.glPushMatrix();\r
+ ref_gl.glLoadIdentity();\r
+ glu.gluOrtho2D(0.0,0.0,cparam.getX(),cparam.getY());\r
+ ref_gl.glMatrixMode(GL.GL_MODELVIEW);\r
+ ref_gl.glPushMatrix();\r
+ ref_gl.glLoadIdentity();\r
+ ref_gl.glRotatef(0.0f,0.0f,180f,0f);\r
+ arglDispImageStateful(zoom);\r
+\r
+\r
+ // Restore previous projection, camera position, and GL state.\r
+ ref_gl.glMatrixMode(GL.GL_PROJECTION);\r
+ ref_gl.glPopMatrix();\r
+ ref_gl.glMatrixMode(GL.GL_MODELVIEW);\r
+ ref_gl.glPopMatrix();\r
+ if (depthTestSave){\r
+ ref_gl.glEnable(GL.GL_DEPTH_TEST); // Restore enabled state of depth test.\r
+ }\r
+ if (lightingSave){\r
+ ref_gl.glEnable(GL.GL_LIGHTING); // Restore enabled state of lighting.\r
+ }\r
+ if (texEnvModeSave.get(0) != GL.GL_REPLACE){\r
+ ref_gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, texEnvModeSave.get(0)); // Restore GL texture environment mode.\r
+ }\r
+ ref_gl.glEnd();\r
+ }\r
+ /**\r
+ * arglDispImageStateful関数モドキ\r
+ * @param image\r
+ * @param zoom\r
+ */\r
+ private void arglDispImageStateful(double zoom)\r
+ {\r
+ float zoomf;\r
+ IntBuffer params=IntBuffer.allocate(4);\r
+ int xsize=cparam.getX();\r
+ int ysize=cparam.getY();\r
+ zoomf = (float)zoom;\r
+ ref_gl.glDisable(GL.GL_TEXTURE_2D);\r
+ ref_gl.glGetIntegerv(GL.GL_VIEWPORT,params);\r
+ ref_gl.glPixelZoom(zoomf * ((float)(params.get(2)) / (float)xsize),-zoomf * ((float)(params.get(3)) / (float)ysize));\r
+ ref_gl.glRasterPos2i(-1,1);\r
+ ref_gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);\r
+ ByteBuffer buf=ByteBuffer.wrap(ref_buf);\r
+ ref_gl.glDrawPixels(xsize,ysize,GL.GL_BGR,GL.GL_UNSIGNED_BYTE,buf);\r
+ } \r
+}\r
--- /dev/null
+/**\r
+ * NyARSingleDetectMarkerにOpenGL向け関数を追加したもの\r
+ * (c)2008 R.iizuka\r
+ * airmail(at)ebony.plala.or.jp\r
+ * http://nyatla.jp/\r
+ */\r
+package jp.nyatla.nyartoolkit.gutil;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.NyARCode;\r
+import jp.nyatla.nyartoolkit.core.NyARMat;\r
+import jp.nyatla.nyartoolkit.core.NyARParam;\r
+import jp.nyatla.nyartoolkit.detector.*;\r
+\r
+public class GLNyARSingleDetectMarker extends NyARSingleDetectMarker\r
+{\r
+ private double view_scale_factor=0.025;//#define VIEW_SCALEFACTOR 0.025 // 1.0 ARToolKit unit becomes 0.025 of my OpenGL units.\r
+ public GLNyARSingleDetectMarker(NyARParam i_param,NyARCode i_code,double i_marker_width)\r
+ {\r
+ super(i_param,i_code,i_marker_width); \r
+ }\r
+ public void setScaleFactor(double i_new_value)\r
+ {\r
+ view_scale_factor=i_new_value;\r
+ }\r
+ // public static void arglCameraViewRH(const double para[3][4], GLdouble m_modelview[16], const double scale)\r
+ public double[] getCameraViewRH() throws NyARException\r
+ {\r
+ //座標を計算\r
+ NyARMat mat=getTransmationMatrix();\r
+ //行列変換\r
+ double[][] para=mat.getArray();\r
+ double[] result=new double[16];\r
+ result[0 + 0*4] = para[0][0]; // R1C1\r
+ result[0 + 1*4] = para[0][1]; // R1C2\r
+ result[0 + 2*4] = para[0][2];\r
+ result[0 + 3*4] = para[0][3];\r
+ result[1 + 0*4] = -para[1][0]; // R2\r
+ result[1 + 1*4] = -para[1][1];\r
+ result[1 + 2*4] = -para[1][2];\r
+ result[1 + 3*4] = -para[1][3];\r
+ result[2 + 0*4] = -para[2][0]; // R3\r
+ result[2 + 1*4] = -para[2][1];\r
+ result[2 + 2*4] = -para[2][2];\r
+ result[2 + 3*4] = -para[2][3];\r
+ result[3 + 0*4] = 0.0;\r
+ result[3 + 1*4] = 0.0;\r
+ result[3 + 2*4] = 0.0;\r
+ result[3 + 3*4] = 1.0;\r
+ if (view_scale_factor != 0.0) {\r
+ result[12] *= view_scale_factor;\r
+ result[13] *= view_scale_factor;\r
+ result[14] *= view_scale_factor;\r
+ }\r
+ return result;\r
+ }\r
+}\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+ <classpathentry kind="src" path=""/>\r
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>\r
+ <classpathentry kind="output" path=""/>\r
+</classpath>\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+ <name>NyARToolKit</name>\r
+ <comment></comment>\r
+ <projects>\r
+ </projects>\r
+ <buildSpec>\r
+ <buildCommand>\r
+ <name>org.eclipse.jdt.core.javabuilder</name>\r
+ <arguments>\r
+ </arguments>\r
+ </buildCommand>\r
+ </buildSpec>\r
+ <natures>\r
+ <nature>org.eclipse.jdt.core.javanature</nature>\r
+ </natures>\r
+</projectDescription>\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit;\r
+\r
+public class NyARException extends Exception {\r
+ private static final long serialVersionUID = 1L;\r
+ public NyARException(){\r
+ super();\r
+ }\r
+ public NyARException(Exception e){\r
+ super(e);\r
+ }\r
+ public NyARException(String m){\r
+ super(m);\r
+ }\r
+ public static void trap(String m) throws NyARException\r
+ {\r
+ throw new NyARException("トラップ:"+m);\r
+ }\r
+}\r
--- /dev/null
+package jp.nyatla.nyartoolkit.base;\r
+\r
+public class Config {\r
+ //Version系情報\r
+// public static final int AR_HEADER_VERSION_MAJOR=2; //#define AR_HEADER_VERSION_MAJOR 2\r
+// public static final int AR_HEADER_VERSION_MINOR=72;//#define AR_HEADER_VERSION_MINOR 72\r
+//\r
+// public static final int AR_HEADER_VERSION_TINY=0;//#define AR_HEADER_VERSION_TINY 0\r
+//\r
+// public static final int AR_HEADER_VERSION_BUILD=0;//#define AR_HEADER_VERSION_BUILD 0\r
+// \r
+// public static final String AR_HEADER_VERSION_STRING="2.72.0";//#define AR_HEADER_VERSION_STRING "2.72.0"\r
+//\r
+// public static final boolean AR_HAVE_HEADER_VERSION_2=true;//#define AR_HAVE_HEADER_VERSION_2\r
+// public static final boolean AR_HAVE_HEADER_VERSION_2_72=true;//#define AR_HAVE_HEADER_VERSION_2_72\r
+\r
+\r
+ /*ビデオ入力系?*/\r
+ /*------------------------------------------------------------*/\r
+\r
+// public static final int AR_DRAW_BY_GL_DRAW_PIXELS =0;//#define AR_DRAW_BY_GL_DRAW_PIXELS 0\r
+// public static final int AR_DRAW_BY_TEXTURE_MAPPING=1;//#define AR_DRAW_BY_TEXTURE_MAPPING 1\r
+// public static final int AR_DRAW_TEXTURE_FULL_IMAGE=0;//#define AR_DRAW_TEXTURE_FULL_IMAGE 0\r
+// public static final int AR_DRAW_TEXTURE_HALF_IMAGE=1;//#define AR_DRAW_TEXTURE_HALF_IMAGE 1\r
+// public static final int AR_IMAGE_PROC_IN_FULL=0;//#define AR_IMAGE_PROC_IN_FULL 0\r
+// public static final int AR_IMAGE_PROC_IN_HALF=1;//#define AR_IMAGE_PROC_IN_HALF 1\r
+// public static final int AR_FITTING_TO_IDEAL=0;//#define AR_FITTING_TO_IDEAL 0\r
+// public static final int AR_FITTING_TO_INPUT=1;//#define AR_FITTING_TO_INPUT 1\r
+\r
+// public static final int AR_TEMPLATE_MATCHING_COLOR=0;//#define AR_TEMPLATE_MATCHING_COLOR 0\r
+// public static final int AR_TEMPLATE_MATCHING_BW=1;//#define AR_TEMPLATE_MATCHING_BW 1\r
+// public static final int AR_MATCHING_WITHOUT_PCA=0;//#define AR_MATCHING_WITHOUT_PCA 0\r
+// public static final int AR_MATCHING_WITH_PCA=1;//#define AR_MATCHING_WITH_PCA 1\r
+ \r
+// public static final int DEFAULT_TEMPLATE_MATCHING_MODE=AR_TEMPLATE_MATCHING_BW;//#define DEFAULT_TEMPLATE_MATCHING_MODE AR_TEMPLATE_MATCHING_COLOR\r
+// public static final int DEFAULT_MATCHING_PCA_MODE=AR_MATCHING_WITH_PCA;//#define DEFAULT_MATCHING_PCA_MODE AR_MATCHING_WITHOUT_PCA\r
+\r
+\r
+ //#ifdef _WIN32\r
+// public static final int DEFAULT_IMAGE_PROC_MODE =AR_IMAGE_PROC_IN_FULL;//# define DEFAULT_IMAGE_PROC_MODE AR_IMAGE_PROC_IN_FULL\r
+// public static final int DEFAULT_FITTING_MODE =AR_FITTING_TO_INPUT;//# define DEFAULT_FITTING_MODE AR_FITTING_TO_INPUT\r
+// public static final int DEFAULT_DRAW_MODE =AR_DRAW_BY_TEXTURE_MAPPING;//# define DEFAULT_DRAW_MODE AR_DRAW_BY_TEXTURE_MAPPING\r
+// public static final int DEFAULT_DRAW_TEXTURE_IMAGE =AR_DRAW_TEXTURE_FULL_IMAGE;//# define DEFAULT_DRAW_TEXTURE_IMAGE AR_DRAW_TEXTURE_FULL_IMAGE\r
+ //#endif\r
+\r
+// public static final int AR_PIX_SIZE_DEFAULT=\r
+// (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ABGR) || (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGRA) || (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGBA) || (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ARGB)?4:\r
+// ((AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGR) || (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGB)?3:\r
+// ((AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_2vuy) || (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_yuvs)?2:\r
+// ((AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_MONO)?1:-1)));\r
+// public static final int AR_GET_TRANS_MAT_MAX_LOOP_COUNT=5;//#define AR_GET_TRANS_MAT_MAX_LOOP_COUNT 5\r
+// public static final double AR_GET_TRANS_MAT_MAX_FIT_ERROR=1.0;//#define AR_GET_TRANS_MAT_MAX_FIT_ERROR 1.0\r
+// public static final double AR_GET_TRANS_CONT_MAT_MAX_FIT_ERROR=1.0;//#define AR_GET_TRANS_CONT_MAT_MAX_FIT_ERROR 1.0\r
+\r
+// public static final int AR_AREA_MAX=100000;//#define AR_AREA_MAX 100000\r
+// public static final int AR_AREA_MIN=70;//#define AR_AREA_MIN 70\r
+\r
+\r
+// public static final int AR_SQUARE_MAX=30;//#define AR_SQUARE_MAX 30\r
+// public static final int AR_CHAIN_MAX=10000;//#define AR_CHAIN_MAX 10000\r
+// public static final int AR_PATT_NUM_MAX=50;//#define AR_PATT_NUM_MAX 50 \r
+// public static final int AR_PATT_SIZE_X=16;//#define AR_PATT_SIZE_X 16 \r
+// public static final int AR_PATT_SIZE_Y=16;//#define AR_PATT_SIZE_Y 16 \r
+// public static final int AR_PATT_SAMPLE_NUM=64;//#define AR_PATT_SAMPLE_NUM 64\r
+\r
+// public static final double AR_GL_CLIP_NEAR=50.0;//#define AR_GL_CLIP_NEAR 50.0\r
+// public static final double AR_GL_CLIP_FAR=5000.0;//#define AR_GL_CLIP_FAR 5000.0\r
+\r
+// public static final int AR_HMD_XSIZE=640;//#define AR_HMD_XSIZE 640\r
+// public static final int AR_HMD_YSIZE=480;//#define AR_HMD_YSIZE 480\r
+\r
+// public static final int AR_PARAM_NMIN=6;//#define AR_PARAM_NMIN 6\r
+// public static final int AR_PARAM_NMAX=1000;//#define AR_PARAM_NMAX 1000\r
+// public static final double AR_PARAM_C34=100.0;//#define AR_PARAM_C34 100.0\r
+}\r
--- /dev/null
+package jp.nyatla.nyartoolkit.base;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.NyARMat;\r
+\r
+\r
+\r
+\r
+public class Param {\r
+ private static final int AR_PARAM_NMIN=6;//#define AR_PARAM_NMIN 6\r
+ private static final int AR_PARAM_NMAX=1000;//#define AR_PARAM_NMAX 1000\r
+ private static final double AR_PARAM_C34=100.0;//#define AR_PARAM_C34 100.0\r
+\r
+ /*\r
+ typedef struct {\r
+ int xsize, ysize;\r
+ double matL[3][4];\r
+ double matR[3][4];\r
+ double matL2R[3][4];\r
+ double dist_factorL[4];\r
+ double dist_factorR[4];\r
+ } ARSParam;*/\r
+/* static class ARSParam{\r
+ int xsize, ysize;\r
+ Double2dArray matL=new Double2dArray(3,4);\r
+ Double2dArray matR=new Double2dArray(3,4);\r
+ Double2dArray matL2R=new Double2dArray(3,4);\r
+ double[] dist_factorL=new double[4];\r
+ double[] dist_factorR=new double[4];\r
+ }*/\r
+ private static final int arParamGet_AR_PARAM_CDMIN = 12;\r
+ /*int arParamGet( double global[][3], double screen[][2], int data_num,double mat[3][4] );*/\r
+ public static int arParamGet( double global[][], double[][] screen, int num,double[][] mat) throws NyARException\r
+ {\r
+ NyARMat mat_a, mat_at, mat_r;//ARMat *mat_a, *mat_at, *mat_r, mat_cpara;\r
+ NyARMat mat_wm1,mat_wm2;//ARMat *mat_wm1, *mat_wm2;\r
+ int i;\r
+ \r
+ if(num < AR_PARAM_NMIN){\r
+ return( -1 );\r
+ }\r
+ if(num > AR_PARAM_NMAX){\r
+ return( -1 );\r
+ }\r
+ NyARException.trap("未チェックのパス");{\r
+ mat_a = new NyARMat(2*num,arParamGet_AR_PARAM_CDMIN-1 );//mat_a = arMatrixAlloc( 2*num, AR_PARAM_CDMIN-1 );\r
+ mat_at =new NyARMat(arParamGet_AR_PARAM_CDMIN-1, 2*num );//mat_at = arMatrixAlloc( AR_PARAM_CDMIN-1, 2*num );\r
+ mat_r = new NyARMat(2*num,1);//mat_r = arMatrixAlloc( 2*num, 1 );\r
+ mat_wm1 =new NyARMat(arParamGet_AR_PARAM_CDMIN-1, arParamGet_AR_PARAM_CDMIN-1 );//mat_wm1 = arMatrixAlloc( AR_PARAM_CDMIN-1, AR_PARAM_CDMIN-1 );\r
+ mat_wm2 =new NyARMat(arParamGet_AR_PARAM_CDMIN-1, 2*num );//mat_wm2 = arMatrixAlloc( AR_PARAM_CDMIN-1, 2*num );\r
+ }\r
+/*\r
+ mat_a = Matrix.arMatrixAlloc( 2*num, arParamGet_AR_PARAM_CDMIN-1 );//mat_a = arMatrixAlloc( 2*num, AR_PARAM_CDMIN-1 );\r
+ if( mat_a == null){\r
+ return -1;\r
+ }\r
+ mat_at =Matrix.arMatrixAlloc(arParamGet_AR_PARAM_CDMIN-1, 2*num );//mat_at = arMatrixAlloc( AR_PARAM_CDMIN-1, 2*num );\r
+ if(mat_at == null){\r
+ return -1;\r
+ }\r
+ mat_r = Matrix.arMatrixAlloc( 2*num, 1 );//mat_r = arMatrixAlloc( 2*num, 1 );\r
+ if(mat_r ==null){\r
+ return -1;\r
+ }\r
+ mat_wm1 = Matrix.arMatrixAlloc(arParamGet_AR_PARAM_CDMIN-1, arParamGet_AR_PARAM_CDMIN-1 );//mat_wm1 = arMatrixAlloc( AR_PARAM_CDMIN-1, AR_PARAM_CDMIN-1 );\r
+ if( mat_wm1 == null) {\r
+ return -1;\r
+ }\r
+ mat_wm2 = Matrix.arMatrixAlloc(arParamGet_AR_PARAM_CDMIN-1, 2*num );//mat_wm2 = arMatrixAlloc( AR_PARAM_CDMIN-1, 2*num );\r
+ if( mat_wm2 == null ) {\r
+ return -1;\r
+ }\r
+*/\r
+ /* Initializing array */\r
+ mat_a.zeroClear();//Javaではゼロクリアされるので不要\r
+// pa1=mat_a.getPointer();//pa1 = mat_a->m;\r
+// for(i = 0; i < 2 * num * (arParamGet_AR_PARAM_CDMIN-1); i++){\r
+// {//*pa1++ = 0.0;\r
+// pa1.set(0.0);\r
+// pa1.incPtr();}\r
+// }\r
+ double[][] pa1 =mat_a.getArray();\r
+ double[][] pa2 =mat_a.getArray();\r
+ /* Calculate A,R matrix */\r
+ double[][] pr=mat_r.getArray();\r
+ int pr_ptr_col=0;\r
+ for(i = 0; i < num; i++) {//for(i = 0, pr = mat_r->m; i < num; i++) {\r
+ int pa1_ptr_row =2*i; //pa1 = &(mat_a->m[ (2*i) * (AR_PARAM_CDMIN-1)\r
+ int pa2_ptr_row =2*i+1;//pa2 = &(mat_a->m[ (2*i+1) * (AR_PARAM_CDMIN-1) + 4]);\r
+\r
+\r
+// pa1=mat_a.getPointer((2*i)*(arParamGet_AR_PARAM_CDMIN-1)); ]);\r
+// pa2=mat_a.getPointer((2*i+1)*(arParamGet_AR_PARAM_CDMIN-1) + 4);\r
+ //*pa1++ = global[i][0]; *pa1++ = global[i][1];\r
+ pa1[pa1_ptr_row][ 0]=global[i][0];\r
+ pa1[pa1_ptr_row][ 1]=global[i][1];\r
+ //*pa1++ = global[i][2]; *pa1++ = 1.0;\r
+ pa1[pa1_ptr_row][ 2]=global[i][2];\r
+ pa1[pa1_ptr_row][ 3]=1.0;\r
+ //*pa2++ = global[i][0]; *pa2++ = global[i][1];\r
+ pa2[pa2_ptr_row][ 4]=global[i][0];\r
+ pa2[pa2_ptr_row][ 5]=global[i][1];\r
+ //*pa2++ = global[i][2]; *pa2++ = 1.0;\r
+ pa2[pa2_ptr_row][ 6]=global[i][2];\r
+ pa2[pa2_ptr_row][ 7]=1.0;\r
+ //pa1 += 4;\r
+ //*pa1++ = -global[i][0] * screen[i][0];\r
+ pa1[pa1_ptr_row][ 8]=-global[i][0] * screen[i][0];\r
+ //*pa1++ = -global[i][1] * screen[i][0];\r
+ pa1[pa1_ptr_row][ 9]=-global[i][1] * screen[i][0];\r
+ //*pa1 = -global[i][2] * screen[i][0];\r
+ pa1[pa1_ptr_row][10]=-global[i][2]* screen[i][0];\r
+ //*pa2++ = -global[i][0] * screen[i][1];\r
+ pa2[pa2_ptr_row][ 8]=-global[i][0] * screen[i][1];\r
+ //*pa2++ = -global[i][1] * screen[i][1];\r
+ pa2[pa2_ptr_row][ 9]=-global[i][1] * screen[i][1];\r
+ //*pa2 = -global[i][2] * screen[i][1];\r
+ pa2[pa2_ptr_row][10]=-global[i][2] * screen[i][1];\r
+ //*pr++ = screen[i][0] * AR_PARAM_C34;\r
+ pr[0][pr_ptr_col]=screen[i][0] * AR_PARAM_C34;pr_ptr_col++;\r
+ //*pr++ = screen[i][1] * AR_PARAM_C34;\r
+ pr[0][pr_ptr_col]=screen[i][1] * AR_PARAM_C34;pr_ptr_col++;\r
+ }\r
+\r
+ NyARException.trap("未チェックのパス");\r
+ NyARMat.matrixTrans(mat_at, mat_a );//if( arMatrixTrans( mat_at, mat_a ) < 0 ){\r
+\r
+ NyARException.trap("未チェックのパス");\r
+ NyARMat.matrixMul( mat_wm1, mat_at, mat_a );//if( arMatrixMul( mat_wm1, mat_at, mat_a ) < 0 ) {\r
+ NyARException.trap("未チェックのパス");\r
+ NyARMat.matrixSelfInv(mat_wm1 );//if( arMatrixSelfInv( mat_wm1 ) < 0 ) {\r
+\r
+ NyARException.trap("未チェックのパス");\r
+ NyARMat.matrixMul( mat_wm2, mat_wm1, mat_at );//if( arMatrixMul( mat_wm2, mat_wm1, mat_at ) < 0 ) {\r
+\r
+ //mat_cpara.row = AR_PARAM_CDMIN-1;//mat_cpara.row = AR_PARAM_CDMIN-1;\r
+ //mat_cpara.clm = 1;\r
+ //mat_cpara.m = &(mat[0][0]);\r
+ /*1次元行列から3x4行列に転写。高負荷なところじゃないから地道に転写でOK*/\r
+ NyARMat mat_cpara=new NyARMat(arParamGet_AR_PARAM_CDMIN-1,1);\r
+ double[][] mat_cpara_array=mat_cpara.getArray();\r
+ NyARException.trap("未チェックのパス");\r
+ NyARMat.matrixMul(mat_cpara, mat_wm2, mat_r );//if( arMatrixMul( &mat_cpara, mat_wm2, mat_r ) < 0 ) {\r
+\r
+ for(int i2=0;i<3;i++){\r
+ for(int i3=0;i3<4;i3++){\r
+ mat[i2][i3]=mat_cpara_array[i2*4+i3][0];\r
+ }\r
+ }\r
+ //ARMat.wrap(mat.array(),arParamGet_AR_PARAM_CDMIN-1,1);}\r
+\r
+ mat[2][3]=AR_PARAM_C34;//mat[2][3] = AR_PARAM_C34;\r
+\r
+ return 0;\r
+ }\r
+\r
+/* //int arsParamChangeSize( ARSParam *source, int xsize, int ysize, ARSParam *newparam );\r
+ public static int arsParamChangeSize( ARSParam source, int xsize, int ysize, ARSParam newparam)\r
+ {\r
+ double scale;\r
+\r
+ newparam.xsize=xsize;//newparam->xsize = xsize;\r
+ newparam.ysize=ysize;//newparam->ysize = ysize;\r
+\r
+ scale=(double)xsize/ (double)(source.xsize);//scale = (double)xsize / (double)(source->xsize);\r
+ for(int i = 0; i < 4; i++ ){\r
+ newparam.matL.set(0,i,source.matL.get(0,i)*scale);//newparam->matL[0][i] = source->matL[0][i] * scale;\r
+ newparam.matL.set(1,i,source.matL.get(1,i)*scale);//newparam->matL[1][i] = source->matL[1][i] * scale;\r
+ newparam.matL.set(2,i,source.matL.get(2,i));//newparam->matL[2][i] = source->matL[2][i];\r
+ }\r
+ for(int i = 0; i < 4; i++ ) {\r
+ newparam.matR.set(0,i,source.matR.get(0,i)*scale);//newparam->matR[0][i] = source->matR[0][i] * scale;\r
+ newparam.matR.set(1,i,source.matR.get(1,i)*scale);//newparam->matR[1][i] = source->matR[1][i] * scale;\r
+ newparam.matR.set(2,i,source.matR.get(2,i));//newparam->matR[2][i] = source->matR[2][i];\r
+ }\r
+ for(int i = 0; i < 4; i++ ) {\r
+ newparam.matL2R.set(0,i,source.matL2R.get(0,i));//newparam->matL2R[0][i] = source->matL2R[0][i];\r
+ newparam.matL2R.set(1,i,source.matL2R.get(1,i));//newparam->matL2R[1][i] = source->matL2R[1][i];\r
+ newparam.matL2R.set(2,i,source.matL2R.get(2,i));//newparam->matL2R[2][i] = source->matL2R[2][i];\r
+ }\r
+\r
+ newparam.dist_factorL[0] = source.dist_factorL[0] * scale;//newparam->dist_factorL[0] = source->dist_factorL[0] * scale;\r
+ newparam.dist_factorL[1] = source.dist_factorL[1] * scale;//newparam->dist_factorL[1] = source->dist_factorL[1] * scale;\r
+ newparam.dist_factorL[2] = source.dist_factorL[2] / (scale*scale);//newparam->dist_factorL[2] = source->dist_factorL[2] / (scale*scale);\r
+ newparam.dist_factorL[3] = source.dist_factorL[3];//newparam->dist_factorL[3] = source->dist_factorL[3];\r
+\r
+ newparam.dist_factorR[0] = source.dist_factorR[0] * scale;//newparam->dist_factorR[0] = source->dist_factorR[0] * scale;\r
+ newparam.dist_factorR[1] = source.dist_factorR[1] * scale;//newparam->dist_factorR[1] = source->dist_factorR[1] * scale;\r
+ newparam.dist_factorR[2] = source.dist_factorR[2] / (scale*scale);//newparam->dist_factorR[2] = source->dist_factorR[2] / (scale*scale);\r
+ newparam.dist_factorR[3] = source.dist_factorR[3];//newparam->dist_factorR[3] = source->dist_factorR[3];\r
+\r
+ return 0;\r
+ }*/\r
+/* //int arsParamSave( char *filename, ARSParam *sparam );\r
+ public static int arsParamSave(String filename, ARSParam sparam) throws Exception\r
+ { \r
+ //int xsize, ysize;\r
+ //Double2dArray matL=new Double2dArray(3,4);\r
+ //Double2dArray matR=new Double2dArray(3,4);\r
+ //Double2dArray matL2R=new Double2dArray(3,4);\r
+ //double dist_factorL[]=new double[4];\r
+ //double dist_factorR[]=new double[4];\r
+\r
+ byte[] buf=new byte[(4+4+(3*4*8)*3+(4*8)*2)];\r
+ \r
+ //バッファをラップ\r
+ ByteBuffer bb = ByteBuffer.wrap(buf);\r
+ bb.order(ByteOrder.BIG_ENDIAN);\r
+\r
+ //書き込み\r
+ bb.putInt(sparam.xsize);\r
+ bb.putInt(sparam.ysize);\r
+ for(int i=0;i<3;i++){\r
+ for(int i2=0;i2<4;i2++){\r
+ bb.putDouble(sparam.matL.get(i, i2));\r
+ }\r
+ }\r
+ for(int i=0;i<3;i++){\r
+ for(int i2=0;i2<4;i2++){\r
+ bb.putDouble(sparam.matR.get(i, i2));\r
+ }\r
+ }\r
+ for(int i=0;i<3;i++){\r
+ for(int i2=0;i2<4;i2++){\r
+ bb.putDouble(sparam.matL2R.get(i, i2));\r
+ }\r
+ }\r
+ for(int i=0;i<4;i++){\r
+ bb.putDouble(sparam.dist_factorL[i]);\r
+ }\r
+ for(int i=0;i<4;i++){\r
+ bb.putDouble(sparam.dist_factorR[i]);\r
+ }\r
+ //ファイルに保存\r
+ FileOutputStream fs=new FileOutputStream(filename);\r
+ fs.write(buf);\r
+ fs.close();\r
+ \r
+ return 0;\r
+ }*/\r
+/* //int arsParamLoad( char *filename, ARSParam *sparam );\r
+ public static int arsParamLoad(String filename, ARSParam sparam ) throws Exception\r
+ {\r
+ //ファイルを読んどく\r
+ FileInputStream fs=new FileInputStream(filename);\r
+ File f=new File(filename);\r
+ int file_size=(int)f.length();\r
+ byte[] buf=new byte[file_size];\r
+ fs.read(buf);\r
+ fs.close();\r
+ \r
+ //バッファを加工\r
+ ByteBuffer bb = ByteBuffer.wrap(buf);\r
+ bb.order(ByteOrder.BIG_ENDIAN);\r
+ \r
+ //固定回数パースして配列に格納 \r
+ sparam.xsize=bb.getInt();\r
+ sparam.ysize=bb.getInt();\r
+ for(int i=0;i<3;i++){\r
+ for(int i2=0;i2<4;i2++){\r
+ sparam.matL.set(i,i2,bb.getDouble());\r
+ }\r
+ }\r
+ for(int i=0;i<3;i++){\r
+ for(int i2=0;i2<4;i2++){\r
+ sparam.matR.set(i,i2,bb.getDouble());\r
+ }\r
+ }\r
+ for(int i=0;i<3;i++){\r
+ for(int i2=0;i2<4;i2++){\r
+ sparam.matL2R.set(i,i2,bb.getDouble());\r
+ }\r
+ }\r
+ for(int i=0;i<3;i++){\r
+ sparam.dist_factorL[i]=bb.getDouble();\r
+ }\r
+ for(int i=0;i<3;i++){\r
+ sparam.dist_factorR[i]=bb.getDouble();\r
+ }\r
+ return 0;\r
+ }*/\r
+/*\r
+ // int arsParamGetMat( double matL[3][4], double matR[3][4],double cparaL[3][4], double cparaR[3][4], double matL2R[3][4] );\r
+ public static int arsParamGetMat(double[][] matL, double[][] matR,double[][] cparaL, double[][] cparaR, double[][] matL2R) throws JartkException\r
+ {\r
+ ARMat t1,t2,t3;//ARMat *t1, *t2, *t3;\r
+ //double transL[3][4], transR[3][4];\r
+ Double2dArray transL=new Double2dArray(3,4);\r
+ Double2dArray transR=new Double2dArray(3,4);\r
+ \r
+ arParamDecompMat( matL,cparaL,transL);\r
+ arParamDecompMat( matR,cparaR,transR);\r
+ JartkException.trap("未チェックパス");{\r
+ t1=new ARMat(4,4);//t1 = arMatrixAlloc( 4, 4 );\r
+ t2=new ARMat(4,4);//t2 = arMatrixAlloc( 4, 4 );\r
+ }\r
+ double[][] t1_array=t1.getArray();\r
+ double[][] t2_array=t2.getArray();\r
+ for(int j = 0; j < 3; j++ ){\r
+ for(int i = 0; i < 4; i++ ) {\r
+ JartkException.trap("未チェックパス");{\r
+ t1_array[j][i]=transL.get(j,i);//t1->m[j*4+i] = transL[j][i];\r
+ t2_array[j][i]=transL.get(j,i);//t2->m[j*4+i] = transR[j][i];\r
+ }\r
+ }\r
+ }\r
+ JartkException.trap("未チェックパス");{\r
+ t1_array[3][0]=t1_array[3][1]=t1_array[3][2]=0.0;//t1->m[12] = t1->m[13] = t1->m[14] = 0.0;\r
+ t1_array[3][3]=1.0;//t1->m[15] = 1.0;\r
+ t2_array[3][0]=t2_array[3][1]=t2_array[3][2]=0.0;//t2->m[12] = t2->m[13] = t2->m[14] = 0.0;\r
+ t2_array[3][3]=1.0;//t2->m[15] = 1.0;\r
+ }\r
+ JartkException.trap("未チェックのパス");\r
+ ARMat.matrixSelfInv(t1);//if( arMatrixSelfInv(t1) != 0 ) {\r
+\r
+ JartkException.trap("未チェックのパス"); \r
+ t3 =ARMat.matrixAllocMul(t2, t1);//t3 = arMatrixAllocMul(t2, t1);\r
+ double[][] t3_array=t3.getArray();\r
+ if(t3==null){\r
+ return -1;\r
+ }\r
+ \r
+ for(int j = 0; j < 3; j++ ) {\r
+ for(int i = 0; i < 4; i++ ) {\r
+ JartkException.trap("未チェックパス");\r
+ matL2R[j][i]=t3_array[j][i];//matL2R[j][i] = t3->m[j*4+i];\r
+ }\r
+ }\r
+ return 0;\r
+ }\r
+*/ //int arsParamDisp( ARSParam *sparam )\r
+/* public static int arsParamDisp( ARSParam sparam)\r
+ {\r
+ System.out.println("--------------------------------------");//printf("--------------------------------------\n");\r
+ System.out.println("SIZE = "+sparam.xsize+", "+sparam.ysize);// printf("SIZE = %d, %d\n", sparam->xsize, sparam->ysize);\r
+ System.out.println("-- Left --");//printf("-- Left --\n");\r
+ System.out.println("Distotion factor = "+sparam.dist_factorL[0]+" "+sparam.dist_factorL[1]+" "+sparam.dist_factorL[2]+" "+sparam.dist_factorL[3]);//printf("Distotion factor = %f %f %f %f\n", sparam->dist_factorL[0],sparam->dist_factorL[1], sparam->dist_factorL[2], sparam->dist_factorL[3] );\r
+ for(int j = 0; j < 3; j++ ) {\r
+ for(int i = 0; i < 4; i++ ){\r
+ System.out.print(sparam.matL.get(j,i)+" ");//printf("%7.5f ", sparam->matL[j][i]);\r
+ }\r
+ System.out.println();//printf("\n");\r
+ }\r
+ \r
+ System.out.println("-- Right --");//printf("-- Right --\n");\r
+ System.out.println("Distotion factor = "+sparam.dist_factorR[0]+" "+sparam.dist_factorR[1]+" "+sparam.dist_factorR[2]+" "+sparam.dist_factorR[3]);//printf("Distotion factor = %f %f %f %f\n", sparam->dist_factorR[0],sparam->dist_factorR[1], sparam->dist_factorR[2], sparam->dist_factorR[3]);\r
+ for(int j = 0; j < 3; j++ ){\r
+ for(int i = 0; i < 4; i++ ){\r
+ System.out.println(sparam.matR.get(j,i)+" ");//printf("%7.5f ", sparam->matR[j][i]);\r
+ }\r
+ System.out.println();//printf("\n");\r
+ }\r
+ \r
+ System.out.println("-- Left => Right --");//printf("-- Left => Right --\n");\r
+ for(int j = 0; j < 3; j++ ) {\r
+ for(int i = 0; i < 4; i++ ){\r
+ //printf("%7.5f ", sparam->matL2R[j][i]);\r
+ }\r
+ System.out.println();//printf("\n");\r
+ }\r
+ \r
+ System.out.println("--------------------------------------");//printf("--------------------------------------\n");\r
+ \r
+ return 0; \r
+ }*/\r
+}\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+\r
+package jp.nyatla.nyartoolkit.core;\r
+\r
+import java.io.FileInputStream;\r
+import java.io.InputStreamReader;\r
+import java.io.StreamTokenizer;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+\r
+\r
+\r
+\r
+\r
+/**\r
+ * ARToolKitのマーカーコードを1個保持します。\r
+ *\r
+ */\r
+public class NyARCode{\r
+ private int[][][][] pat;//static int pat[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];\r
+ private double[] patpow=new double[4];//static double patpow[AR_PATT_NUM_MAX][4];\r
+ private short[][][] patBW;//static int patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];\r
+ private double[] patpowBW=new double[4];//static double patpowBW[AR_PATT_NUM_MAX][4]; \r
+ private int width,height;\r
+ public int[][][][] getPat()\r
+ {\r
+ return pat;\r
+ }\r
+ public double [] getPatPow()\r
+ {\r
+ return patpow;\r
+ }\r
+ public short[][][] getPatBW()\r
+ {\r
+ return patBW;\r
+ }\r
+ public double[] getPatPowBW()\r
+ {\r
+ return patpowBW;\r
+ }\r
+ public int getWidth()\r
+ {\r
+ return width;\r
+ }\r
+ public int getHeight()\r
+ {\r
+ return height;\r
+ }\r
+ \r
+ public NyARCode(int i_width,int i_height)\r
+ {\r
+ width=i_width;\r
+ height=i_height;\r
+ pat=new int[4][height][width][3];//static int pat[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];\r
+ patBW=new short[4][height][width];//static int patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];\r
+ }\r
+ \r
+ /**\r
+ * int arLoadPatt( const char *filename );\r
+ * ARToolKitのパターンファイルをロードする。\r
+ * @param filename\r
+ * @return\r
+ * @throws Exception\r
+ */\r
+ public void LoadFromARFile(String filename) throws NyARException\r
+ {\r
+ try{\r
+ StreamTokenizer st=new StreamTokenizer(new InputStreamReader(new FileInputStream(filename)));\r
+ //パターンデータはGBRAで並んでる。\r
+ for(int h=0; h<4; h++ ) {\r
+ int l = 0;\r
+ for(int i3 = 0; i3 < 3; i3++ ) {\r
+ for(int i2 = 0; i2 < height; i2++ ) {\r
+ for(int i1 = 0; i1 < width; i1++ ){\r
+ //数値のみ読み出す\r
+ switch(st.nextToken()){//if( fscanf(fp, "%d", &j) != 1 ) {\r
+ case StreamTokenizer.TT_NUMBER:\r
+ break;\r
+ default:\r
+ throw new NyARException();\r
+ }\r
+ short j=(short)(255-st.nval);//j = 255-j;\r
+ //標準ファイルのパターンはBGRでならんでるからRGBに並べなおす\r
+ switch(i3){\r
+ case 0:pat[h][i2][i1][2] = j;break;//pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+2] = j;break;\r
+ case 1:pat[h][i2][i1][1] = j;break;//pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+1] = j;break;\r
+ case 2:pat[h][i2][i1][0] = j;break;//pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+0] = j;break;\r
+ }\r
+ //pat[patno][h][(i2*Config.AR_PATT_SIZE_X+i1)*3+i3] = j;\r
+ if( i3 == 0 ){\r
+ patBW[h][i2][i1] = j;//patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1] = j;\r
+ }else{\r
+ patBW[h][i2][i1] += j;//patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1] += j;\r
+ }\r
+ if( i3 == 2 ){\r
+ patBW[h][i2][i1] /= 3;//patBW[patno][h][i2*Config.AR_PATT_SIZE_X+i1] /= 3;\r
+ }\r
+ l += j;\r
+ }\r
+ }\r
+ }\r
+ \r
+ l /= (height*width*3);\r
+ \r
+ int m = 0;\r
+ for(int i = 0; i < height; i++ ) {//for( i = 0; i < AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3; i++ ) {\r
+ for(int i2 = 0; i2 < width; i2++ ) {\r
+ for(int i3 = 0; i3 < 3; i3++ ) {\r
+ pat[h][i][i2][i3] -= l;\r
+ m += (pat[h][i][i2][i3]*pat[h][i][i2][i3]);\r
+ }\r
+ }\r
+ }\r
+ patpow[h] = Math.sqrt((double)m);\r
+ if( patpow[h] == 0.0 ){\r
+ patpow[h] = 0.0000001;\r
+ }\r
+ \r
+ m = 0;\r
+ for(int i = 0; i < height; i++ ) {\r
+ for(int i2 = 0; i2 < width; i2++ ) {\r
+ patBW[h][i][i2] -= l;\r
+ m += (patBW[h][i][i2]*patBW[h][i][i2]);\r
+ }\r
+ }\r
+ patpowBW[h] = Math.sqrt((double)m);\r
+ if(patpowBW[h] == 0.0 ){\r
+ patpowBW[h] = 0.0000001;\r
+ }\r
+ }\r
+ }catch(Exception e){\r
+ throw new NyARException(e);\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.*;\r
+\r
+/**\r
+ * 24ビットカラーのマーカーを保持するために使うクラスです。\r
+ * このクラスは、ARToolkitのパターンと、ラスタから取得したパターンを保持します。\r
+ *\r
+ */\r
+public class NyARColorPatt\r
+{\r
+ public static final int AR_PATT_SAMPLE_NUM=64;//#define AR_PATT_SAMPLE_NUM 64\r
+ private short extpat[][][];\r
+ private int width;\r
+ private int height;\r
+ public NyARColorPatt(int i_width,int i_height)\r
+ {\r
+ width=i_width;\r
+ height=i_height;\r
+ extpat=new short[i_height][i_width][3];\r
+ }\r
+ public short[][][] getPatArray()\r
+ {\r
+ return extpat;\r
+ }\r
+ public int getWidth()\r
+ {\r
+ return width;\r
+ }\r
+ public int getHeight()\r
+ {\r
+ return height;\r
+ }\r
+ private static void get_cpara( double world[][], double vertex[][],double para[][] ) throws NyARException\r
+ {\r
+ NyARMat a = new NyARMat( 8, 8 );\r
+ double[][] a_array=a.getArray();\r
+ NyARMat b = new NyARMat( 8, 1 );\r
+ double[][] b_array=b.getArray();\r
+ NyARMat c = new NyARMat( 8, 1 );\r
+ double[][] c_array=c.getArray();\r
+ \r
+ for(int i = 0; i < 4; i++ ) {\r
+ a_array[i*2][0]=world[i][0];//a->m[i*16+0] = world[i][0];\r
+ a_array[i*2][1]=world[i][1];//a->m[i*16+1] = world[i][1];\r
+ a_array[i*2][2]=1.0;//a->m[i*16+2] = 1.0;\r
+ a_array[i*2][3]=0.0;//a->m[i*16+3] = 0.0;\r
+ a_array[i*2][4]=0.0;//a->m[i*16+4] = 0.0;\r
+ a_array[i*2][5]=0.0;//a->m[i*16+5] = 0.0;\r
+ a_array[i*2][6]=-world[i][0] * vertex[i][0];//a->m[i*16+6] = -world[i][0] * vertex[i][0];\r
+ a_array[i*2][7]=-world[i][1] * vertex[i][0];//a->m[i*16+7] = -world[i][1] * vertex[i][0];\r
+ a_array[i*2+1][0]=0.0;//a->m[i*16+8] = 0.0;\r
+ a_array[i*2+1][1]=0.0;//a->m[i*16+9] = 0.0;\r
+ a_array[i*2+1][2]=0.0;//a->m[i*16+10] = 0.0;\r
+ a_array[i*2+1][3]=world[i][0];//a->m[i*16+11] = world[i][0];\r
+ a_array[i*2+1][4]=world[i][1];//a->m[i*16+12] = world[i][1];\r
+ a_array[i*2+1][5]=1.0;//a->m[i*16+13] = 1.0;\r
+ a_array[i*2+1][6]=-world[i][0] * vertex[i][1];//a->m[i*16+14] = -world[i][0] * vertex[i][1];\r
+ a_array[i*2+1][7]=-world[i][1] * vertex[i][1];//a->m[i*16+15] = -world[i][1] * vertex[i][1];\r
+ b_array[i*2+0][0]=vertex[i][0];//b->m[i*2+0] = vertex[i][0];\r
+ b_array[i*2+1][0]=vertex[i][1];//b->m[i*2+1] = vertex[i][1];\r
+ }\r
+// JartkException.trap("未チェックのパス");\r
+ NyARMat.matrixSelfInv(a);\r
+ \r
+// JartkException.trap("未チェックのパス");\r
+ NyARMat.matrixMul( c, a, b );\r
+ for(int i = 0; i < 2; i++ ) {\r
+ para[i][0] = c_array[i*3+0][0];//para[i][0] = c->m[i*3+0];\r
+ para[i][1] = c_array[i*3+1][0];//para[i][1] = c->m[i*3+1];\r
+ para[i][2] = c_array[i*3+2][0];//para[i][2] = c->m[i*3+2];\r
+ }\r
+ para[2][0] = c_array[2*3+0][0];//para[2][0] = c->m[2*3+0];\r
+ para[2][1] = c_array[2*3+1][0];//para[2][1] = c->m[2*3+1];\r
+ para[2][2] = 1.0;//para[2][2] = 1.0;\r
+ }\r
+ /**\r
+ * imageから、i_markerの位置にあるパターンを切り出して、保持します。\r
+ * @param image\r
+ * @param i_marker\r
+ * @throws Exception\r
+ */\r
+ public void pickFromRaster(NyARRaster image, NyARMarker i_marker) throws NyARException\r
+ {\r
+ int[] x_coord=i_marker.x_coord;\r
+ int[] y_coord=i_marker.y_coord;\r
+ int[] vertex=i_marker.vertex;\r
+ int[][][] ext_pat2=new int[height][width][3];//ARUint32 ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];\r
+ double[][] world=new double[4][2];//double world[4][2];\r
+ double[][] local=new double[4][2];//double local[4][2];\r
+ double[][] para=new double[3][3]; //double para[3][3];\r
+ double d, xw, yw;\r
+ int xc, yc;\r
+ int xdiv, ydiv;\r
+ int xdiv2, ydiv2;\r
+ int lx1, lx2, ly1, ly2;\r
+ int img_x,img_y;\r
+ \r
+ img_x=image.getWidth();\r
+ img_y=image.getHeight();\r
+\r
+ double xdiv2_reciprocal; // [tp]\r
+ double ydiv2_reciprocal; // [tp]\r
+ int ext_pat2_x_index;\r
+ int ext_pat2_y_index;\r
+ \r
+ world[0][0] = 100.0;\r
+ world[0][1] = 100.0;\r
+ world[1][0] = 100.0 + 10.0;\r
+ world[1][1] = 100.0;\r
+ world[2][0] = 100.0 + 10.0;\r
+ world[2][1] = 100.0 + 10.0;\r
+ world[3][0] = 100.0;\r
+ world[3][1] = 100.0 + 10.0;\r
+ for(int i = 0; i < 4; i++ ) {\r
+ local[i][0] = x_coord[vertex[i]];\r
+ local[i][1] = y_coord[vertex[i]];\r
+ }\r
+ get_cpara( world, local, para );\r
+\r
+ lx1 = (int)((local[0][0] - local[1][0])*(local[0][0] - local[1][0])+ (local[0][1] - local[1][1])*(local[0][1] - local[1][1]));\r
+ lx2 = (int)((local[2][0] - local[3][0])*(local[2][0] - local[3][0])+ (local[2][1] - local[3][1])*(local[2][1] - local[3][1]));\r
+ ly1 = (int)((local[1][0] - local[2][0])*(local[1][0] - local[2][0])+ (local[1][1] - local[2][1])*(local[1][1] - local[2][1]));\r
+ ly2 = (int)((local[3][0] - local[0][0])*(local[3][0] - local[0][0])+ (local[3][1] - local[0][1])*(local[3][1] - local[0][1]));\r
+ if( lx2 > lx1 ){\r
+ lx1 = lx2;\r
+ }\r
+ if( ly2 > ly1 ){\r
+ ly1 = ly2;\r
+ }\r
+ xdiv2 =width;\r
+ ydiv2 =height;\r
+ \r
+ while( xdiv2*xdiv2 < lx1/4 ){\r
+ xdiv2*=2;\r
+ }\r
+ while( ydiv2*ydiv2 < ly1/4 ){\r
+ ydiv2*=2;\r
+ }\r
+ \r
+ if( xdiv2 > AR_PATT_SAMPLE_NUM)\r
+ {\r
+ xdiv2 =AR_PATT_SAMPLE_NUM;\r
+ }\r
+ if( ydiv2 >AR_PATT_SAMPLE_NUM)\r
+ {\r
+ ydiv2 = AR_PATT_SAMPLE_NUM;\r
+ }\r
+ \r
+ xdiv = xdiv2/width;//xdiv = xdiv2/Config.AR_PATT_SIZE_X;\r
+ ydiv = ydiv2/height;//ydiv = ydiv2/Config.AR_PATT_SIZE_Y;\r
+/*\r
+printf("%3d(%f), %3d(%f)\n", xdiv2, sqrt(lx1), ydiv2, sqrt(ly1));\r
+*/\r
+\r
+ xdiv2_reciprocal = 1.0 / xdiv2;\r
+ ydiv2_reciprocal = 1.0 / ydiv2;\r
+ int[] rgb_tmp=new int[3];\r
+ // arGetCode_put_zero(ext_pat2);//put_zero( (ARUint8 *)ext_pat2, AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3*sizeof(ARUint32) );\r
+ for(int j = 0; j < ydiv2; j++ ) {\r
+ yw = 102.5 + 5.0 * (j+0.5) * ydiv2_reciprocal;\r
+ for(int i = 0; i < xdiv2; i++ ) {\r
+ xw = 102.5 + 5.0 * (i+0.5) * xdiv2_reciprocal;\r
+ d = para[2][0]*xw + para[2][1]*yw + para[2][2];\r
+ if( d == 0 ){\r
+ throw new NyARException();\r
+ }\r
+ xc = (int)((para[0][0]*xw + para[0][1]*yw + para[0][2])/d);\r
+ yc = (int)((para[1][0]*xw + para[1][1]*yw + para[1][2])/d);\r
+\r
+\r
+ if( xc >= 0 && xc < img_x && yc >= 0 && yc < img_y ) {\r
+ ext_pat2_y_index = j/ydiv;\r
+ ext_pat2_x_index = i/xdiv;\r
+// image_index = (yc*arUtil_c.arImXsize+xc)*Config.AR_PIX_SIZE_DEFAULT;\r
+ image.pickRgbArray(xc, yc, rgb_tmp);\r
+\r
+ ext_pat2[ext_pat2_y_index][ext_pat2_x_index][0] += rgb_tmp[0];//R\r
+ ext_pat2[ext_pat2_y_index][ext_pat2_x_index][1] += rgb_tmp[1];//G\r
+ ext_pat2[ext_pat2_y_index][ext_pat2_x_index][2] += rgb_tmp[2];//B\r
+// System.out.println(xc+":"+yc+":"+rgb_tmp[0]+":"+rgb_tmp[1]+":"+rgb_tmp[2]);\r
+ }\r
+ }\r
+ }\r
+// short[][][] ext_pat=new short[Config.AR_PATT_SIZE_Y][Config.AR_PATT_SIZE_X][3];//ARUint32 ext_pat2[AR_PATT_SIZE_Y][AR_PATT_SIZE_X][3];\r
+\r
+ for(int j = 0; j < height; j++ ) {\r
+ for(int i = 0; i < width; i++ ) { // PRL 2006-06-08.\r
+ extpat[j][i][0]=(short)(ext_pat2[j][i][0] / (xdiv*ydiv));//ext_pat[j][i][0] = (byte)(ext_pat2[j][i][0] / (xdiv*ydiv));\r
+ extpat[j][i][1]=(short)(ext_pat2[j][i][1] / (xdiv*ydiv));//ext_pat[j][i][1] = (byte)(ext_pat2[j][i][1] / (xdiv*ydiv));\r
+ extpat[j][i][2]=(short)(ext_pat2[j][i][2] / (xdiv*ydiv));//ext_pat[j][i][2] = (byte)(ext_pat2[j][i][2] / (xdiv*ydiv));\r
+ }\r
+ }\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core;\r
+\r
+\r
+\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.util.IntValue;\r
+/**\r
+ * イメージからマーカー情報を検出するクラス。\r
+ * このクラスは、arDetectMarker2.cとの置き換えになります。\r
+ * ラベリング済みのラスタデータからマーカー位置を検出して、結果を保持します。\r
+ *\r
+ */\r
+public class NyARDetectMarker {\r
+ private static final int AR_AREA_MAX=100000;//#define AR_AREA_MAX 100000\r
+ private static final int AR_AREA_MIN=70;//#define AR_AREA_MIN 70\r
+\r
+ private int area_max=AR_AREA_MAX;\r
+ private int area_min=AR_AREA_MIN;\r
+ private NyARMarker[] marker_info2_array;\r
+ private int marker_num;\r
+ private int width,height;\r
+ /**\r
+ * 最大i_squre_max個のマーカーを検出するクラスを作成する。\r
+ * @param i_width\r
+ * @param i_height\r
+ * @param i_squre_max\r
+ */\r
+ public NyARDetectMarker(int i_width,int i_height,int i_squre_max)\r
+ {\r
+ width =i_width;\r
+ height=i_height;\r
+ marker_info2_array=new NyARMarker[i_squre_max];\r
+ }\r
+ public int getMarkerNum()\r
+ {\r
+ return marker_num;\r
+ }\r
+ public NyARMarker[] getMarkerArray() throws NyARException\r
+ {\r
+ return marker_info2_array;\r
+ }\r
+ /**\r
+ * static int get_vertex( int x_coord[], int y_coord[], int st, int ed,double thresh, int vertex[], int *vnum)\r
+ * 関数の代替関数\r
+ * @param x_coord\r
+ * @param y_coord\r
+ * @param st\r
+ * @param ed\r
+ * @param thresh\r
+ * @param vertex\r
+ * @param vnum\r
+ * @return\r
+ */\r
+ private static boolean get_vertex( int[] x_coord, int[] y_coord, int st, int ed,double thresh, int vertex[],IntValue vnum)\r
+ {\r
+ double d, dmax;\r
+ double a, b, c;\r
+ int i, v1=0;\r
+ \r
+ a = y_coord[ed] - y_coord[st];\r
+ b = x_coord[st] - x_coord[ed];\r
+ c = x_coord[ed]*y_coord[st] - y_coord[ed]*x_coord[st];\r
+ dmax = 0;\r
+ for(i=st+1;i<ed;i++) {\r
+ d = a*x_coord[i] + b*y_coord[i] + c;\r
+ if( d*d > dmax ) {\r
+ dmax = d*d;\r
+ v1 = i;\r
+ }\r
+ }\r
+ if( dmax/(a*a+b*b) > thresh ) {\r
+ if(!get_vertex(x_coord, y_coord, st, v1, thresh, vertex, vnum)){\r
+ return false;\r
+ }\r
+ if( vnum.get() > 5 ){\r
+ return false;\r
+ }\r
+ vertex[vnum.get()] = v1;//vertex[(*vnum)] = v1;\r
+ vnum.inc();//(*vnum)++;\r
+ \r
+ if(!get_vertex(x_coord, y_coord, v1, ed, thresh, vertex, vnum)){\r
+ return false;\r
+ }\r
+ }\r
+ return true;\r
+ }\r
+ /**\r
+ * static int arDetectMarker2_check_square( int area, ARMarkerInfo2 *marker_info2, double factor )\r
+ * 関数の代替関数\r
+ * @param area\r
+ * @param i_marker_info2\r
+ * @param factor\r
+ * @return\r
+ */\r
+ private static boolean check_square( int area, NyARMarker i_marker_info2, double factor )\r
+ {\r
+ int sx, sy;\r
+ int dmax, d, v1;\r
+ int[] vertex=new int[10];//int vertex[10]\r
+ int[] wv1=new int[10],wv2=new int[10];//int wv1[10],wv2[10];\r
+ int v2;// int wvnum1,wvnum2,v2;\r
+ double thresh;\r
+ int i;\r
+ IntValue wvnum1=new IntValue(),wvnum2=new IntValue();\r
+\r
+\r
+ dmax = 0;\r
+ v1 = 0;\r
+ sx = i_marker_info2.x_coord[0];//sx = marker_info2->x_coord[0];\r
+ sy = i_marker_info2.y_coord[0];//sy = marker_info2->y_coord[0];\r
+ for(i=1;i<i_marker_info2.coord_num-1;i++){//for(i=1;i<marker_info2->coord_num-1;i++) {\r
+ d = (i_marker_info2.x_coord[i]-sx)*(i_marker_info2.x_coord[i]-sx)+ (i_marker_info2.y_coord[i]-sy)*(i_marker_info2.y_coord[i]-sy);\r
+ if( d > dmax ) {\r
+ dmax = d;\r
+ v1 = i;\r
+ }\r
+ }\r
+\r
+ thresh = (area/0.75) * 0.01 * factor;\r
+// vnum = 1;\r
+ vertex[0] = 0;\r
+ wvnum1.set(0);// wvnum1 = 0;\r
+ wvnum2.set(0);// wvnum2 = 0;\r
+\r
+ if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord, 0, v1,thresh, wv1, wvnum1)){ //if( get_vertex(marker_info2->x_coord, marker_info2->y_coord, 0, v1,thresh, wv1, &wvnum1) < 0 ) {\r
+ return false;\r
+ }\r
+ if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,v1, i_marker_info2.coord_num-1, thresh, wv2, wvnum2)) {//if(get_vertex(marker_info2->x_coord, marker_info2->y_coord,v1, marker_info2->coord_num-1, thresh, wv2, &wvnum2) < 0 ) {\r
+ return false;\r
+ }\r
+\r
+ if( wvnum1.get() == 1 && wvnum2.get() == 1 ) {//if( wvnum1 == 1 && wvnum2 == 1 ) {\r
+ vertex[1] = wv1[0];\r
+ vertex[2] = v1;\r
+ vertex[3] = wv2[0];\r
+ }else if( wvnum1.get() > 1 && wvnum2.get() == 0 ) {//}else if( wvnum1 > 1 && wvnum2 == 0 ) {\r
+ v2 = v1 / 2;\r
+ wvnum1.set(0);wvnum2.set(0);//wvnum1 = wvnum2 = 0;\r
+ if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,0, v2, thresh, wv1, wvnum1)) {\r
+ return false;\r
+ }\r
+ if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,v2, v1, thresh, wv2, wvnum2)) {\r
+ return false;\r
+ }\r
+ if( wvnum1.get() == 1 && wvnum2.get() == 1 ) {\r
+ vertex[1] = wv1[0];\r
+ vertex[2] = wv2[0];\r
+ vertex[3] = v1;\r
+ }else{\r
+ return false;\r
+ }\r
+ }else if( wvnum1.get() == 0 && wvnum2.get() > 1 ) {\r
+ v2 = (v1 + i_marker_info2.coord_num-1) / 2;\r
+ \r
+ wvnum1.set(0);wvnum2.set(0);//wvnum1 = wvnum2 = 0;\r
+ if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,v1, v2, thresh, wv1,wvnum1)) {\r
+ return false;\r
+ }\r
+ if(!get_vertex(i_marker_info2.x_coord, i_marker_info2.y_coord,v2, i_marker_info2.coord_num-1, thresh, wv2, wvnum2)) {\r
+ return false;\r
+ }\r
+ if( wvnum1.get() == 1 && wvnum2.get() == 1 ) {\r
+ vertex[1] = v1;\r
+ vertex[2] = wv1[0];\r
+ vertex[3] = wv2[0];\r
+ }\r
+ else {\r
+ return false;\r
+ }\r
+ }\r
+ else {\r
+ return false;\r
+ }\r
+\r
+ i_marker_info2.vertex[0] = vertex[0];\r
+ i_marker_info2.vertex[1] = vertex[1];\r
+ i_marker_info2.vertex[2] = vertex[2];\r
+ i_marker_info2.vertex[3] = vertex[3];\r
+ i_marker_info2.vertex[4] = i_marker_info2.coord_num-1;\r
+\r
+ return true;\r
+ }\r
+ /**\r
+ * int arGetContour( ARInt16 *limage, int *label_ref,int label, int clip[4], ARMarkerInfo2 *marker_info2 )\r
+ * 関数の代替品 \r
+ * @param limage\r
+ * @param label_ref\r
+ * @param label\r
+ * @param clip\r
+ * @return\r
+ * 検出したマーカーからマーカーオブジェクトを生成して返す。\r
+ * @throws NyARException\r
+ */\r
+ private NyARMarker arGetContour(short[][] limage, int[] label_ref,int label, int[] clip) throws NyARException\r
+ {\r
+ final int[] xdir={0, 1, 1, 1, 0,-1,-1,-1}; //static int xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1};\r
+ final int[] ydir={-1,-1, 0, 1, 1, 1, 0,-1};//static int ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1};\r
+ //ShortPointer p1;//ARInt16 *p1;\r
+ int sx=0, sy=0, dir;\r
+ int dmax, d, v1=0;\r
+ int i, j;\r
+ \r
+// JartkException.trap("未チェックのパス");\r
+ j = clip[2];\r
+ //p1=ShortPointer.wrap(limage,j*xsize+clip.get());//p1 = &(limage[j*xsize+clip[0]]);\r
+ for( i = clip[0]; i <= clip[1]; i++){//for( i = clip[0]; i <= clip[1]; i++, p1++ ) {\r
+ if(limage[j][i] > 0 && label_ref[(limage[j][i])-1] == label ) {//if( *p1 > 0 && label_ref[(*p1)-1] == label ) {\r
+ sx = i; sy = j;\r
+ break;\r
+ }\r
+ }\r
+ if(i> clip[1]){//if( i > clip[1] ) {\r
+ System.out.println("??? 1");//printf();\r
+ throw new NyARException();//return(-1);\r
+ }\r
+ \r
+ NyARMarker marker_info2=new NyARMarker();\r
+ \r
+ marker_info2.coord_num=1;//marker_info2->coord_num = 1;\r
+ marker_info2.x_coord[0]=sx;//marker_info2->x_coord[0] = sx;\r
+ marker_info2.y_coord[0]=sy;//marker_info2->y_coord[0] = sy;\r
+ dir = 5;\r
+ \r
+ for(;;){\r
+ int r=marker_info2.y_coord[marker_info2.coord_num-1];\r
+ int c=marker_info2.x_coord[marker_info2.coord_num-1];\r
+ //p1 = &(limage[marker_info2->y_coord[marker_info2->coord_num-1] * xsize+ marker_info2->x_coord[marker_info2->coord_num-1]]);\r
+ dir = (dir+5)%8;\r
+ for(i=0;i<8;i++) {\r
+ if(limage[r+ydir[dir]][c+xdir[dir]]>0){//if( p1[ydir[dir]*xsize+xdir[dir]] > 0 ){\r
+ break;\r
+ }\r
+ dir = (dir+1)%8; \r
+ }\r
+ if( i == 8 ){\r
+ System.out.println("??? 2");//printf("??? 2\n");\r
+ throw new NyARException();//return(-1);\r
+ }\r
+ marker_info2.x_coord[marker_info2.coord_num]= marker_info2.x_coord[marker_info2.coord_num-1] + xdir[dir];//marker_info2->x_coord[marker_info2->coord_num]= marker_info2->x_coord[marker_info2->coord_num-1] + xdir[dir];\r
+ marker_info2.y_coord[marker_info2.coord_num]= marker_info2.y_coord[marker_info2.coord_num-1] + ydir[dir];//marker_info2->y_coord[marker_info2->coord_num]= marker_info2->y_coord[marker_info2->coord_num-1] + ydir[dir];\r
+ if( marker_info2.x_coord[marker_info2.coord_num] == sx && marker_info2.y_coord[marker_info2.coord_num] == sy ){\r
+ break;\r
+ }\r
+ marker_info2.coord_num++;\r
+ if( marker_info2.coord_num == marker_info2.x_coord.length-1){//if( marker_info2.coord_num == Config.AR_CHAIN_MAX-1 ){\r
+ System.out.println("??? 3");//printf("??? 3\n");\r
+ throw new NyARException();//return(-1);\r
+ }\r
+ }\r
+ \r
+ dmax = 0;\r
+ for(i=1;i<marker_info2.coord_num;i++) {// for(i=1;i<marker_info2->coord_num;i++) {\r
+ d = (marker_info2.x_coord[i]-sx)*(marker_info2.x_coord[i]-sx)+ (marker_info2.y_coord[i]-sy)*(marker_info2.y_coord[i]-sy);// d = (marker_info2->x_coord[i]-sx)*(marker_info2->x_coord[i]-sx)+ (marker_info2->y_coord[i]-sy)*(marker_info2->y_coord[i]-sy);\r
+ if( d > dmax ) {\r
+ dmax = d;\r
+ v1 = i;\r
+ }\r
+ }\r
+\r
+ int[] wx=new int[v1];//new int[Config.AR_CHAIN_MAX];\r
+ int[] wy=new int[v1]; //new int[Config.AR_CHAIN_MAX]; \r
+ for(i=0;i<v1;i++) {\r
+ wx[i] = marker_info2.x_coord[i];//wx[i] = marker_info2->x_coord[i];\r
+ wy[i] = marker_info2.y_coord[i];//wy[i] = marker_info2->y_coord[i];\r
+ }\r
+ for(i=v1;i<marker_info2.coord_num;i++) {//for(i=v1;i<marker_info2->coord_num;i++) {\r
+ marker_info2.x_coord[i-v1] = marker_info2.x_coord[i];//marker_info2->x_coord[i-v1] = marker_info2->x_coord[i];\r
+ marker_info2.y_coord[i-v1] = marker_info2.y_coord[i];//marker_info2->y_coord[i-v1] = marker_info2->y_coord[i];\r
+ }\r
+ for(i=0;i<v1;i++) {\r
+ marker_info2.x_coord[i-v1+marker_info2.coord_num] = wx[i];//marker_info2->x_coord[i-v1+marker_info2->coord_num] = wx[i];\r
+ marker_info2.y_coord[i-v1+marker_info2.coord_num] = wy[i];//marker_info2->y_coord[i-v1+marker_info2->coord_num] = wy[i];\r
+ }\r
+ marker_info2.x_coord[marker_info2.coord_num] = marker_info2.x_coord[0];//marker_info2->x_coord[marker_info2->coord_num] = marker_info2->x_coord[0];\r
+ marker_info2.y_coord[marker_info2.coord_num] = marker_info2.y_coord[0];//marker_info2->y_coord[marker_info2->coord_num] = marker_info2->y_coord[0];\r
+ marker_info2.coord_num++;//marker_info2->coord_num++;\r
+ \r
+ return marker_info2;\r
+ }\r
+ /**\r
+ * ARMarkerInfo2 *arDetectMarker2( ARInt16 *limage, int label_num, int *label_ref,int *warea, double *wpos, int *wclip,int area_max, int area_min, double factor, int *marker_num )\r
+ * 関数の代替品\r
+ * ラベリング情報からマーカー一覧を作成して、保持する。\r
+ * @param i_labeling\r
+ * ラベリング済みの情報を持つラベリングオブジェクト\r
+ * @param area_max\r
+ * 何かの閾値?\r
+ * @param area_min\r
+ * 何かの閾値?\r
+ * @param factor\r
+ * 何かの閾値?\r
+ * @return\r
+ * @throws NyARException\r
+ */\r
+// public void detectMarker(short[][] limage,int label_num,int[] label_ref,int[] warea,double[] wpos,int[] wclip,int area_max, int area_min, double factor) throws JartkException\r
+ public void detectMarker(NyARLabeling i_labeling,double factor) throws NyARException\r
+ {\r
+ int xsize, ysize;\r
+ int marker_num2;\r
+ int i, j;\r
+ double d;\r
+ int[] warea =i_labeling.getArea();\r
+ int label_num =i_labeling.getLabelNum();\r
+ int[][] wclip =i_labeling.getClip();\r
+ double[] wpos =i_labeling.getPos();\r
+ short[][] limage =i_labeling.getLabelImg();\r
+ int[] label_ref =i_labeling.getLabelRef();\r
+ \r
+ marker_num=0;\r
+ xsize =width;\r
+ ysize =height;\r
+ \r
+ marker_num2 = 0;\r
+ for(i=0; i<label_num; i++ ) {\r
+ if( warea[i] < area_min || warea[i] > area_max ){\r
+ continue;\r
+ }\r
+ if( wclip[i][0] == 1 || wclip[i][1] == xsize-2 ){//if( wclip[i*4+0] == 1 || wclip[i*4+1] == xsize-2 ){\r
+ continue;\r
+ }\r
+ if( wclip[i][2] == 1 || wclip[i][3] == ysize-2 ){//if( wclip[i*4+2] == 1 || wclip[i*4+3] == ysize-2 ){\r
+ continue;\r
+ }\r
+ //ret = arGetContour( limage, label_ref, i+1,&(wclip[i*4]), &(marker_info2[marker_num2]));\r
+ marker_info2_array[marker_num2]=arGetContour( limage, label_ref, i+1,wclip[i]);\r
+ \r
+ boolean ret = check_square( warea[i], marker_info2_array[marker_num2], factor );//ret = check_square( warea[i], &(marker_info2[marker_num2]), factor );\r
+ if(!ret){\r
+ marker_info2_array[marker_num2]=null;\r
+ continue;\r
+ }\r
+ marker_info2_array[marker_num2].area = warea[i];\r
+ marker_info2_array[marker_num2].pos[0] = wpos[i*2+0];\r
+ marker_info2_array[marker_num2].pos[1] = wpos[i*2+1];\r
+ marker_num2++;\r
+ //マーカーリストが上限に達した\r
+ if( marker_num2 == marker_info2_array.length){\r
+ break;\r
+ }\r
+ }\r
+ for( i=0; i < marker_num2; i++ ) {\r
+ for( j=i+1; j < marker_num2; j++ ) {\r
+ d = (marker_info2_array[i].pos[0] - marker_info2_array[j].pos[0])*\r
+ (marker_info2_array[i].pos[0] - marker_info2_array[j].pos[0])+\r
+ (marker_info2_array[i].pos[1] - marker_info2_array[j].pos[1])*\r
+ (marker_info2_array[i].pos[1] - marker_info2_array[j].pos[1]);\r
+ if(marker_info2_array[i].area >marker_info2_array[j].area ) {\r
+ if( d <marker_info2_array[i].area / 4 ) {\r
+ marker_info2_array[j].area = 0;\r
+ }\r
+ }else{\r
+ if( d < marker_info2_array[j].area / 4 ) {\r
+ marker_info2_array[i].area = 0;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ for( i=0; i < marker_num2; i++ ) {\r
+ if( marker_info2_array[i].area == 0.0 ) {\r
+ for( j=i+1; j < marker_num2; j++ ) {\r
+ marker_info2_array[j-1] = marker_info2_array[j];\r
+ }\r
+ marker_num2--;\r
+ }\r
+ }\r
+ //発見したマーカー数をセット\r
+ marker_num=marker_num2;//*marker_num = marker_num2;\r
+ //return( &(marker_info2[0]) );\r
+ }\r
+\r
+}\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core;\r
+\r
+import jp.nyatla.util.DoubleValue;\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.*;\r
+\r
+\r
+public class NyARDetectSquare{\r
+ private NyARLabeling labeling;\r
+ private NyARDetectMarker detect;\r
+\r
+ private NyARSquare[] marker_info;\r
+ private int number_of_square;\r
+ private NyARParam param;\r
+\r
+ /**\r
+ * 最大i_sqaure_max個のマーカー情報を抽出できるインスタンスを作る。\r
+ * @param i_sqaure_max\r
+ */\r
+ public NyARDetectSquare(int i_sqaure_max,NyARParam i_param)\r
+ {\r
+ param=i_param;\r
+ marker_info=new NyARSquare[i_sqaure_max];//static ARMarkerInfo marker_infoL[AR_SQUARE_MAX];\r
+ //解析オブジェクトを作る\r
+ int width=i_param.getX();\r
+ int height=i_param.getY();\r
+\r
+ labeling=new NyARLabeling(width,height);\r
+ detect=new NyARDetectMarker(width,height,i_sqaure_max);\r
+ }\r
+ public NyARSquare[] getSquareArray()\r
+ {\r
+ return marker_info;\r
+ }\r
+ public int getSquareCount()\r
+ {\r
+ return number_of_square;\r
+ }\r
+ /**\r
+ * 矩形を検出する。\r
+ * @param i_marker\r
+ * @param i_number_of_marker\r
+ * @throws NyARException\r
+ */\r
+ public void detectSquare(NyARRaster i_image,int i_thresh) throws NyARException\r
+ {\r
+ number_of_square=0;\r
+ labeling.labeling(i_image, i_thresh);\r
+ if(labeling.getLabelNum()<1){\r
+ return;\r
+ }\r
+ detect.detectMarker(labeling,1.0);\r
+ NyARMarker[] marker=detect.getMarkerArray();\r
+ int number_of_marker=detect.getMarkerNum();\r
+\r
+\r
+ \r
+ int j=0;\r
+ for (int i = 0; i <number_of_marker; i++){\r
+ double[][] line =new double[4][3];\r
+ double[][] vertex =new double[4][2];\r
+ \r
+ //・・・線の検出??\r
+ if (!getLine(marker[i].x_coord, marker[i].y_coord,marker[i].coord_num, marker[i].vertex,line,vertex))\r
+ {\r
+ continue;\r
+ }\r
+ marker_info[j]=new NyARSquare(marker[i],line,vertex);\r
+\r
+ \r
+//ここで計算するのは良くないと思うんだ \r
+// marker_infoL[j].id = id.get();\r
+// marker_infoL[j].dir = dir.get();\r
+// marker_infoL[j].cf = cf.get(); \r
+ j++;\r
+ //配列数こえたらドゴォォォンしないようにループを抜ける\r
+ if(j>=marker_info.length){\r
+ break;\r
+ }\r
+ }\r
+ number_of_square=j;\r
+ }\r
+ /**\r
+ * arGetLine(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[4][3], double v[4][2])\r
+ * arGetLine2(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[4][3], double v[4][2], double *dist_factor)\r
+ * の2関数の合成品です。\r
+ * @param x_coord\r
+ * @param y_coord\r
+ * @param coord_num\r
+ * @param vertex\r
+ * @param line\r
+ * @param v\r
+ * @return\r
+ * @throws NyARException\r
+ */\r
+ private boolean getLine(int x_coord[], int y_coord[], int coord_num,int vertex[], double line[][], double v[][]) throws NyARException\r
+ {\r
+ NyARMat input,evec;\r
+ NyARVec ev,mean;\r
+ double w1;\r
+ int st, ed, n;\r
+ int i, j;\r
+ DoubleValue dv1=new DoubleValue();\r
+ DoubleValue dv2=new DoubleValue();\r
+ \r
+ ev = new NyARVec(2);\r
+ mean = new NyARVec(2);\r
+ evec = new NyARMat(2,2);\r
+ double[] mean_array=mean.getArray();\r
+ double[][] evec_array=evec.getArray();\r
+ for( i = 0; i < 4; i++ ) {\r
+ w1 = (double)(vertex[i+1]-vertex[i]+1) * 0.05 + 0.5;\r
+ st = (int)(vertex[i] + w1);\r
+ ed = (int)(vertex[i+1] - w1);\r
+ n = ed - st + 1;\r
+ if(n<2){//nが2以下でmatrix.PCAを計算することはできないので、エラーにしておく。\r
+ //System.err.println("NyARDetectSquare::getLine 稀に出るエラーです。このエラーが出ても例外が起こらなければ平気だと思いますが、出たらnyatlaまで連絡してください。");\r
+ return false;//throw new NyARException();\r
+ }\r
+ input = new NyARMat( n, 2 );\r
+ double [][] in_array=input.getArray();\r
+ for( j = 0; j < n; j++ ) {\r
+ param.observ2Ideal(x_coord[st+j], y_coord[st+j],dv1,dv2);//arParamObserv2Ideal( dist_factor, x_coord[st+j], y_coord[st+j],&(input->m[j*2+0]), &(input->m[j*2+1]) );\r
+ in_array[j][0]=dv1.get();\r
+ in_array[j][1]=dv2.get();\r
+ }\r
+ NyARMat.matrixPCA(input, evec, ev, mean);\r
+ \r
+ line[i][0] = evec_array[0][1];//line[i][0] = evec->m[1];\r
+ line[i][1] = -evec_array[0][0];//line[i][1] = -evec->m[0];\r
+ line[i][2] = -(line[i][0]*mean_array[0] + line[i][1]*mean_array[1]);//line[i][2] = -(line[i][0]*mean->v[0] + line[i][1]*mean->v[1]);\r
+ }\r
+ \r
+ for( i = 0; i < 4; i++ ) {\r
+ w1 = line[(i+3)%4][0] * line[i][1] - line[i][0] * line[(i+3)%4][1];\r
+ if( w1 == 0.0 ){\r
+ return false;\r
+ }\r
+ v[i][0] = ( line[(i+3)%4][1] * line[i][2]- line[i][1] * line[(i+3)%4][2] ) / w1;\r
+ v[i][1] = ( line[i][0] * line[(i+3)%4][2]- line[(i+3)%4][0] * line[i][2] ) / w1;\r
+ }\r
+ return true;\r
+ }\r
+}\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.*;\r
+\r
+\r
+\r
+\r
+/**\r
+ * ラベリングクラス。NyARRasterをラベリングして、結果値を保持します。\r
+ *\r
+ */\r
+public class NyARLabeling{\r
+ private final int WORK_SIZE=1024*32;//#define WORK_SIZE 1024*32\r
+ private short[][] label_img;//static ARInt16 l_imageL[HARDCODED_BUFFER_WIDTH*HARDCODED_BUFFER_HEIGHT];\r
+ private int[] work=new int[WORK_SIZE];//static int workL[WORK_SIZE];\r
+ private int[] work2=new int[WORK_SIZE*7];//static int work2L[WORK_SIZE*7];\r
+ private int[] area=new int[WORK_SIZE];//static int wareaL[WORK_SIZE];\r
+ private int[][] clip=new int[WORK_SIZE][4];//static int wclipL[WORK_SIZE*4];\r
+ private double[] pos=new double[WORK_SIZE*2];//static double wposL[WORK_SIZE*2];\r
+ private int label_num;\r
+ //\r
+ private int width;\r
+ private int height;\r
+ /**\r
+ * @param i_width\r
+ * ラベリング画像の幅。解析するラスタの幅より大きいこと。\r
+ * @param i_height\r
+ * ラベリング画像の高さ。解析するラスタの高さより大きいこと。\r
+ */\r
+ public NyARLabeling(int i_width,int i_height)\r
+ {\r
+ width =i_width;\r
+ height=i_height;\r
+ label_img=new short[height][width];\r
+ label_num=0;\r
+ }\r
+ /**\r
+ * 検出したラベルの数を返す\r
+ * @return\r
+ */\r
+ public int getLabelNum()\r
+ {\r
+ return label_num;\r
+ }\r
+ /**\r
+ * わからん\r
+ * @return\r
+ * @throws NyARException\r
+ */\r
+ public int[] getLabelRef() throws NyARException\r
+ {\r
+ if(label_num<1){\r
+ throw new NyARException();\r
+ }\r
+ return work;\r
+ }\r
+ /**\r
+ * 検出したエリア配列?よくわからぬ\r
+ * @return\r
+ * @throws NyARException\r
+ */\r
+ public int[] getArea() throws NyARException\r
+ {\r
+ if(label_num<1){\r
+ throw new NyARException();\r
+ }\r
+ return area;\r
+ }\r
+ /**\r
+ * 検出したクリップ配列?よくわからぬ\r
+ * @return\r
+ * @throws NyARException\r
+ */\r
+ public int[][] getClip() throws NyARException\r
+ {\r
+ if(label_num<1){\r
+ throw new NyARException();\r
+ }\r
+ return clip;\r
+ }\r
+ /**\r
+ * 検出した位置配列?よくわからぬ\r
+ * @return\r
+ * @throws NyARException\r
+ */\r
+ public double[] getPos() throws NyARException\r
+ {\r
+ if(label_num<1){\r
+ throw new NyARException();\r
+ }\r
+ return pos;\r
+ }\r
+ /**\r
+ * ラベリング済みイメージを返す\r
+ * @return\r
+ * @throws NyARException\r
+ */\r
+ public short[][] getLabelImg() throws NyARException\r
+ {\r
+ if(label_num<1){\r
+ throw new NyARException();\r
+ }\r
+ return label_img;\r
+ }\r
+ /**\r
+ * 配列の先頭からsize個をゼロクリアする\r
+ * @param array\r
+ * @param size\r
+ */\r
+ private void putZero(int[] array,int size)\r
+ {\r
+ for(int i=0;i<size;i++){\r
+ array[i]=0;\r
+ }\r
+ }\r
+ /**\r
+ * 配列の先頭からsize個をゼロクリアする\r
+ * @param array\r
+ * @param size\r
+ */\r
+ private void putZero(double[] array,int size)\r
+ {\r
+ for(int i=0;i<size;i++){\r
+ array[i]=0;\r
+ }\r
+ }\r
+ /**\r
+ * static ARInt16 *labeling2( ARUint8 *image, int thresh,int *label_num, int **area, double **pos, int **clip,int **label_ref, int LorR )\r
+ * 関数の代替品\r
+ * ラスタimageをラベリングして、結果を保存します。\r
+ * @param image\r
+ * @param thresh\r
+ * @throws NyARException\r
+ */\r
+ public void labeling(NyARRaster image,int thresh) throws NyARException\r
+ {\r
+ int wk_max; /* work */\r
+ int m,n; /* work */\r
+ int lxsize, lysize;\r
+ int[] warea;//int *warea;\r
+ int[][] wclip;//int *wclip;\r
+ double[] wpos;//double *wpos;\r
+ int thresht3 = thresh * 3;\r
+ \r
+ //ラベル数を0に初期化\r
+ label_num=0;\r
+ \r
+ warea=area;//warea = &wareaL[0];\r
+ wclip=clip;//wclip = &wclipL[0];\r
+ wpos=pos;//wpos = &wposL[0];\r
+ \r
+ lxsize=image.getWidth();//lxsize = arUtil_c.arImXsize;\r
+ lysize=image.getHeight();//lysize = arUtil_c.arImYsize;\r
+ \r
+ for(int i = 0; i < lxsize; i++){\r
+ label_img[0][i]=0;\r
+ label_img[lysize-1][i]=0;\r
+ }\r
+ for(int i = 0; i < lysize; i++) {\r
+ label_img[i][0]=0;\r
+ label_img[i][lxsize-1]=0; \r
+ }\r
+ int nya_pnt_start_x_start,nya_pnt_start_y_start;\r
+ int nya_poff_step;//スキャンステップ\r
+\r
+ wk_max = 0;\r
+ nya_pnt_start_y_start=1;\r
+ nya_pnt_start_x_start=1;\r
+ nya_poff_step=1;//スキャンステップ\r
+ int nya_pnt_start_y=nya_pnt_start_y_start;\r
+ for (int j = 1; j < lysize - 1; j++, nya_pnt_start_y++) {//for (int j = 1; j < lysize - 1; j++, pnt += poff*2, pnt2 += 2) {\r
+ int nya_pnt_start_x=nya_pnt_start_x_start;\r
+ int p1=j-1;\r
+ int p2=j;\r
+ for(int i = 1; i < lxsize-1; i++, nya_pnt_start_x+=nya_poff_step) {//for(int i = 1; i < lxsize-1; i++, pnt+=poff, pnt2++) {\r
+ //RGBの合計値が閾値より大きいかな?\r
+ if(image.getPixcelTotal(nya_pnt_start_x,nya_pnt_start_y)<=thresht3){\r
+ //pnt1 = ShortPointer.wrap(pnt2, -lxsize);//pnt1 = &(pnt2[-lxsize]);\r
+ if(label_img[p1][i]>0){//if( *pnt1 > 0 ) {\r
+ label_img[p2][i]=label_img[p1][i];//*pnt2 = *pnt1;\r
+\r
+\r
+ int p2_index=(label_img[p2][i]-1)*7;\r
+ work2[p2_index+0]++;//work2[((*pnt2)-1)*7+0] ++;\r
+ work2[p2_index+1]+=i;//work2[((*pnt2)-1)*7+1] += i;\r
+ work2[p2_index+2]+=j;//work2[((*pnt2)-1)*7+2] += j;\r
+ work2[p2_index+6]=j;//work2[((*pnt2)-1)*7+6] = j;\r
+ }else if(label_img[p1][i+1]> 0 ) {//}else if( *(pnt1+1) > 0 ) {\r
+ if(label_img[p1][i-1] > 0 ) {//if( *(pnt1-1) > 0 ) {\r
+ m = work[label_img[p1][i+1]-1];//m = work[*(pnt1+1)-1];\r
+ n = work[label_img[p1][i-1]-1];//n = work[*(pnt1-1)-1];\r
+ if( m > n ){\r
+ //JartkException.trap("未チェックのパス");\r
+ label_img[p2][i]=(short)n;//*pnt2 = n;\r
+ //wk=IntPointer.wrap(work, 0);//wk = &(work[0]);\r
+ for(int k = 0; k < wk_max; k++) {\r
+ //JartkException.trap("未チェックのパス");\r
+ if(work[k] == m ){//if( *wk == m ) \r
+ //JartkException.trap("未チェックのパス");\r
+ work[k]=n;//*wk = n;\r
+ }\r
+ }\r
+ }else if( m < n ) {\r
+ //JartkException.trap("未チェックのパス");\r
+ label_img[p2][i]=(short)m;//*pnt2 = m;\r
+ //wk=IntPointer.wrap(work,0);//wk = &(work[0]);\r
+ for(int k = 0; k < wk_max; k++){\r
+ //JartkException.trap("未チェックのパス");\r
+ if(work[k]==n){//if( *wk == n ){\r
+ //JartkException.trap("未チェックのパス");\r
+ work[k]=m;//*wk = m;\r
+ }\r
+ }\r
+ }else{\r
+ label_img[p2][i]=(short)m;//*pnt2 = m;\r
+ }\r
+\r
+ int p2_index=(label_img[p2][i]-1)*7;\r
+ work2[p2_index+0] ++;\r
+ work2[p2_index+1] += i;\r
+ work2[p2_index+2] += j;\r
+ work2[p2_index+6] = j;\r
+ }else if( (label_img[p2][i-1]) > 0 ) {//}else if( *(pnt2-1) > 0 ) {\r
+ m = work[(label_img[p1][i+1])-1];//m = work[*(pnt1+1)-1];\r
+ n = work[(label_img[p2][i-1])-1];//n = work[*(pnt2-1)-1];\r
+ if( m > n ) {\r
+\r
+ label_img[p2][i]=(short)n;//*pnt2 = n;\r
+ for(int k = 0; k < wk_max; k++) {\r
+ if(work[k]==m){//if( *wk == m ){\r
+ work[k]=n;//*wk = n;\r
+ }\r
+ }\r
+ }else if( m < n ) {\r
+ label_img[p2][i]=(short)m;//*pnt2 = m;\r
+ for(int k = 0; k < wk_max; k++) {\r
+ if(work[k]==n){//if( *wk == n ){\r
+ work[k]=m;//*wk = m;\r
+ }\r
+ }\r
+ }else{\r
+ label_img[p2][i]=(short)m;//*pnt2 = m;\r
+ }\r
+\r
+\r
+ int p2_index=((label_img[p2][i])-1)*7;\r
+ work2[p2_index+0] ++;//work2[((*pnt2)-1)*7+0] ++;\r
+ work2[p2_index+1] += i;//work2[((*pnt2)-1)*7+1] += i;\r
+ work2[p2_index+2] += j;//work2[((*pnt2)-1)*7+2] += j;\r
+ }else{\r
+\r
+ label_img[p2][i]=label_img[p1][i+1];//*pnt2 = *(pnt1+1);\r
+ \r
+ int p2_index=((label_img[p2][i])-1)*7;\r
+ work2[p2_index+0] ++;//work2[((*pnt2)-1)*7+0] ++;\r
+ work2[p2_index+1] += i;//work2[((*pnt2)-1)*7+1] += i;\r
+ work2[p2_index+2] += j;//work2[((*pnt2)-1)*7+2] += j;\r
+ if( work2[p2_index+3] > i ){//if( work2[((*pnt2)-1)*7+3] > i ){ \r
+ work2[p2_index+3] = i;// work2[((*pnt2)-1)*7+3] = i;\r
+ }\r
+ work2[p2_index+6] = j;//work2[((*pnt2)-1)*7+6] = j;\r
+ }\r
+ }else if( (label_img[p1][i-1]) > 0 ) {//}else if( *(pnt1-1) > 0 ) {\r
+ label_img[p2][i]=label_img[p1][i-1];//*pnt2 = *(pnt1-1);\r
+\r
+ int p2_index=((label_img[p2][i])-1)*7;\r
+ work2[p2_index+0] ++;//work2[((*pnt2)-1)*7+0] ++;\r
+ work2[p2_index+1] += i;//work2[((*pnt2)-1)*7+1] += i;\r
+ work2[p2_index+2] += j;//work2[((*pnt2)-1)*7+2] += j;\r
+ if( work2[p2_index+4] < i ){//if( work2[((*pnt2)-1)*7+4] < i ){\r
+ work2[p2_index+4] = i;// work2[((*pnt2)-1)*7+4] = i;\r
+ }\r
+ work2[p2_index+6] = j;//work2[((*pnt2)-1)*7+6] = j;\r
+ }else if(label_img[p2][i-1] > 0) {//}else if( *(pnt2-1) > 0) {\r
+ label_img[p2][i]=label_img[p2][i-1];//*pnt2 = *(pnt2-1);\r
+\r
+ int p2_index=((label_img[p2][i])-1)*7;\r
+ work2[p2_index+0] ++;//work2[((*pnt2)-1)*7+0] ++;\r
+ work2[p2_index+1] += i;//work2[((*pnt2)-1)*7+1] += i;\r
+ work2[p2_index+2] += j;//work2[((*pnt2)-1)*7+2] += j;\r
+ if( work2[p2_index+4] < i ){//if( work2[((*pnt2)-1)*7+4] < i ){\r
+ work2[p2_index+4] = i;// work2[((*pnt2)-1)*7+4] = i;\r
+ }\r
+ }else{\r
+ wk_max++;\r
+ if( wk_max > WORK_SIZE ) {\r
+ throw new NyARException();//return (0);\r
+ }\r
+ work[wk_max-1] = wk_max;label_img[p2][i]=(short)wk_max;//work[wk_max-1] = *pnt2 = wk_max;\r
+ work2[(wk_max-1)*7+0] = 1;\r
+ work2[(wk_max-1)*7+1] = i;\r
+ work2[(wk_max-1)*7+2] = j;\r
+ work2[(wk_max-1)*7+3] = i;\r
+ work2[(wk_max-1)*7+4] = i;\r
+ work2[(wk_max-1)*7+5] = j;\r
+ work2[(wk_max-1)*7+6] = j;\r
+ }\r
+ }else {\r
+ label_img[p2][i]=0;//*pnt2 = 0;\r
+ }\r
+ }\r
+ }\r
+ int j = 1;\r
+ for(int i = 0; i < wk_max; i++){//for(int i = 1; i <= wk_max; i++, wk++) {\r
+ work[i]=(work[i]==i+1)? j++: work[work[i]-1];//*wk = (*wk==i)? j++: work[(*wk)-1];\r
+ }\r
+ \r
+ int wlabel_num=j - 1;//*label_num = *wlabel_num = j - 1;\r
+\r
+ if(wlabel_num==0){//if( *label_num == 0 ) {\r
+ //発見数0\r
+ return;\r
+ }\r
+\r
+ putZero(warea,wlabel_num);//put_zero( (ARUint8 *)warea, *label_num * sizeof(int) );\r
+ putZero(wpos,wlabel_num*2);//put_zero( (ARUint8 *)wpos, *label_num * 2 * sizeof(double) );\r
+ for(int i = 0; i < wlabel_num; i++) {//for(i = 0; i < *label_num; i++) {\r
+ wclip[i][0] = lxsize;//wclip[i*4+0] = lxsize;\r
+ wclip[i][1] = 0;//wclip[i*4+1] = 0;\r
+ wclip[i][2] = lysize;//wclip[i*4+2] = lysize;\r
+ wclip[i][3] = 0;//wclip[i*4+3] = 0;\r
+ }\r
+ for(int i = 0; i < wk_max; i++) {\r
+ j = work[i] - 1;\r
+ warea[j] += work2[i*7+0];\r
+ wpos[j*2+0] += work2[i*7+1];\r
+ wpos[j*2+1] += work2[i*7+2];\r
+ if( wclip[j][0] > work2[i*7+3] ){\r
+ wclip[j][0] = work2[i*7+3];\r
+ }\r
+ if( wclip[j][1] < work2[i*7+4] ){\r
+ wclip[j][1] = work2[i*7+4];\r
+ }\r
+ if( wclip[j][2] > work2[i*7+5] ){\r
+ wclip[j][2] = work2[i*7+5];\r
+ }\r
+ if( wclip[j][3] < work2[i*7+6] ){\r
+ wclip[j][3] = work2[i*7+6];\r
+ }\r
+ }\r
+\r
+ for(int i = 0; i < wlabel_num; i++ ) {//for(int i = 0; i < *label_num; i++ ) {\r
+ wpos[i*2+0] /= warea[i];\r
+ wpos[i*2+1] /= warea[i];\r
+ }\r
+ \r
+ label_num=wlabel_num;\r
+ return;\r
+ }\r
+}\r
+\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core;\r
+\r
+\r
+\r
+\r
+\r
+/**\r
+ * typedef struct {\r
+ * int area;\r
+ * double pos[2];\r
+ * int coord_num;\r
+ * int x_coord[AR_CHAIN_MAX];\r
+ * int y_coord[AR_CHAIN_MAX];\r
+ * int vertex[5];\r
+ * } ARMarkerInfo2;\r
+ * \r
+ */\r
+class NyARMarker\r
+{\r
+ private static final int AR_CHAIN_MAX=10000;\r
+ int area;\r
+ double[] pos=new double[2];\r
+ int coord_num;\r
+ int[] x_coord=new int[AR_CHAIN_MAX];\r
+ int[] y_coord=new int[AR_CHAIN_MAX];\r
+ int[] vertex=new int[5];\r
+}\r
+\r
+\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+\r
+ \r
+\r
+/**\r
+ * ARMat構造体に対応するクラス\r
+ * typedef struct {\r
+ * double *m;\r
+ * int row;\r
+ * int clm;\r
+ * }ARMat;\r
+ *\r
+ */\r
+public class NyARMat{\r
+ private double[][] m;\r
+ private int clm,row;\r
+ public NyARMat(int i_row,int i_clm)\r
+ {\r
+ m=new double[i_row][i_clm];\r
+ clm=i_clm;\r
+ row=i_row;\r
+ }\r
+ public int getClm()\r
+ {\r
+ return clm;\r
+ }\r
+ public int getRow()\r
+ {\r
+ return row;\r
+ }\r
+ /**\r
+ * 行列をゼロクリアする。\r
+ */\r
+ public void zeroClear()\r
+ {\r
+ for(int i=0;i<row;i++){\r
+ for(int i2=0;i2<clm;i2++){\r
+ m[i][i2]=0.0;\r
+ }\r
+ }\r
+ }\r
+ public double[] getRowArray(int i_row)\r
+ {\r
+ return m[i_row];\r
+ }\r
+ public double[][] getArray()\r
+ {\r
+ return m;\r
+ }\r
+ public NyARVec getRowVec(int i_row)\r
+ {\r
+ return NyARVec.wrap(m[i_row]);\r
+ }\r
+ /**\r
+ * aとbの積をdestに出力する。arMatrixMul()の代替品\r
+ * @param dest\r
+ * @param a\r
+ * @param b\r
+ * @throws NyARException\r
+ */\r
+ public static void matrixMul(NyARMat dest, NyARMat a, NyARMat b) throws NyARException\r
+ {\r
+ if(a.clm != b.row || dest.row != a.row || dest.clm != b.clm){\r
+ throw new NyARException();\r
+ }\r
+ for(int r = 0; r < dest.row; r++){\r
+ for(int c = 0; c < dest.getClm(); c++){\r
+ dest.m[r][c]=0.0;//dest.setARELEM0(r, c,0.0);\r
+ for(int i = 0; i < a.getClm(); i++){\r
+ dest.m[r][c]+=a.m[r][i]*b.m[i][c];//ARELEM0(dest, r, c) += ARELEM0(a, r, i) * ARELEM0(b, i, c);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ /**\r
+ * i_targetを逆行列に変換する。arMatrixSelfInv()と、arMatrixSelfInv_minv()関数を合成してあります。\r
+ * @param i_target\r
+ * 逆行列にする行列\r
+ * @throws NyARException\r
+ */\r
+ public static void matrixSelfInv(NyARMat i_target) throws NyARException\r
+ {\r
+ double[][] ap=i_target.m;\r
+ int dimen=ap.length;\r
+ double[] wcp,wap,wbp;\r
+ int i,j,ip,nwork;\r
+ int[] nos=new int[50];\r
+ double epsl;\r
+ double p,pbuf,work;\r
+\r
+ epsl = 1.0e-10; /* Threshold value */\r
+ /* check size */\r
+ switch(dimen){\r
+ case 0:\r
+ throw new NyARException();\r
+ case 1:\r
+ ap[0][0]=1.0/ap[0][0];//*ap = 1.0 / (*ap);\r
+ return;/* 1 dimension */\r
+ }\r
+\r
+ for(int n = 0; n < dimen ; n++){\r
+ nos[n] = n;\r
+ }\r
+\r
+ /* nyatla memo\r
+ * ipが定まらないで計算が行われる場合があるので挿入。\r
+ * ループ内で0初期化していいかが判らない。\r
+ */\r
+ ip=0;\r
+ int wap_ptr,wbp_ptr;\r
+ for(int n=0; n<dimen;n++)\r
+ {\r
+ wcp =ap[n];//wcp = ap + n * rowa;\r
+ p=0.0;\r
+ wap_ptr=0;//wap = DoublePointer.wrap(wcp);\r
+ for(i = n; i<dimen ; i++){//for(i = n, wap = wcp, p = 0.0; i < dimen ; i++, wap += rowa)\r
+ wap=ap[i];\r
+ if( p < ( pbuf = Math.abs(wap[0]))) {\r
+ p = pbuf;\r
+ ip = i;\r
+ }\r
+ }\r
+ if (p <= epsl){\r
+ return;\r
+ }\r
+\r
+ nwork = nos[ip];\r
+ nos[ip]= nos[n];\r
+ nos[n] = nwork;\r
+ \r
+ wap=ap[ip];\r
+ wbp=wcp;\r
+ wap_ptr=0;\r
+ wbp_ptr=0;\r
+ for(j=0; j< dimen ; j++){//for(j = 0, wap = ap + ip * rowa, wbp = wcp; j < dimen ; j++) {\r
+ work = wap[wap_ptr]; //work = *wap;\r
+ wap[wap_ptr]=wbp[wbp_ptr];wap_ptr++;//*wap++ = *wbp;\r
+ wbp[wbp_ptr]=work;wbp_ptr++; //*wbp++ = work;\r
+ }\r
+ \r
+ wap=wcp;\r
+ wap_ptr=0;\r
+ work=wcp[0];\r
+ for(j = 1; j < dimen ; j++){//for(j = 1, wap = wcp, work = *wcp; j < dimen ; j++, wap++)\r
+ wap[wap_ptr]=wap[wap_ptr+1]/work;//*wap = *(wap + 1) / work;\r
+ wap_ptr++;\r
+ }\r
+ wap[wap_ptr]=1.0/work;//*wap = 1.0 / work;\r
+\r
+ for(i = 0; i < dimen ; i++) {\r
+ if(i != n) {\r
+ wap =ap[i];//wap = ap + i * rowa;\r
+ wbp =wcp;\r
+ wap_ptr=0;\r
+ wbp_ptr=0;\r
+ work=wap[0];\r
+ for(j = 1;j < dimen ; j++){//for(j = 1, wbp = wcp, work = *wap;j < dimen ; j++, wap++, wbp++)\r
+ wap[wap_ptr]=wap[wap_ptr+1]-work*wbp[wbp_ptr];//wap = *(wap + 1) - work * (*wbp);\r
+ wap_ptr++;\r
+ wbp_ptr++;\r
+ }\r
+ wap[wap_ptr]=-work*wbp[wbp_ptr];//*wap = -work * (*wbp);\r
+ }\r
+ }\r
+ }\r
+\r
+ for(int n = 0; n < dimen ; n++) {\r
+ for(j = n; j < dimen ; j++){\r
+ if( nos[j] == n){\r
+ break;\r
+ }\r
+ }\r
+ nos[j] = nos[n];\r
+ for(i = 0; i < dimen ;i++){//for(i = 0, wap = ap + j, wbp = ap + n; i < dimen ;i++, wap += rowa, wbp += rowa) {\r
+ wap=ap[i];\r
+ wbp=ap[i];\r
+ work =wap[j];//work = *wap;\r
+ wap[j]=wbp[n];//*wap = *wbp;\r
+ wbp[n]=work;//*wbp = work;\r
+ }\r
+ }\r
+ return;\r
+ }\r
+ /**\r
+ * sourceの転置行列をdestに得る。arMatrixTrans()の代替品\r
+ * @param dest\r
+ * @param source\r
+ * @return\r
+ */\r
+ public static void matrixTrans(NyARMat dest,NyARMat source) throws NyARException\r
+ {\r
+ if(dest.row != source.clm || dest.clm != source.row){\r
+ throw new NyARException();\r
+ }\r
+ NyARException.trap("未チェックのパス");\r
+ for(int r=0;r< dest.row;r++){\r
+ for(int c=0;c<dest.clm;c++){\r
+ dest.m[r][c]=source.m[c][r];\r
+ }\r
+ }\r
+ }\r
+ /**\r
+ * unitを単位行列に初期化する。arMatrixUnitの代替品\r
+ * @param unit\r
+ */\r
+ public static void matrixUnit(NyARMat unit) throws NyARException\r
+ {\r
+ if(unit.row != unit.clm){\r
+ throw new NyARException();\r
+ }\r
+ NyARException.trap("未チェックのパス");\r
+ for(int r = 0; r < unit.getRow(); r++) {\r
+ for(int c = 0; c < unit.getClm(); c++) {\r
+ if(r == c) {\r
+ unit.m[r][c]=1.0;\r
+ }else{\r
+ unit.m[r][c]=0.0;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ /**\r
+ * destにsourceと同じ内容をコピーする。arMatrixDupの代替品\r
+ * @param dest\r
+ * @param source\r
+ * @return\r
+ */\r
+ public static void matrixDup(NyARMat dest, NyARMat source) throws NyARException\r
+ {\r
+ if(dest.row != source.row || dest.clm != source.clm)\r
+ {\r
+ throw new NyARException();\r
+ }\r
+ for(int r = 0; r < source.getRow(); r++) {\r
+ for(int c = 0; c < source.getClm(); c++)\r
+ {\r
+ dest.m[r][c]=source.m[r][c];\r
+ }\r
+ }\r
+ }\r
+ public NyARMat matrixAllocDup() throws NyARException\r
+ {\r
+ NyARMat result=new NyARMat(row,clm);\r
+ matrixDup(result,this);\r
+ return result;\r
+ } \r
+ /**\r
+ * arMatrixInv関数の代替品です。\r
+ * destにsourceの逆行列を返します。\r
+ * @param dest\r
+ * @param source\r
+ * @throws NyARException\r
+ */\r
+ public static void matrixInv(NyARMat dest,NyARMat source) throws NyARException\r
+ {\r
+ NyARException.trap("未チェックのパス");\r
+ matrixDup(dest, source);\r
+\r
+ NyARException.trap("未チェックのパス");\r
+ matrixSelfInv(dest);\r
+ }\r
+ public NyARMat matrixAllocInv() throws NyARException\r
+ {\r
+ NyARException.trap("未チェックのパス");\r
+ NyARMat result=matrixAllocDup();\r
+\r
+ NyARException.trap("未チェックのパス");\r
+ matrixSelfInv(result);\r
+ return result;\r
+ }\r
+ /**\r
+ * dim x dim の単位行列を作る。\r
+ * @param dim\r
+ * @return\r
+ * @throws NyARException\r
+ */\r
+ public static NyARMat matrixAllocUnit(int dim) throws NyARException\r
+ {\r
+ NyARException.trap("未チェックのパス");\r
+ NyARMat result = new NyARMat(dim, dim);\r
+ NyARException.trap("未チェックのパス");\r
+ NyARMat.matrixUnit(result);\r
+ return result;\r
+ }\r
+ /**\r
+ * arMatrixDispの代替品\r
+ * @param m\r
+ * @return\r
+ */\r
+ public int matrixDisp() throws NyARException\r
+ {\r
+ NyARException.trap("未チェックのパス");\r
+ System.out.println(" === matrix ("+row+","+clm+") ===");//printf(" === matrix (%d,%d) ===\n", m->row, m->clm);\r
+ for(int r = 0; r < row; r++){//for(int r = 0; r < m->row; r++) {\r
+ System.out.print(" |");//printf(" |");\r
+ for(int c = 0; c < clm; c++) {//for(int c = 0; c < m->clm; c++) {\r
+ System.out.print(" "+m[r][c]);//printf(" %10g", ARELEM0(m, r, c));\r
+ }\r
+ System.out.println(" |");//printf(" |\n");\r
+ }\r
+ System.out.println(" ======================");//printf(" ======================\n");\r
+ return 0;\r
+ }\r
+ private final static double PCA_EPS=1e-6; //#define EPS 1e-6\r
+ private final static int PCA_MAX_ITER=100; //#define MAX_ITER 100\r
+ private final static double PCA_VZERO=1e-16; //#define VZERO 1e-16\r
+ /**\r
+ * static int EX( ARMat *input, ARVec *mean )の代替関数\r
+ * @param input\r
+ * @param mean\r
+ * @return\r
+ * @throws NyARException\r
+ */\r
+ private static void PCA_EX(NyARMat input, NyARVec mean) throws NyARException\r
+ {\r
+ double[] v;\r
+\r
+ int row, clm;\r
+ \r
+ row = input.row;\r
+ clm = input.clm;\r
+ if(row <= 0 || clm <= 0){\r
+ throw new NyARException();\r
+ }\r
+ if( mean.getClm() != clm ){\r
+ throw new NyARException();\r
+ }\r
+ double[] mean_array=mean.getArray();\r
+ for(int i = 0; i < clm; i++ ){\r
+ mean_array[i]=0.0;//mean->v[i] = 0.0;\r
+ }\r
+ \r
+ v=mean.getArray();\r
+ for(int i = 0; i < row; i++ ) {\r
+ for(int j = 0; j < clm; j++ ){\r
+ //*(v++) += *(m++);\r
+ v[j]+=input.m[i][j];\r
+ }\r
+ }\r
+ \r
+ for(int i = 0; i < clm; i++ ){\r
+ mean_array[i]/=row;//mean->v[i] /= row;\r
+ }\r
+ }\r
+ /**\r
+ * static int CENTER( ARMat *inout, ARVec *mean )の代替関数\r
+ * @param inout\r
+ * @param mean\r
+ * @return\r
+ */\r
+ private static void PCA_CENTER(NyARMat inout, NyARVec mean) throws NyARException\r
+ {\r
+ double[] v;\r
+ int row, clm;\r
+ \r
+ row = inout.getRow();\r
+ clm = inout.getClm();\r
+ if(mean.getClm()!= clm){\r
+ throw new NyARException();\r
+ }\r
+ \r
+ v = mean.getArray();\r
+ for(int i = 0; i < row; i++ ) {\r
+ for(int j = 0; j < clm; j++ ){\r
+ //*(m++) -= *(v++);\r
+ inout.m[i][j]-=v[j];\r
+ }\r
+ }\r
+ }\r
+ /**\r
+ * int x_by_xt( ARMat *input, ARMat *output )の代替関数\r
+ * @param input\r
+ * @param output\r
+ * @throws NyARException\r
+ */\r
+ private static void PCA_x_by_xt( NyARMat input, NyARMat output) throws NyARException\r
+ {\r
+ NyARException.trap("動作未チェック/配列化未チェック");\r
+ int row, clm;\r
+// double[][] out;\r
+ double[] in1,in2;\r
+ \r
+ NyARException.trap("未チェックのパス");\r
+ row = input.row;\r
+ clm = input.clm;\r
+ NyARException.trap("未チェックのパス");\r
+ if( output.row != row || output.clm != row ){\r
+ throw new NyARException();\r
+ }\r
+ \r
+// out = output.getArray();\r
+ for(int i = 0; i < row; i++ ) {\r
+ for(int j = 0; j < row; j++ ) {\r
+ if( j < i ) {\r
+ NyARException.trap("未チェックのパス");{\r
+ output.m[i][j]=output.m[j][i];//*out = output->m[j*row+i];\r
+ }\r
+ }else{\r
+ in1=input.getRowArray(i);//in1 = &(input->m[clm*i]);\r
+ in2=input.getRowArray(j);//in2 = &(input->m[clm*j]);\r
+ output.m[i][j]=0;//*out = 0.0;\r
+ for(int k = 0; k < clm; k++ ){\r
+ output.m[i][j]+=(in1[k]*in2[k]);//*out += *(in1++) * *(in2++);\r
+ }\r
+ }\r
+ // out.incPtr();\r
+ }\r
+ }\r
+ }\r
+ /**\r
+ * static int xt_by_x( ARMat *input, ARMat *output )の代替関数\r
+ * @param input\r
+ * @param output\r
+ * @throws NyARException\r
+ */\r
+ private static void PCA_xt_by_x(NyARMat input, NyARMat output) throws NyARException\r
+ {\r
+ double[] in;\r
+ int row, clm;\r
+ \r
+ row = input.row;\r
+ clm = input.clm;\r
+ if(output.row!= clm || output.clm != clm ){\r
+ throw new NyARException();\r
+ }\r
+ \r
+ for(int i = 0; i < clm; i++ ) {\r
+ for(int j = 0; j < clm; j++ ) {\r
+ if( j < i ) {\r
+ output.m[i][j]=output.m[j][i];//*out = output->m[j*clm+i];\r
+ }else{\r
+ output.m[i][j]=0.0;//*out = 0.0;\r
+ for(int k = 0; k < row; k++ ){\r
+ in=input.getRowArray(k);\r
+ output.m[i][j]+=(in[i]*in[j]);//*out += *in1 * *in2;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ /**\r
+ * static int QRM( ARMat *a, ARVec *dv )の代替関数\r
+ * @param a\r
+ * @param dv\r
+ * @throws NyARException\r
+ */\r
+ private static void PCA_QRM(NyARMat a, NyARVec dv) throws NyARException\r
+ {\r
+ double w, t, s, x, y, c;\r
+ int dim, iter;\r
+ double[] dv_array=dv.getArray();\r
+ \r
+ dim = a.row;\r
+ if( dim != a.clm || dim < 2 ){\r
+ throw new NyARException();\r
+ }\r
+ if( dv.getClm() != dim ){\r
+ throw new NyARException();\r
+ }\r
+ \r
+ NyARVec ev = new NyARVec( dim );\r
+ double[] ev_array=ev.getArray();\r
+ if( ev == null ){\r
+ throw new NyARException();\r
+ }\r
+\r
+ NyARVec.vecTridiagonalize(a,dv,ev,1);\r
+ \r
+ ev_array[0]=0.0;//ev->v[0] = 0.0;\r
+ for(int h = dim-1; h > 0; h-- ) {\r
+ int j = h;\r
+ while(j>0 && Math.abs(ev_array[j]) > PCA_EPS*(Math.abs(dv_array[j-1])+Math.abs(dv_array[j]))){// while(j>0 && fabs(ev->v[j]) > EPS*(fabs(dv->v[j-1])+fabs(dv->v[j]))) j--;\r
+ j--;\r
+ }\r
+ if( j == h ){\r
+ continue;\r
+ }\r
+ iter = 0;\r
+ do{\r
+ iter++;\r
+ if( iter > PCA_MAX_ITER ){\r
+ break;\r
+ }\r
+ w = (dv_array[h-1] - dv_array[h]) / 2;//w = (dv->v[h-1] - dv->v[h]) / 2;//ここ?\r
+ t = ev_array[h] * ev_array[h];//t = ev->v[h] * ev->v[h];\r
+ s = Math.sqrt(w*w+t);\r
+ if( w < 0 ){\r
+ s = -s;\r
+ }\r
+ x=dv_array[j] - dv_array[h] + t/(w+s);//x = dv->v[j] - dv->v[h] + t/(w+s);\r
+ y=ev_array[j+1];//y = ev->v[j+1];\r
+ for(int k = j; k < h; k++ ){\r
+ if( Math.abs(x) >= Math.abs(y)){\r
+ if( Math.abs(x) > PCA_VZERO ) {\r
+ t = -y / x;\r
+ c = 1 / Math.sqrt(t*t+1);\r
+ s = t * c;\r
+ }else{\r
+ c = 1.0;\r
+ s = 0.0;\r
+ }\r
+ }else{\r
+ t = -x / y;\r
+ s = 1.0 / Math.sqrt(t*t+1);\r
+ c = t * s;\r
+ }\r
+ w = dv_array[k] - dv_array[k+1];//w = dv->v[k] - dv->v[k+1];\r
+ t = (w * s + 2 * c * ev_array[k+1]) * s;//t = (w * s + 2 * c * ev->v[k+1]) * s;\r
+ dv_array[k]-=t;//dv->v[k] -= t;\r
+ dv_array[k+1]+=t;//dv->v[k+1] += t;\r
+ if( k > j){\r
+ NyARException.trap("未チェックパス");{\r
+ ev_array[k]=c * ev_array[k] - s * y;//ev->v[k] = c * ev->v[k] - s * y;\r
+ }\r
+ }\r
+ ev_array[k+1]+=s * (c * w - 2 * s * ev_array[k+1]);//ev->v[k+1] += s * (c * w - 2 * s * ev->v[k+1]);\r
+ \r
+ for(int i = 0; i < dim; i++ ){\r
+ x = a.m[k][i];//x = a->m[k*dim+i];\r
+ y = a.m[k+1][i];//y = a->m[(k+1)*dim+i];\r
+ a.m[k][i]=c * x - s * y;//a->m[k*dim+i] = c * x - s * y;\r
+ a.m[k+1][i]=s * x + c * y;//a->m[(k+1)*dim+i] = s * x + c * y;\r
+ }\r
+ if( k < h-1 ) {\r
+ NyARException.trap("未チェックパス");{\r
+ x = ev_array[k+1];//x = ev->v[k+1];\r
+ y =-s*ev_array[k+2];//y = -s * ev->v[k+2];\r
+ ev_array[k+2]*=c;//ev->v[k+2] *= c;\r
+ }\r
+ }\r
+ }\r
+ }while(Math.abs(ev_array[h]) > PCA_EPS*(Math.abs(dv_array[h-1])+Math.abs(dv_array[h])));\r
+ }\r
+ double[] v1,v2;\r
+ for(int k = 0; k < dim-1; k++ ) {\r
+ int h = k;\r
+ t=dv_array[h];//t = dv->v[h];\r
+ for(int i = k+1; i < dim; i++ ){\r
+ if(dv_array[i] > t ){//if( dv->v[i] > t ) {\r
+ h = i;\r
+ t=dv_array[h];//t = dv->v[h];\r
+ }\r
+ }\r
+ dv_array[h]=dv_array[k];//dv->v[h] = dv->v[k];\r
+ dv_array[k]=t;//dv->v[k] = t;\r
+ v1=a.getRowArray(h);//v1 = &(a->m[h*dim]);\r
+ v2=a.getRowArray(k);//v2 = &(a->m[k*dim]);\r
+ for(int i = 0; i < dim; i++ ) {\r
+ w=v1[i];//w = *v1;\r
+ v1[i]=v2[i];//*v1 = *v2;\r
+ v2[i]=w;//*v2 = w;\r
+ }\r
+ }\r
+ }\r
+ /**\r
+ * static int EV_create( ARMat *input, ARMat *u, ARMat *output, ARVec *ev )の代替関数\r
+ * @param input\r
+ * @param u\r
+ * @param output\r
+ * @param ev\r
+ * @throws NyARException\r
+ */\r
+ private static void PCA_EV_create(NyARMat input, NyARMat u, NyARMat output, NyARVec ev) throws NyARException\r
+ {\r
+ NyARException.trap("未チェックのパス");\r
+ int row, clm;\r
+ row = input.row;//row = input->row;\r
+ clm = input.clm;//clm = input->clm;\r
+ if( row <= 0 || clm <= 0 ){\r
+ throw new NyARException();\r
+ }\r
+ if( u.row != row || u.clm != row ){//if( u->row != row || u->clm != row ){\r
+ throw new NyARException();\r
+ }\r
+ if( output.row != row || output.clm != clm ){//if( output->row != row || output->clm != clm ){\r
+ throw new NyARException();\r
+ }\r
+ if( ev.getClm()!= row ){//if( ev->clm != row ){\r
+ throw new NyARException();\r
+ }\r
+ double[][] m,in;\r
+ double[] m1,ev_array;\r
+ double sum, work;\r
+ \r
+ m =output.getArray();//m = output->m;\r
+ in=input.getArray();\r
+ int i;\r
+ ev_array=ev.getArray();\r
+ for(i = 0; i < row; i++ ) {\r
+ NyARException.trap("未チェックのパス");\r
+ if( ev_array[i]<PCA_VZERO ){//if( ev->v[i] < VZERO ){\r
+ break;\r
+ }\r
+ NyARException.trap("未チェックのパス");\r
+ work = 1 / Math.sqrt(Math.abs(ev_array[i]));//work = 1 / sqrt(fabs(ev->v[i]));\r
+ for(int j = 0; j < clm; j++ ) {\r
+ sum = 0.0;\r
+ m1=u.getRowArray(i);//m1 = &(u->m[i*row]);\r
+ // m2=input.getPointer(j);//m2 = &(input->m[j]);\r
+ for(int k = 0; k < row; k++ ) {\r
+ sum+=m1[k]+in[k][j];//sum += *m1 * *m2;\r
+ // m1.incPtr(); //m1++;\r
+ // m2.addPtr(clm);//m2 += clm;\r
+ }\r
+ m1[j]=sum * work;//*(m++) = sum * work;\r
+ // {//*(m++) = sum * work;\r
+ // m.set(sum * work);\r
+ // m.incPtr();}\r
+ }\r
+ }\r
+ for( ; i < row; i++ ) {\r
+ NyARException.trap("未チェックのパス");\r
+ ev_array[i]=0.0;//ev->v[i] = 0.0;\r
+ for(int j = 0; j < clm; j++ ){\r
+ m[i][j]=0.0;\r
+ // m.set(0.0);//*(m++) = 0.0;\r
+ // m.incPtr();\r
+ }\r
+ }\r
+ }\r
+ /*static int PCA( ARMat *input, ARMat *output, ARVec *ev )*/\r
+ private static void PCA_PCA(NyARMat input, NyARMat output, NyARVec ev) throws NyARException\r
+ {\r
+ NyARMat u;\r
+ int row, clm, min;\r
+ double[] ev_array=ev.getArray();\r
+\r
+ row =input.row;//row = input->row;\r
+ clm =input.clm;//clm = input->clm;\r
+ min =(clm < row)? clm: row;\r
+ if( row < 2 || clm < 2 ){\r
+ throw new NyARException();\r
+ }\r
+ if( output.clm != input.clm){//if( output->clm != input->clm ){\r
+ throw new NyARException();\r
+ }\r
+ if( output.row!= min ){//if( output->row != min ){\r
+ throw new NyARException();\r
+ }\r
+ if( ev.getClm() != min ){//if( ev->clm != min ){\r
+ throw new NyARException();\r
+ }\r
+ u =new NyARMat( min, min );\r
+ \r
+ if( row < clm ){\r
+ NyARException.trap("未チェックのパス");\r
+ PCA_x_by_xt( input, u );//if(x_by_xt( input, u ) < 0 ) {\r
+ }else{\r
+ PCA_xt_by_x( input, u );//if(xt_by_x( input, u ) < 0 ) {\r
+ }\r
+ PCA_QRM( u, ev );\r
+\r
+ double[][] m1,m2;\r
+ if( row < clm ) {\r
+ NyARException.trap("未チェックのパス");{\r
+ PCA_EV_create( input, u, output, ev );\r
+ }\r
+ }else{\r
+ m1=u.m;//m1 = u->m;\r
+ m2=output.m;//m2 = output->m;\r
+ int i;\r
+ for(i = 0; i < min; i++){\r
+ if( ev_array[i] < PCA_VZERO){//if( ev->v[i] < VZERO ){\r
+ break;\r
+ }\r
+ for(int j = 0; j < min; j++ ){\r
+ m2[i][j]=m1[i][j];//*(m2++) = *(m1++);\r
+ }\r
+ }\r
+ for( ; i < min; i++){//for( ; i < min; i++){\r
+ //コードを見た限りあってそうだからコメントアウト(2008/03/26)NyARException.trap("未チェックのパス");\r
+ ev_array[i]=0.0;//ev->v[i] = 0.0;\r
+ for(int j = 0; j < min; j++ ){\r
+ m2[i][j]=0.0;//*(m2++) = 0.0;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ /*int arMatrixPCA( ARMat *input, ARMat *evec, ARVec *ev, ARVec *mean );*/\r
+ public static void matrixPCA(NyARMat input, NyARMat evec, NyARVec ev, NyARVec mean) throws NyARException\r
+ {\r
+ NyARMat work;\r
+ double srow, sum;\r
+ int row, clm;\r
+ int check;\r
+ \r
+ row=input.row;//row = input->row;\r
+ clm=input.clm;//clm = input->clm;\r
+ check = (row < clm)? row: clm;\r
+ if( row < 2 || clm < 2 ){\r
+ throw new NyARException();\r
+ }\r
+ if( evec.clm != input.clm || evec.row != check ){//if( evec->clm != input->clm || evec->row != check ){\r
+ throw new NyARException();\r
+ }\r
+ if( ev.getClm() != check ){//if( ev->clm != check ){\r
+ throw new NyARException();\r
+ }\r
+ if( mean.getClm() != input.clm){//if( mean->clm != input->clm ){\r
+ throw new NyARException();\r
+ }\r
+ \r
+ work =input.matrixAllocDup();//arMatrixAllocDup( input );work = arMatrixAllocDup( input );\r
+ \r
+ srow = Math.sqrt((double)row);\r
+ PCA_EX( work, mean );\r
+\r
+ PCA_CENTER(work,mean);\r
+\r
+\r
+ for(int i=0; i<row; i++){\r
+ for(int j=0;j<clm;j++){\r
+ work.m[i][j]/=srow;//work->m[i] /= srow;\r
+ }\r
+ }\r
+ \r
+ PCA_PCA( work, evec, ev );\r
+ \r
+ sum = 0.0;\r
+ double[] ev_array=ev.getArray();\r
+ for(int i = 0; i < ev.getClm(); i++ ){//for(int i = 0; i < ev->clm; i++ ){\r
+ sum+=ev_array[i];//sum += ev->v[i];\r
+ }\r
+ for(int i = 0; i < ev.getClm(); i++ ){//for(int i = 0; i < ev->clm; i++ ){\r
+ ev_array[i]/=sum;//ev->v[i] /= sum;\r
+ }\r
+ }\r
+\r
+ /*int arMatrixPCA2( ARMat *input, ARMat *evec, ARVec *ev );*/\r
+ public static void arMatrixPCA2( NyARMat input, NyARMat evec, NyARVec ev) throws NyARException\r
+ {\r
+ NyARException.trap("未チェックのパス");\r
+ NyARMat work;\r
+ // double srow; // unreferenced\r
+ double sum;\r
+ int row, clm;\r
+ int check;\r
+\r
+ row=input.row;//row = input->row;\r
+ clm=input.clm;//clm = input->clm;\r
+ check = (row < clm)? row: clm;\r
+ if( row < 2 || clm < 2 ){\r
+ throw new NyARException();\r
+ }\r
+ if( evec.getClm()!= input.clm|| evec.row!=check){//if( evec->clm != input->clm || evec->row != check ){\r
+ throw new NyARException();\r
+ }\r
+ if( ev.getClm() != check ){//if( ev->clm != check ){\r
+ throw new NyARException();\r
+ }\r
+ \r
+ NyARException.trap("未チェックのパス");\r
+ work =input.matrixAllocDup();\r
+\r
+ NyARException.trap("未チェックパス");\r
+ PCA_PCA( work, evec, ev );//rval = PCA( work, evec, ev );\r
+ sum = 0.0;\r
+ double[] ev_array=ev.getArray();\r
+ for(int i = 0; i < ev.getClm(); i++ ){//for( i = 0; i < ev->clm; i++ ){\r
+ NyARException.trap("未チェックパス");\r
+ sum+=ev_array[i];//sum += ev->v[i];\r
+ }\r
+ for(int i = 0; i < ev.getClm(); i++ ){//for(int i = 0; i < ev->clm; i++ ){\r
+ NyARException.trap("未チェックパス");\r
+ ev_array[i]/=sum;//ev->v[i] /= sum;\r
+ }\r
+ return;\r
+ }\r
+ public static NyARMat matrixAllocMul(NyARMat a, NyARMat b) throws NyARException\r
+ {\r
+ NyARException.trap("未チェックのパス");\r
+ NyARMat dest=new NyARMat(a.row, b.clm);\r
+ NyARException.trap("未チェックのパス");\r
+ matrixMul(dest, a, b);\r
+ return dest;\r
+ }\r
+ /*static double mdet(double *ap, int dimen, int rowa)*/\r
+ private static double Det_mdet(double[][] ap, int dimen, int rowa) throws NyARException\r
+ {\r
+ NyARException.trap("動作未チェック/配列化未チェック");\r
+ double det = 1.0;\r
+ double work;\r
+ int is = 0;\r
+ int mmax;\r
+ \r
+ for(int k = 0; k < dimen - 1; k++) {\r
+ mmax = k;\r
+ for(int i = k + 1; i < dimen; i++){\r
+// if (Math.abs(arMatrixDet_MATRIX_get(ap, i, k, rowa)) > Math.abs(arMatrixDet_MATRIX_get(ap, mmax, k, rowa))){\r
+ if (Math.abs(ap[i][k]) > Math.abs(ap[mmax][k])){\r
+ mmax = i;\r
+ }\r
+ }\r
+ if(mmax != k) {\r
+ for (int j = k; j < dimen; j++) {\r
+ work = ap[k][j];//work = MATRIX(ap, k, j, rowa);\r
+ ap[k][j]=ap[mmax][j];//MATRIX(ap, k, j, rowa) = MATRIX(ap, mmax, j, rowa);\r
+ ap[mmax][j]=work;//MATRIX(ap, mmax, j, rowa) = work;\r
+ }\r
+ is++;\r
+ }\r
+ for(int i = k + 1; i < dimen; i++) {\r
+ work = ap[i][k]/ ap[k][k];//work = arMatrixDet_MATRIX_get(ap, i, k, rowa) / arMatrixDet_MATRIX_get(ap, k, k, rowa);\r
+ for (int j = k + 1; j < dimen; j++){\r
+ //MATRIX(ap, i, j, rowa) -= work * MATRIX(ap, k, j, rowa);\r
+ ap[i][j]-=work * ap[k][j];\r
+ }\r
+ }\r
+ }\r
+ for(int i = 0; i < dimen; i++){\r
+ det=ap[i][i];//det *= MATRIX(ap, i, i, rowa);\r
+ }\r
+ for(int i = 0; i < is; i++){ \r
+ det *= -1.0;\r
+ }\r
+ return det;\r
+ }\r
+ /*double arMatrixDet(ARMat *m);*/\r
+ public static double arMatrixDet(NyARMat m) throws NyARException\r
+ {\r
+ NyARException.trap("動作未チェック/配列化未チェック");\r
+ if(m.row != m.clm){\r
+ return 0.0;\r
+ }\r
+ return Det_mdet(m.getArray(), m.row, m.clm);//return mdet(m->m, m->row, m->row);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core;\r
+\r
+\r
+import java.io.*;\r
+import java.nio.*;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.util.DoubleValue;\r
+\r
+/*typedef struct {\r
+ int xsize, ysize;\r
+ double mat[3][4];\r
+ double dist_factor[4];\r
+} ARParam;*/\r
+public class NyARParam{\r
+ private static final int SIZE_OF_PARAM_SET=4+4+(3*4*8)+(4*8);\r
+ private static final int PD_LOOP = 3;\r
+ protected int xsize, ysize;\r
+ private double[][] mat=new double[3][4];//Double2dArray mat=new Double2dArray(3,4);\r
+ private double[] dist_factor=new double[4];\r
+ public int getX()\r
+ {\r
+ return xsize;\r
+ }\r
+ public int getY()\r
+ {\r
+ return ysize;\r
+ }\r
+ public double[] getDistFactor()\r
+ {\r
+ return dist_factor;\r
+ }\r
+ public double[][] getMat()\r
+ {\r
+ return mat;\r
+ }\r
+ /**\r
+ * ARToolKit標準ファイルから1個目の設定をロードする。\r
+ * @param i_filename\r
+ * @throws NyARException\r
+ */\r
+ public void loadFromARFile(String i_filename) throws NyARException\r
+ {\r
+ try{\r
+ FileInputStream fs=new FileInputStream(i_filename);\r
+ NyARParam new_inst[]=arParamLoad(fs,1);\r
+ fs.close();\r
+ xsize =new_inst[0].xsize;\r
+ ysize =new_inst[0].ysize;\r
+ mat =new_inst[0].mat;\r
+ dist_factor=new_inst[0].dist_factor;\r
+ }catch(Exception e){\r
+ throw new NyARException(e);\r
+ }\r
+ }\r
+ /*static double dot( double a1, double a2, double a3,double b1, double b2, double b3 )*/\r
+ private static double dot( double a1, double a2, double a3,double b1, double b2, double b3 )\r
+ {\r
+ return( a1 * b1 + a2 * b2 + a3 * b3 );\r
+ }\r
+ /* static double norm( double a, double b, double c )*/\r
+ private static double norm( double a, double b, double c )\r
+ {\r
+ return Math.sqrt( a*a + b*b + c*c );\r
+ }\r
+ /**\r
+ * int arParamDecompMat( double source[3][4], double cpara[3][4], double trans[3][4] );\r
+ * 関数の置き換え\r
+ * @param o_cpara\r
+ * 戻り引数。3x4のマトリクスを指定すること。\r
+ * @param o_trans\r
+ * 戻り引数。3x4のマトリクスを指定すること。\r
+ * @return\r
+ */\r
+ public void decompMat(NyARMat o_cpara, NyARMat o_trans)\r
+ {\r
+ double[][] source=mat;\r
+ double[][] Cpara=new double[3][4];//double Cpara[3][4];\r
+ double rem1, rem2, rem3;\r
+ \r
+ if(source[2][3]>= 0 ){//if( source[2][3] >= 0 ) {\r
+ for(int r = 0; r < 3; r++ ){\r
+ for(int c = 0; c < 4; c++ ){\r
+ Cpara[r][c]=source[r][c];//Cpara[r][c] = source[r][c];\r
+ }\r
+ }\r
+ }else {\r
+ for(int r = 0; r < 3; r++ ){\r
+ for(int c = 0; c < 4; c++ ){\r
+ Cpara[r][c]=-source[r][c];//Cpara[r][c] = -(source[r][c]);\r
+ }\r
+ }\r
+ }\r
+ \r
+ double[][] cpara=o_cpara.getArray();\r
+ double[][] trans=o_trans.getArray();\r
+ for(int r = 0; r < 3; r++ ){\r
+ for(int c = 0; c < 4; c++ ){\r
+ cpara[r][c]=0.0;//cpara[r][c] = 0.0;\r
+ }\r
+ }\r
+ cpara[2][2]=norm(Cpara[2][0],Cpara[2][1], Cpara[2][2]);//cpara[2][2] = norm( Cpara[2][0], Cpara[2][1], Cpara[2][2] );\r
+ trans[2][0]=Cpara[2][0] / cpara[2][2];//trans[2][0] = Cpara[2][0] / cpara[2][2];\r
+ trans[2][1]=Cpara[2][1]/ cpara[2][2];//trans[2][1] = Cpara[2][1] / cpara[2][2];\r
+ trans[2][2]=Cpara[2][2]/ cpara[2][2];//trans[2][2] = Cpara[2][2] / cpara[2][2];\r
+ trans[2][3]=Cpara[2][3] / cpara[2][2];//trans[2][3] = Cpara[2][3] / cpara[2][2];\r
+ \r
+ cpara[1][2]=dot(trans[2][0], trans[2][1], trans[2][2],Cpara[1][0], Cpara[1][1], Cpara[1][2]);//cpara[1][2] = dot( trans[2][0], trans[2][1], trans[2][2],Cpara[1][0], Cpara[1][1], Cpara[1][2] );\r
+ rem1=Cpara[1][0]- cpara[1][2] * trans[2][0];//rem1 = Cpara[1][0] - cpara[1][2] * trans[2][0];\r
+ rem2=Cpara[1][1] - cpara[1][2] * trans[2][1];//rem2 = Cpara[1][1] - cpara[1][2] * trans[2][1];\r
+ rem3=Cpara[1][2] - cpara[1][2] * trans[2][2];//rem3 = Cpara[1][2] - cpara[1][2] * trans[2][2];\r
+ cpara[1][1]=norm(rem1, rem2, rem3 );//cpara[1][1] = norm( rem1, rem2, rem3 );\r
+ trans[1][0]= rem1/cpara[1][1];//trans[1][0] = rem1 / cpara[1][1];\r
+ trans[1][1]=rem2/cpara[1][1];//trans[1][1] = rem2 / cpara[1][1];\r
+ trans[1][2]=rem3 / cpara[1][1];//trans[1][2] = rem3 / cpara[1][1];\r
+ \r
+ cpara[0][2]=dot(trans[2][0],trans[2][1], trans[2][2],Cpara[0][0], Cpara[0][1], Cpara[0][2] );//cpara[0][2] = dot( trans[2][0], trans[2][1], trans[2][2],Cpara[0][0], Cpara[0][1], Cpara[0][2] );\r
+ cpara[0][1]=dot(trans[1][0],trans[1][1], trans[1][2],Cpara[0][0], Cpara[0][1], Cpara[0][2]);//cpara[0][1] = dot( trans[1][0], trans[1][1], trans[1][2],Cpara[0][0], Cpara[0][1], Cpara[0][2] );\r
+ rem1=Cpara[0][0]- cpara[0][1]*trans[1][0] - cpara[0][2]*trans[2][0];//rem1 = Cpara[0][0] - cpara[0][1]*trans[1][0] - cpara[0][2]*trans[2][0];\r
+ rem2 = Cpara[0][1] - cpara[0][1]*trans[1][1] - cpara[0][2]*trans[2][1];//rem2 = Cpara[0][1] - cpara[0][1]*trans[1][1] - cpara[0][2]*trans[2][1];\r
+ rem3 = Cpara[0][2] - cpara[0][1]*trans[1][2] - cpara[0][2]*trans[2][2];//rem3 = Cpara[0][2] - cpara[0][1]*trans[1][2] - cpara[0][2]*trans[2][2];\r
+ cpara[0][0]=norm(rem1, rem2, rem3);//cpara[0][0] = norm( rem1, rem2, rem3 );\r
+ trans[0][0]=rem1 / cpara[0][0];//trans[0][0] = rem1 / cpara[0][0];\r
+ trans[0][1]= rem2 / cpara[0][0];//trans[0][1] = rem2 / cpara[0][0];\r
+ trans[0][2]= rem3 / cpara[0][0];//trans[0][2] = rem3 / cpara[0][0];\r
+ \r
+ trans[1][3]=(Cpara[1][3] - cpara[1][2]*trans[2][3]) / cpara[1][1];//trans[1][3] = (Cpara[1][3] - cpara[1][2]*trans[2][3]) / cpara[1][1];\r
+ trans[0][3]=(Cpara[0][3] - cpara[0][1]*trans[1][3]- cpara[0][2]*trans[2][3]) / cpara[0][0];//trans[0][3] = (Cpara[0][3] - cpara[0][1]*trans[1][3]- cpara[0][2]*trans[2][3]) / cpara[0][0];\r
+ \r
+ for(int r = 0; r < 3; r++ ){\r
+ for(int c = 0; c < 3; c++ ){\r
+ cpara[r][c]/=cpara[2][2];//cpara[r][c] /= cpara[2][2];\r
+ }\r
+ }\r
+ }\r
+\r
+\r
+ /*int arParamDisp( ARParam *param );*/\r
+ public int paramDisp()\r
+ {\r
+ System.out.println("--------------------------------------");//printf("--------------------------------------\n");\r
+ System.out.print("SIZE = "+xsize+", "+ysize);//printf("SIZE = %d, %d\n", param->xsize, param->ysize);\r
+ System.out.println("Distortion factor = "+dist_factor[0]+" "+dist_factor[1]+" "+dist_factor[2]+" "+dist_factor[3]);//printf("Distortion factor = %f %f %f %f\n", param->dist_factor[0],param->dist_factor[1], param->dist_factor[2], param->dist_factor[3] );\r
+ for(int j = 0; j < 3; j++ ) {//for(j = 0; j < 3; j++ ) {\r
+ for(int i = 0; i < 4; i++ ){\r
+ System.out.print(mat[j][i]+" ");//printf("%7.5f ", param->mat[j][i]);\r
+ }\r
+ System.out.println();// printf("\n");\r
+ }//}\r
+ System.out.println("--------------------------------------");//printf("--------------------------------------\n");\r
+ return 0;\r
+ }\r
+// /*int arParamDecomp( ARParam *source, ARParam *icpara, double trans[3][4] );*/\r
+// private static int arParamDecomp( NyARParam source, NyARParam icpara, double[][] trans)\r
+// {\r
+// icpara.xsize = source.xsize;//icpara->xsize = source->xsize;\r
+// icpara.ysize = source.ysize;//icpara->ysize = source->ysize;\r
+// icpara.dist_factor[0] = source.dist_factor[0];//icpara->dist_factor[0] = source->dist_factor[0];\r
+// icpara.dist_factor[1] = source.dist_factor[1];// icpara->dist_factor[1] = source->dist_factor[1];\r
+// icpara.dist_factor[2] = source.dist_factor[2];//icpara->dist_factor[2] = source->dist_factor[2];\r
+// icpara.dist_factor[3] = source.dist_factor[3];//icpara->dist_factor[3] = source->dist_factor[3];\r
+// return arParamDecompMat(source.mat, icpara.mat, trans );\r
+// }\r
+ /**\r
+ * int arParamChangeSize( ARParam *source, int xsize, int ysize, ARParam *newparam );\r
+ * 関数の代替関数\r
+ * サイズプロパティをi_xsize,i_ysizeに変更します。\r
+ * @param xsize\r
+ * @param ysize\r
+ * @param newparam\r
+ * @return\r
+ * \r
+ */\r
+ public void changeSize(int i_xsize, int i_ysize)\r
+ {\r
+ double scale; \r
+ scale = (double)i_xsize / (double)(xsize);//scale = (double)xsize / (double)(source->xsize);\r
+ \r
+ for(int i = 0; i < 4; i++ ) {\r
+ mat[0][i]=mat[0][i]*scale;//newparam->mat[0][i] = source->mat[0][i] * scale;\r
+ mat[1][i]=mat[1][i]*scale;//newparam->mat[1][i] = source->mat[1][i] * scale;\r
+ mat[2][i]=mat[2][i];//newparam->mat[2][i] = source->mat[2][i];\r
+ }\r
+ \r
+ dist_factor[0] = dist_factor[0] * scale;//newparam->dist_factor[0] = source->dist_factor[0] * scale;\r
+ dist_factor[1] = dist_factor[1] * scale;//newparam->dist_factor[1] = source->dist_factor[1] * scale;\r
+ dist_factor[2] = dist_factor[2] / (scale*scale);//newparam->dist_factor[2] = source->dist_factor[2] / (scale*scale);\r
+ dist_factor[3] = dist_factor[3];//newparam->dist_factor[3] = source->dist_factor[3];\r
+ \r
+ xsize = i_xsize;//newparam->xsize = xsize;\r
+ ysize = i_ysize;//newparam->ysize = ysize;\r
+ }\r
+ /**\r
+ * int arParamIdeal2Observ( const double dist_factor[4], const double ix, const double iy,double *ox, double *oy )\r
+ * 関数の代替関数\r
+ * @param ix\r
+ * @param iy\r
+ * @param ox\r
+ * @param oy\r
+ */\r
+ public void ideal2Observ(double ix,double iy,DoubleValue ox, DoubleValue oy)\r
+ {\r
+ double x, y, d;\r
+ \r
+ x = (ix - dist_factor[0]) * dist_factor[3];\r
+ y = (iy - dist_factor[1]) * dist_factor[3];\r
+ if( x == 0.0 && y == 0.0 ) {\r
+ ox.set(dist_factor[0]);\r
+ oy.set(dist_factor[1]);\r
+ }else{\r
+ d = 1.0 - dist_factor[2]/100000000.0 * (x*x+y*y);\r
+ ox.set(x * d + dist_factor[0]);\r
+ oy.set(y * d + dist_factor[1]);\r
+ }\r
+ }\r
+ /*int arParamObserv2Ideal( const double dist_factor[4], const double ox, const double oy,double *ix, double *iy );*/\r
+ public int observ2Ideal(double ox,double oy,DoubleValue ix,DoubleValue iy)\r
+ {\r
+ double z02, z0, p, q, z, px, py;\r
+ \r
+ px = ox - dist_factor[0];\r
+ py = oy - dist_factor[1];\r
+ p = dist_factor[2]/100000000.0;\r
+ z02 = px*px+ py*py;\r
+ q = z0 = Math.sqrt(px*px+ py*py);\r
+ \r
+ for(int i = 1; ; i++ ) {\r
+ if( z0 != 0.0 ) {\r
+ z = z0 - ((1.0 - p*z02)*z0 - q) / (1.0 - 3.0*p*z02);\r
+ px = px * z / z0;\r
+ py = py * z / z0;\r
+ }else {\r
+ px = 0.0;\r
+ py = 0.0;\r
+ break;\r
+ }\r
+ if( i == PD_LOOP ){\r
+ break;\r
+ }\r
+ z02 = px*px+ py*py;\r
+ z0 = Math.sqrt(px*px+ py*py);\r
+ }\r
+ \r
+ ix.set(px / dist_factor[3] + dist_factor[0]);\r
+ iy.set(py / dist_factor[3] + dist_factor[1]);\r
+ return 0;\r
+ }\r
+ /**\r
+ * int arParamLoad( const char *filename, int num, ARParam *param, ...);\r
+ * i_streamの入力ストリームからi_num個の設定を読み込み、パラメタを配列にして返します。\r
+ * @param filename\r
+ * @param num\r
+ * @param param\r
+ * @return\r
+ * 設定を格納した配列を返します。\r
+ * @throws Exception\r
+ * i_num個の設定が読み出せない場合、JartkExceptionを発生します。\r
+ */\r
+ private static NyARParam[] arParamLoad(InputStream i_stream, int i_num) throws NyARException\r
+ {\r
+ try{\r
+ int read_size=SIZE_OF_PARAM_SET*i_num;\r
+ byte[] buf=new byte[read_size];\r
+ i_stream.read(buf);\r
+ //返却配列を確保\r
+ NyARParam[] result=new NyARParam[i_num];\r
+ \r
+ //バッファを加工\r
+ ByteBuffer bb = ByteBuffer.wrap(buf);\r
+ bb.order(ByteOrder.BIG_ENDIAN);\r
+ \r
+ //固定回数パースして配列に格納\r
+ for(int i=0;i<i_num;i++){\r
+ NyARParam new_param=new NyARParam();;\r
+ new_param.xsize=bb.getInt();\r
+ new_param.ysize=bb.getInt();\r
+ for(int i2=0;i2<3;i2++){\r
+ for(int i3=0;i3<4;i3++){\r
+ new_param.mat[i2][i3]=bb.getDouble();\r
+ }\r
+ }\r
+ for(int i2=0;i2<4;i2++){\r
+ new_param.dist_factor[i2]=bb.getDouble();\r
+ }\r
+ result[i]=new_param;\r
+ }\r
+ return result;\r
+ }catch(Exception e){\r
+ throw new NyARException(e);\r
+ }\r
+ }\r
+ public static int arParamSave(String filename,int num, NyARParam param[]) throws Exception\r
+ {\r
+ NyARException.trap("未チェックの関数");\r
+ byte buf[]=new byte[SIZE_OF_PARAM_SET*param.length];\r
+ //バッファをラップ\r
+ ByteBuffer bb = ByteBuffer.wrap(buf);\r
+ bb.order(ByteOrder.BIG_ENDIAN);\r
+\r
+ //書き込み\r
+ for(int i=0;i<param.length;i++){\r
+ bb.putInt(param[i].xsize);\r
+ bb.putInt(param[i].ysize);\r
+ for(int i2=0;i2<3;i2++){\r
+ for(int i3=0;i3<4;i3++){\r
+ bb.putDouble(param[i].mat[i2][i3]);\r
+ }\r
+ }\r
+ for(int i2=0;i2<4;i2++){\r
+ bb.putDouble(param[i].dist_factor[i2]);\r
+ }\r
+ }\r
+ //ファイルに保存\r
+ FileOutputStream fs=new FileOutputStream(filename);\r
+ fs.write(buf);\r
+ fs.close();\r
+\r
+ return 0;\r
+ }\r
+}\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core;\r
+/**\r
+ * ARMarkerInfoに相当するクラス。\r
+ * スクエア情報を保持します。\r
+ *\r
+ */\r
+public class NyARSquare{\r
+ private NyARMarker marker;\r
+ public int area;\r
+ public double[] pos;\r
+ public double[][] line; //double[4][3]\r
+ public double[][] vertex;//double[4][2];\r
+ public NyARSquare(NyARMarker i_marker,double[][] i_attached_line,double[][] i_attached_vertex)\r
+ {\r
+ //ARSquareは、ARMarkerを完全にラップするようにした。\r
+ marker=i_marker;\r
+ area=i_marker.area;\r
+ pos =i_marker.pos;\r
+ line =i_attached_line;\r
+ vertex=i_attached_vertex;\r
+ }\r
+ public NyARMarker getMarker()\r
+ {\r
+ return marker;\r
+ }\r
+}\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core;\r
+\r
+\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.util.DoubleValue;\r
+\r
+public class NyARTransMat{\r
+ private static final int AR_FITTING_TO_IDEAL=0;//#define AR_FITTING_TO_IDEAL 0\r
+ private static final int AR_FITTING_TO_INPUT=1;//#define AR_FITTING_TO_INPUT 1\r
+ private static final int arFittingMode =AR_FITTING_TO_INPUT;\r
+\r
+ private static final int AR_GET_TRANS_MAT_MAX_LOOP_COUNT=5;//#define AR_GET_TRANS_MAT_MAX_LOOP_COUNT 5\r
+ private static final double AR_GET_TRANS_MAT_MAX_FIT_ERROR=1.0;//#define AR_GET_TRANS_MAT_MAX_FIT_ERROR 1.0\r
+ private final static int P_MAX=500;//#define P_MAX 500\r
+ private double[][] pos3d=new double[P_MAX][3];//pos3d[P_MAX][3]; \r
+ private double[][] pos2d=new double[P_MAX][2];//pos2d[P_MAX][2];\r
+\r
+ private double[] center={0.0,0.0};\r
+ private NyARParam param;\r
+ private double conv[][];\r
+ private NyARMat result_mat=new NyARMat(3,4);\r
+ public NyARTransMat(NyARParam i_param)\r
+ {\r
+ conv=result_mat.getArray();\r
+ param=i_param;\r
+ \r
+ }\r
+ public void setCenter(double i_x,double i_y)\r
+ {\r
+ center[0]=i_x;\r
+ center[1]=i_x;\r
+ }\r
+ public NyARMat getTransformationMatrix()\r
+ {\r
+ return result_mat;\r
+ }\r
+ /*double arGetTransMat( ARMarkerInfo *marker_info,double center[2], double width, double conv[3][4] )*/\r
+ public double transMat( NyARSquare square,int i_direction, double width)throws NyARException\r
+ {\r
+ double[][] rot=new double[3][3];\r
+ double[][] ppos2d=new double[4][2];\r
+ double[][] ppos3d=new double[4][2];\r
+ int dir;\r
+ double err=-1;\r
+\r
+\r
+\r
+ \r
+ if( arGetInitRot( square,i_direction, rot ) < 0 ){\r
+ return -1;\r
+ }\r
+ \r
+ dir = i_direction;\r
+ ppos2d[0][0] = square.vertex[(4-dir)%4][0];\r
+ ppos2d[0][1] = square.vertex[(4-dir)%4][1];\r
+ ppos2d[1][0] = square.vertex[(5-dir)%4][0];\r
+ ppos2d[1][1] = square.vertex[(5-dir)%4][1];\r
+ ppos2d[2][0] = square.vertex[(6-dir)%4][0];\r
+ ppos2d[2][1] = square.vertex[(6-dir)%4][1];\r
+ ppos2d[3][0] = square.vertex[(7-dir)%4][0];\r
+ ppos2d[3][1] = square.vertex[(7-dir)%4][1];\r
+ ppos3d[0][0] = center[0] - width/2.0;\r
+ ppos3d[0][1] = center[1] + width/2.0;\r
+ ppos3d[1][0] = center[0] + width/2.0;\r
+ ppos3d[1][1] = center[1] + width/2.0;\r
+ ppos3d[2][0] = center[0] + width/2.0;\r
+ ppos3d[2][1] = center[1] - width/2.0;\r
+ ppos3d[3][0] = center[0] - width/2.0;\r
+ ppos3d[3][1] = center[1] - width/2.0;\r
+ \r
+\r
+ \r
+ \r
+ \r
+ for(int i=0;i<AR_GET_TRANS_MAT_MAX_LOOP_COUNT; i++ ) {\r
+ err = arGetTransMat3( rot, ppos2d, ppos3d, 4);\r
+ if( err < AR_GET_TRANS_MAT_MAX_FIT_ERROR ){\r
+ break;\r
+ }\r
+ }\r
+ return err;\r
+ }\r
+ /*double arGetTransMat3( double rot[3][3], double ppos2d[][2],double ppos3d[][2], int num, double conv[3][4],double *dist_factor, double cpara[3][4] )*/\r
+ private double arGetTransMat3( double rot[][], double ppos2d[][],double ppos3d[][], int num)throws NyARException\r
+ {\r
+ double[] off=new double[3], pmax=new double[3], pmin=new double[3];//double off[3], pmax[3], pmin[3];\r
+ double ret;\r
+ \r
+ pmax[0]=pmax[1]=pmax[2] = -10000000000.0;\r
+ pmin[0]=pmin[1]=pmin[2] = 10000000000.0;\r
+ for(int i = 0; i < num; i++ ) {\r
+ if( ppos3d[i][0] > pmax[0] ){\r
+ pmax[0] = ppos3d[i][0];\r
+ }\r
+ if( ppos3d[i][0] < pmin[0] ){\r
+ pmin[0] = ppos3d[i][0];\r
+ }\r
+ if( ppos3d[i][1] > pmax[1] ){\r
+ pmax[1] = ppos3d[i][1];\r
+ }\r
+ if( ppos3d[i][1] < pmin[1] ){\r
+ pmin[1] = ppos3d[i][1];\r
+ }\r
+ }\r
+ off[0] = -(pmax[0] + pmin[0]) / 2.0;\r
+ off[1] = -(pmax[1] + pmin[1]) / 2.0;\r
+ off[2] = -(pmax[2] + pmin[2]) / 2.0;\r
+ for(int i = 0; i < num; i++ ) {\r
+ pos3d[i][0] = ppos3d[i][0] + off[0];\r
+ pos3d[i][1] = ppos3d[i][1] + off[1];\r
+\r
+ pos3d[i][2] = 0.0;\r
+ }\r
+ ret = arGetTransMatSub( rot, ppos2d, pos3d, num);\r
+ \r
+ conv[0][3] = conv[0][0]*off[0] + conv[0][1]*off[1] + conv[0][2]*off[2] + conv[0][3];\r
+ conv[1][3] = conv[1][0]*off[0] + conv[1][1]*off[1] + conv[1][2]*off[2] + conv[1][3];\r
+ conv[2][3] = conv[2][0]*off[0] + conv[2][1]*off[1] + conv[2][2]*off[2] + conv[2][3];\r
+ \r
+ return ret;\r
+ }\r
+ /*static double arGetTransMatSub( double rot[3][3], double ppos2d[][2],double pos3d[][3], int num, double conv[3][4],double *dist_factor, double cpara[3][4] )*/\r
+ private double arGetTransMatSub( double rot[][], double ppos2d[][],double pos3d[][], int num) throws NyARException\r
+ {\r
+ double cpara[][]=param.getMat();\r
+ NyARMat mat_a,mat_b,mat_c,mat_d,mat_e,mat_f;//ARMat *mat_a, *mat_b, *mat_c, *mat_d, *mat_e, *mat_f;\r
+ double[] trans=new double[3];//double trans[3];\r
+ double wx, wy, wz;\r
+ double ret;\r
+ int i, j;\r
+ mat_a = new NyARMat(num*2, 3 );\r
+ mat_b = new NyARMat( 3, num*2 );\r
+ mat_c = new NyARMat( num*2, 1 );\r
+ mat_d = new NyARMat( 3, 3 );\r
+ mat_e = new NyARMat( 3, 1 );\r
+ mat_f = new NyARMat( 3, 1 );\r
+ double[][] a_array=mat_a.getArray();\r
+ double[][] b_array=mat_b.getArray();\r
+ double[][] c_array=mat_c.getArray();\r
+ double[][] f_array=mat_f.getArray();\r
+ \r
+ if(arFittingMode == AR_FITTING_TO_INPUT ){\r
+ DoubleValue a1=new DoubleValue(),a2=new DoubleValue();\r
+ for( i = 0; i < num; i++ ) {\r
+ param.ideal2Observ(ppos2d[i][0], ppos2d[i][1],a1,a2);//arParamIdeal2Observ(dist_factor, ppos2d[i][0], ppos2d[i][1],&pos2d[i][0], &pos2d[i][1]);\r
+ pos2d[i][0]=a1.get();\r
+ pos2d[i][1]=a2.get();\r
+ }\r
+ }else{\r
+ for( i = 0; i < num; i++ ) {\r
+ pos2d[i][0] = ppos2d[i][0];\r
+ pos2d[i][1] = ppos2d[i][1];\r
+ }\r
+ }\r
+ for( j = 0; j < num; j++ ) {\r
+ int x2=j*2;\r
+ wx = rot[0][0] * pos3d[j][0]+ rot[0][1] * pos3d[j][1]+ rot[0][2] * pos3d[j][2];\r
+ wy = rot[1][0] * pos3d[j][0]+ rot[1][1] * pos3d[j][1]+ rot[1][2] * pos3d[j][2];\r
+ wz = rot[2][0] * pos3d[j][0]+ rot[2][1] * pos3d[j][1]+ rot[2][2] * pos3d[j][2];\r
+ a_array[x2 ][0]=b_array[0][x2]=cpara[0][0];//mat_a->m[j*6+0] = mat_b->m[num*0+j*2] = cpara[0][0];\r
+ a_array[x2 ][1]=b_array[1][x2]=cpara[0][1];//mat_a->m[j*6+1] = mat_b->m[num*2+j*2] = cpara[0][1];\r
+ a_array[x2 ][2]=b_array[2][x2]=cpara[0][2] - pos2d[j][0];//mat_a->m[j*6+2] = mat_b->m[num*4+j*2] = cpara[0][2] - pos2d[j][0];\r
+ a_array[x2+1][0]=b_array[0][x2+1]=0.0;//mat_a->m[j*6+3] = mat_b->m[num*0+j*2+1] = 0.0;\r
+ a_array[x2+1][1]=b_array[1][x2+1]=cpara[1][1];//mat_a->m[j*6+4] = mat_b->m[num*2+j*2+1] = cpara[1][1];\r
+ a_array[x2+1][2]=b_array[2][x2+1]=cpara[1][2] - pos2d[j][1];//mat_a->m[j*6+5] = mat_b->m[num*4+j*2+1] = cpara[1][2] - pos2d[j][1];\r
+ c_array[x2][0] =wz * pos2d[j][0]- cpara[0][0]*wx - cpara[0][1]*wy - cpara[0][2]*wz;//mat_c->m[j*2+0] = wz * pos2d[j][0]- cpara[0][0]*wx - cpara[0][1]*wy - cpara[0][2]*wz;\r
+ c_array[x2+1][0]=wz * pos2d[j][1]- cpara[1][1]*wy - cpara[1][2]*wz;//mat_c->m[j*2+1] = wz * pos2d[j][1]- cpara[1][1]*wy - cpara[1][2]*wz;\r
+ }\r
+// JartkException.trap("未チェックのパス");{\r
+ NyARMat.matrixMul( mat_d, mat_b, mat_a );\r
+ NyARMat.matrixMul( mat_e, mat_b, mat_c );\r
+ NyARMat.matrixSelfInv(mat_d);\r
+ NyARMat.matrixMul( mat_f, mat_d, mat_e );\r
+// }\r
+ trans[0] = f_array[0][0];//trans[0] = mat_f->m[0];\r
+ trans[1] = f_array[1][0];\r
+ trans[2] = f_array[2][0];//trans[2] = mat_f->m[2];\r
+\r
+ ret = arModifyMatrix( rot, trans, pos3d, pos2d, num );\r
+ for( j = 0; j < num; j++ ) {\r
+ int x2=j*2;\r
+ wx = rot[0][0] * pos3d[j][0]+ rot[0][1] * pos3d[j][1]+ rot[0][2] * pos3d[j][2];\r
+ wy = rot[1][0] * pos3d[j][0]+ rot[1][1] * pos3d[j][1]+ rot[1][2] * pos3d[j][2];\r
+ wz = rot[2][0] * pos3d[j][0]+ rot[2][1] * pos3d[j][1]+ rot[2][2] * pos3d[j][2];\r
+ a_array[x2 ][0]=b_array[0][x2]=cpara[0][0];//mat_a->m[j*6+0] = mat_b->m[num*0+j*2] = cpara[0][0];\r
+ a_array[x2 ][1]=b_array[1][x2]=cpara[0][1];//mat_a->m[j*6+1] = mat_b->m[num*2+j*2] = cpara[0][1];\r
+ a_array[x2 ][2]=b_array[2][x2]=cpara[0][2] - pos2d[j][0];//mat_a->m[j*6+2] = mat_b->m[num*4+j*2] = cpara[0][2] - pos2d[j][0];\r
+ a_array[x2+1][0]=b_array[0][x2+1]=0.0;//mat_a->m[j*6+3] = mat_b->m[num*0+j*2+1] = 0.0;\r
+ a_array[x2+1][1]=b_array[1][x2+1]=cpara[1][1];//mat_a->m[j*6+4] = mat_b->m[num*2+j*2+1] = cpara[1][1];\r
+ a_array[x2+1][2]=b_array[2][x2+1]=cpara[1][2] - pos2d[j][1];//mat_a->m[j*6+5] = mat_b->m[num*4+j*2+1] = cpara[1][2] - pos2d[j][1];\r
+ c_array[x2][0] =wz * pos2d[j][0]- cpara[0][0]*wx - cpara[0][1]*wy - cpara[0][2]*wz;//mat_c->m[j*2+0] = wz * pos2d[j][0]- cpara[0][0]*wx - cpara[0][1]*wy - cpara[0][2]*wz;\r
+ c_array[x2+1][0]=wz * pos2d[j][1]- cpara[1][1]*wy - cpara[1][2]*wz;//mat_c->m[j*2+1] = wz * pos2d[j][1]- cpara[1][1]*wy - cpara[1][2]*wz;\r
+ }\r
+// JartkException.trap("未チェックのパス");{\r
+ NyARMat.matrixMul( mat_d, mat_b, mat_a );\r
+ NyARMat.matrixMul( mat_e, mat_b, mat_c );\r
+ NyARMat.matrixSelfInv(mat_d);\r
+ NyARMat.matrixMul( mat_f, mat_d, mat_e );\r
+// }\r
+ trans[0] = f_array[0][0];//trans[0] = mat_f->m[0];\r
+ trans[1] = f_array[1][0];\r
+ trans[2] = f_array[2][0];//trans[2] = mat_f->m[2];\r
+\r
+\r
+ ret = arModifyMatrix( rot, trans, pos3d, pos2d, num );\r
+ for( j = 0; j < 3; j++ ) {\r
+ for( i = 0; i < 3; i++ ){\r
+ conv[j][i] = rot[j][i];\r
+ }\r
+ conv[j][3] = trans[j];\r
+ }\r
+ return ret;\r
+ }\r
+ private double arModifyMatrix( double rot[][], double trans[],double vertex[][], double pos2d[][], int num )\r
+ {\r
+ double factor;\r
+ DoubleValue a=new DoubleValue(),b=new DoubleValue(),c=new DoubleValue();//double a, b, c;\r
+ double a1, b1, c1;\r
+ double a2, b2, c2;\r
+ double ma = 0.0, mb = 0.0, mc = 0.0;\r
+ double[][] combo=new double[3][4];\r
+ double hx, hy, h, x, y;\r
+ double err, minerr=0;\r
+ int t1, t2, t3;\r
+ int s1 = 0, s2 = 0, s3 = 0;\r
+ int i, j;\r
+\r
+ arGetAngle( rot, a, b, c);//arGetAngle( rot, &a, &b, &c );\r
+ a2 = a.get();\r
+ b2 = b.get();\r
+ c2 = c.get();\r
+ factor = 10.0*Math.PI/180.0;\r
+ for( j = 0; j < 10; j++ ) {\r
+ minerr = 1000000000.0;\r
+ for(t1=-1;t1<=1;t1++) {\r
+ for(t2=-1;t2<=1;t2++) {\r
+ for(t3=-1;t3<=1;t3++) {\r
+ a1 = a2 + factor*t1;\r
+ b1 = b2 + factor*t2;\r
+ c1 = c2 + factor*t3;\r
+ arGetNewMatrix( a1, b1, c1, trans, null, combo );\r
+ err = 0.0;\r
+ for( i = 0; i < num; i++ ) {\r
+ hx = combo[0][0] * vertex[i][0]+ combo[0][1] * vertex[i][1]+ combo[0][2] * vertex[i][2]+ combo[0][3];\r
+ hy = combo[1][0] * vertex[i][0]+ combo[1][1] * vertex[i][1]+ combo[1][2] * vertex[i][2]+ combo[1][3];\r
+ h = combo[2][0] * vertex[i][0]+ combo[2][1] * vertex[i][1]+ combo[2][2] * vertex[i][2]+ combo[2][3];\r
+ x = hx / h;\r
+ y = hy / h;\r
+ err += (pos2d[i][0] - x) * (pos2d[i][0] - x)+ (pos2d[i][1] - y) * (pos2d[i][1] - y);\r
+ }\r
+ if( err < minerr ) {\r
+ minerr = err;\r
+ ma = a1;\r
+ mb = b1;\r
+ mc = c1;\r
+ s1 = t1;\r
+ s2 = t2;\r
+ s3 = t3;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ if( s1 == 0 && s2 == 0 && s3 == 0 ){\r
+ factor *= 0.5;\r
+ }\r
+ a2 = ma;\r
+ b2 = mb;\r
+ c2 = mc;\r
+ }\r
+ arGetRot( ma, mb, mc, rot );\r
+ /* printf("factor = %10.5f\n", factor*180.0/MD_PI); */\r
+ return minerr/num;\r
+ }\r
+ private int arGetNewMatrix( double a, double b, double c,double trans[], double trans2[][], double ret[][] )\r
+ {\r
+ double cpara[][]=param.getMat();\r
+ double[][] cpara2=new double[3][4];\r
+ double[][] rot=new double[3][3];\r
+ int i, j;\r
+ \r
+ arGetRot( a, b, c, rot );\r
+ \r
+ if( trans2 != null ) {\r
+ for( j = 0; j < 3; j++ ) {\r
+ for( i = 0; i < 4; i++ ) {\r
+ cpara2[j][i] = cpara[j][0] * trans2[0][i]+ cpara[j][1] * trans2[1][i]+ cpara[j][2] * trans2[2][i];\r
+ }\r
+ }\r
+ }else{\r
+ for( j = 0; j < 3; j++ ) {\r
+ for( i = 0; i < 4; i++ ) {\r
+ cpara2[j][i] = cpara[j][i];\r
+ }\r
+ }\r
+ } \r
+ for( j = 0; j < 3; j++ ) {\r
+ for( i = 0; i < 3; i++ ) {\r
+ ret[j][i] = cpara2[j][0] * rot[0][i]+ cpara2[j][1] * rot[1][i]+ cpara2[j][2] * rot[2][i];\r
+ }\r
+ ret[j][3] = cpara2[j][0] * trans[0]+ cpara2[j][1] * trans[1]+ cpara2[j][2] * trans[2]+ cpara2[j][3];\r
+ }\r
+ return(0);\r
+ }\r
+ private int arGetRot( double a, double b, double c, double rot[][] )\r
+ {\r
+ double sina, sinb, sinc;\r
+ double cosa, cosb, cosc;\r
+ \r
+ sina = Math.sin(a);\r
+ cosa = Math.cos(a);\r
+ sinb = Math.sin(b);\r
+ cosb = Math.cos(b);\r
+ sinc = Math.sin(c);\r
+ cosc = Math.cos(c);\r
+ rot[0][0] = cosa*cosa*cosb*cosc+sina*sina*cosc+sina*cosa*cosb*sinc-sina*cosa*sinc;\r
+ rot[0][1] = -cosa*cosa*cosb*sinc-sina*sina*sinc+sina*cosa*cosb*cosc-sina*cosa*cosc;\r
+ rot[0][2] = cosa*sinb;\r
+ rot[1][0] = sina*cosa*cosb*cosc-sina*cosa*cosc+sina*sina*cosb*sinc+cosa*cosa*sinc;\r
+ rot[1][1] = -sina*cosa*cosb*sinc+sina*cosa*sinc+sina*sina*cosb*cosc+cosa*cosa*cosc;\r
+ rot[1][2] = sina*sinb;\r
+ rot[2][0] = -cosa*sinb*cosc-sina*sinb*sinc;\r
+ rot[2][1] = cosa*sinb*sinc-sina*sinb*cosc;\r
+ rot[2][2] = cosb;\r
+ \r
+ return 0;\r
+ }\r
+ /*int arGetAngle( double rot[3][3], double *wa, double *wb, double *wc )*/\r
+ private int arGetAngle( double rot[][], DoubleValue wa, DoubleValue wb, DoubleValue wc )\r
+ {\r
+ double a, b, c;\r
+ double sina, cosa, sinb, cosb, sinc, cosc;\r
+// #if CHECK_CALC\r
+// double w[3];\r
+// int i;\r
+// for(i=0;i<3;i++) w[i] = rot[i][0];\r
+// for(i=0;i<3;i++) rot[i][0] = rot[i][1];\r
+// for(i=0;i<3;i++) rot[i][1] = rot[i][2];\r
+// for(i=0;i<3;i++) rot[i][2] = w[i];\r
+// #endif \r
+ if( rot[2][2] > 1.0 ) {\r
+ /* printf("cos(beta) = %f\n", rot[2][2]); */\r
+ rot[2][2] = 1.0;\r
+ }else if( rot[2][2] < -1.0 ) {\r
+ /* printf("cos(beta) = %f\n", rot[2][2]); */\r
+ rot[2][2] = -1.0;\r
+ }\r
+ cosb = rot[2][2];\r
+ b = Math.acos( cosb );\r
+ sinb = Math.sin( b );\r
+ if( b >= 0.000001 || b <= -0.000001) {\r
+ cosa = rot[0][2] / sinb;\r
+ sina = rot[1][2] / sinb;\r
+ if( cosa > 1.0 ) {\r
+ /* printf("cos(alph) = %f\n", cosa); */\r
+ cosa = 1.0;\r
+ sina = 0.0;\r
+ }\r
+ if( cosa < -1.0 ) {\r
+ /* printf("cos(alph) = %f\n", cosa); */\r
+ cosa = -1.0;\r
+ sina = 0.0;\r
+ }\r
+ if( sina > 1.0 ) {\r
+ /* printf("sin(alph) = %f\n", sina); */\r
+ sina = 1.0;\r
+ cosa = 0.0;\r
+ }\r
+ if( sina < -1.0 ) {\r
+ /* printf("sin(alph) = %f\n", sina); */\r
+ sina = -1.0;\r
+ cosa = 0.0;\r
+ }\r
+ a = Math.acos( cosa );\r
+ if( sina < 0 ){\r
+ a = -a;\r
+ }\r
+ sinc = (rot[2][1]*rot[0][2]-rot[2][0]*rot[1][2])/ (rot[0][2]*rot[0][2]+rot[1][2]*rot[1][2]);\r
+ cosc = -(rot[0][2]*rot[2][0]+rot[1][2]*rot[2][1])/ (rot[0][2]*rot[0][2]+rot[1][2]*rot[1][2]);\r
+ if( cosc > 1.0 ) {\r
+ /* printf("cos(r) = %f\n", cosc); */\r
+ cosc = 1.0;\r
+ sinc = 0.0;\r
+ }\r
+ if( cosc < -1.0 ) {\r
+ /* printf("cos(r) = %f\n", cosc); */\r
+ cosc = -1.0;\r
+ sinc = 0.0;\r
+ }\r
+ if( sinc > 1.0 ) {\r
+ /* printf("sin(r) = %f\n", sinc); */\r
+ sinc = 1.0;\r
+ cosc = 0.0;\r
+ }\r
+ if( sinc < -1.0 ) {\r
+ /* printf("sin(r) = %f\n", sinc); */\r
+ sinc = -1.0;\r
+ cosc = 0.0;\r
+ }\r
+ c = Math.acos( cosc );\r
+ if( sinc < 0 ){\r
+ c = -c;\r
+ }\r
+ }else {\r
+ a = b = 0.0;\r
+ cosa = cosb = 1.0;\r
+ sina = sinb = 0.0;\r
+ cosc = rot[0][0];\r
+ sinc = rot[1][0];\r
+ if( cosc > 1.0 ) {\r
+ /* printf("cos(r) = %f\n", cosc); */\r
+ cosc = 1.0;\r
+ sinc = 0.0;\r
+ }\r
+ if( cosc < -1.0 ) {\r
+ /* printf("cos(r) = %f\n", cosc); */\r
+ cosc = -1.0;\r
+ sinc = 0.0;\r
+ }\r
+ if( sinc > 1.0 ) {\r
+ /* printf("sin(r) = %f\n", sinc); */\r
+ sinc = 1.0;\r
+ cosc = 0.0;\r
+ }\r
+ if( sinc < -1.0 ) {\r
+ /* printf("sin(r) = %f\n", sinc); */\r
+ sinc = -1.0;\r
+ cosc = 0.0;\r
+ }\r
+ c = Math.acos( cosc );\r
+ if( sinc < 0 ) c = -c;\r
+ }\r
+ \r
+ wa.set(a);//*wa = a;\r
+ wb.set(b);//*wb = b;\r
+ wc.set(c);//*wc = c;\r
+ \r
+ return 0;\r
+ }\r
+ /*int arGetInitRot( ARMarkerInfo *marker_info, double cpara[3][4], double rot[3][3] )*/\r
+ private int arGetInitRot( NyARSquare marker_info,int i_direction, double rot[][] ) throws NyARException\r
+ {\r
+ double cpara[][]=param.getMat();\r
+ double[][] wdir=new double[3][3];\r
+ double w, w1, w2, w3;\r
+ int dir;\r
+ int j;\r
+ \r
+ dir = i_direction;\r
+ \r
+ for( j = 0; j < 2; j++ ) {\r
+ w1 = marker_info.line[(4-dir+j)%4][0] * marker_info.line[(6-dir+j)%4][1]- marker_info.line[(6-dir+j)%4][0] * marker_info.line[(4-dir+j)%4][1];\r
+ w2 = marker_info.line[(4-dir+j)%4][1] * marker_info.line[(6-dir+j)%4][2]- marker_info.line[(6-dir+j)%4][1] * marker_info.line[(4-dir+j)%4][2];\r
+ w3 = marker_info.line[(4-dir+j)%4][2] * marker_info.line[(6-dir+j)%4][0]- marker_info.line[(6-dir+j)%4][2] * marker_info.line[(4-dir+j)%4][0];\r
+ \r
+ wdir[j][0] = w1*(cpara[0][1]*cpara[1][2]-cpara[0][2]*cpara[1][1])+ w2*cpara[1][1]- w3*cpara[0][1];\r
+ wdir[j][1] = -w1*cpara[0][0]*cpara[1][2]+ w3*cpara[0][0];\r
+ wdir[j][2] = w1*cpara[0][0]*cpara[1][1];\r
+ w = Math.sqrt( wdir[j][0]*wdir[j][0]+ wdir[j][1]*wdir[j][1]+ wdir[j][2]*wdir[j][2] );\r
+ wdir[j][0] /= w;\r
+ wdir[j][1] /= w;\r
+ wdir[j][2] /= w;\r
+ }\r
+ \r
+ if( check_dir(wdir[0], marker_info.vertex[(4-dir)%4],marker_info.vertex[(5-dir)%4], cpara) < 0 ){\r
+ return -1;\r
+ }\r
+ if( check_dir(wdir[1], marker_info.vertex[(7-dir)%4],marker_info.vertex[(4-dir)%4], cpara) < 0 ){\r
+ return -1;\r
+ }\r
+ if( check_rotation(wdir) < 0 ){\r
+ return -1;\r
+ }\r
+ \r
+ wdir[2][0] = wdir[0][1]*wdir[1][2] - wdir[0][2]*wdir[1][1];\r
+ wdir[2][1] = wdir[0][2]*wdir[1][0] - wdir[0][0]*wdir[1][2];\r
+ wdir[2][2] = wdir[0][0]*wdir[1][1] - wdir[0][1]*wdir[1][0];\r
+ w = Math.sqrt( wdir[2][0]*wdir[2][0]+ wdir[2][1]*wdir[2][1]+ wdir[2][2]*wdir[2][2] );\r
+ wdir[2][0] /= w;\r
+ wdir[2][1] /= w;\r
+ wdir[2][2] /= w;\r
+ /*\r
+ if( wdir[2][2] < 0 ) {\r
+ wdir[2][0] /= -w;\r
+ wdir[2][1] /= -w;\r
+ wdir[2][2] /= -w;\r
+ }\r
+ else {\r
+ wdir[2][0] /= w;\r
+ wdir[2][1] /= w;\r
+ wdir[2][2] /= w;\r
+ }\r
+ */\r
+ \r
+ rot[0][0] = wdir[0][0];\r
+ rot[1][0] = wdir[0][1];\r
+ rot[2][0] = wdir[0][2];\r
+ rot[0][1] = wdir[1][0];\r
+ rot[1][1] = wdir[1][1];\r
+ rot[2][1] = wdir[1][2];\r
+ rot[0][2] = wdir[2][0];\r
+ rot[1][2] = wdir[2][1];\r
+ rot[2][2] = wdir[2][2];\r
+ \r
+ return 0;\r
+ }\r
+\r
+ /*static int check_dir( double dir[3], double st[2], double ed[2],double cpara[3][4] )*/\r
+ private static int check_dir( double dir[], double st[], double ed[],double cpara[][]) throws NyARException\r
+ {\r
+ \r
+ double[][] world=new double[2][3];\r
+ double[][] camera=new double[2][2];\r
+ double[][] v=new double[2][2];\r
+ double h;\r
+ int i, j;\r
+ // JartkException.trap("未チェックパス");\r
+ NyARMat mat_a = new NyARMat( 3, 3 );\r
+ double[][] a_array=mat_a.getArray();\r
+ for(j=0;j<3;j++){\r
+ for(i=0;i<3;i++){\r
+ a_array[j][i]=cpara[j][i];//m[j*3+i] = cpara[j][i];\r
+ }\r
+ }\r
+ // JartkException.trap("未チェックのパス");\r
+ NyARMat.matrixSelfInv(mat_a);\r
+ world[0][0] = a_array[0][0]*st[0]*10.0+ a_array[0][1]*st[1]*10.0+ a_array[0][2]*10.0;//mat_a->m[0]*st[0]*10.0+ mat_a->m[1]*st[1]*10.0+ mat_a->m[2]*10.0;\r
+ world[0][1] = a_array[1][0]*st[0]*10.0+ a_array[1][1]*st[1]*10.0+ a_array[1][2]*10.0;//mat_a->m[3]*st[0]*10.0+ mat_a->m[4]*st[1]*10.0+ mat_a->m[5]*10.0;\r
+ world[0][2] = a_array[2][0]*st[0]*10.0+ a_array[2][1]*st[1]*10.0+ a_array[2][2]*10.0;//mat_a->m[6]*st[0]*10.0+ mat_a->m[7]*st[1]*10.0+ mat_a->m[8]*10.0;\r
+ world[1][0] = world[0][0] + dir[0];\r
+ world[1][1] = world[0][1] + dir[1];\r
+ world[1][2] = world[0][2] + dir[2];\r
+ \r
+ for( i = 0; i < 2; i++ ) {\r
+ h = cpara[2][0] * world[i][0]+ cpara[2][1] * world[i][1]+ cpara[2][2] * world[i][2];\r
+ if( h == 0.0 ){\r
+ return -1;\r
+ }\r
+ camera[i][0] = (cpara[0][0] * world[i][0]+ cpara[0][1] * world[i][1]+ cpara[0][2] * world[i][2]) / h;\r
+ camera[i][1] = (cpara[1][0] * world[i][0]+ cpara[1][1] * world[i][1]+ cpara[1][2] * world[i][2]) / h;\r
+ }\r
+ \r
+ v[0][0] = ed[0] - st[0];\r
+ v[0][1] = ed[1] - st[1];\r
+ v[1][0] = camera[1][0] - camera[0][0];\r
+ v[1][1] = camera[1][1] - camera[0][1];\r
+ \r
+ if( v[0][0]*v[1][0] + v[0][1]*v[1][1] < 0 ) {\r
+ dir[0] = -dir[0];\r
+ dir[1] = -dir[1];\r
+ dir[2] = -dir[2];\r
+ }\r
+ return 0;\r
+ }\r
+\r
+ /*int check_rotation( double rot[2][3] )*/\r
+ private static int check_rotation( double rot[][] )\r
+ {\r
+ double[] v1=new double[3], v2=new double[3], v3=new double[3];\r
+ double ca, cb, k1, k2, k3, k4;\r
+ double a, b, c, d;\r
+ double p1, q1, r1;\r
+ double p2, q2, r2;\r
+ double p3, q3, r3;\r
+ double p4, q4, r4;\r
+ double w;\r
+ double e1, e2, e3, e4;\r
+ int f;\r
+ \r
+ v1[0] = rot[0][0];\r
+ v1[1] = rot[0][1];\r
+ v1[2] = rot[0][2];\r
+ v2[0] = rot[1][0];\r
+ v2[1] = rot[1][1];\r
+ v2[2] = rot[1][2];\r
+ v3[0] = v1[1]*v2[2] - v1[2]*v2[1];\r
+ v3[1] = v1[2]*v2[0] - v1[0]*v2[2];\r
+ v3[2] = v1[0]*v2[1] - v1[1]*v2[0];\r
+ w = Math.sqrt( v3[0]*v3[0]+v3[1]*v3[1]+v3[2]*v3[2] );\r
+ if( w == 0.0 ) return -1;\r
+ v3[0] /= w;\r
+ v3[1] /= w;\r
+ v3[2] /= w;\r
+ \r
+ cb = v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];\r
+ if( cb < 0 ) cb *= -1.0;\r
+ ca = (Math.sqrt(cb+1.0) + Math.sqrt(1.0-cb)) * 0.5;\r
+ \r
+ if( v3[1]*v1[0] - v1[1]*v3[0] != 0.0 ) {\r
+ f = 0;\r
+ }\r
+ else {\r
+ if( v3[2]*v1[0] - v1[2]*v3[0] != 0.0 ) {\r
+ w = v1[1]; v1[1] = v1[2]; v1[2] = w;\r
+ w = v3[1]; v3[1] = v3[2]; v3[2] = w;\r
+ f = 1;\r
+ }\r
+ else {\r
+ w = v1[0]; v1[0] = v1[2]; v1[2] = w;\r
+ w = v3[0]; v3[0] = v3[2]; v3[2] = w;\r
+ f = 2;\r
+ }\r
+ }\r
+ if( v3[1]*v1[0] - v1[1]*v3[0] == 0.0 ){\r
+ return -1;\r
+ }\r
+ k1 = (v1[1]*v3[2] - v3[1]*v1[2]) / (v3[1]*v1[0] - v1[1]*v3[0]);\r
+ k2 = (v3[1] * ca) / (v3[1]*v1[0] - v1[1]*v3[0]);\r
+ k3 = (v1[0]*v3[2] - v3[0]*v1[2]) / (v3[0]*v1[1] - v1[0]*v3[1]);\r
+ k4 = (v3[0] * ca) / (v3[0]*v1[1] - v1[0]*v3[1]);\r
+ \r
+ a = k1*k1 + k3*k3 + 1;\r
+ b = k1*k2 + k3*k4;\r
+ c = k2*k2 + k4*k4 - 1;\r
+ \r
+ d = b*b - a*c;\r
+ if( d < 0 ){\r
+ return -1;\r
+ }\r
+ r1 = (-b + Math.sqrt(d))/a;\r
+ p1 = k1*r1 + k2;\r
+ q1 = k3*r1 + k4;\r
+ r2 = (-b - Math.sqrt(d))/a;\r
+ p2 = k1*r2 + k2;\r
+ q2 = k3*r2 + k4;\r
+ if( f == 1 ) {\r
+ w = q1; q1 = r1; r1 = w;\r
+ w = q2; q2 = r2; r2 = w;\r
+ w = v1[1]; v1[1] = v1[2]; v1[2] = w;\r
+ w = v3[1]; v3[1] = v3[2]; v3[2] = w;\r
+ f = 0;\r
+ }\r
+ if( f == 2 ) {\r
+ w = p1; p1 = r1; r1 = w;\r
+ w = p2; p2 = r2; r2 = w;\r
+ w = v1[0]; v1[0] = v1[2]; v1[2] = w;\r
+ w = v3[0]; v3[0] = v3[2]; v3[2] = w;\r
+ f = 0;\r
+ }\r
+ \r
+ if( v3[1]*v2[0] - v2[1]*v3[0] != 0.0 ) {\r
+ f = 0;\r
+ }\r
+ else {\r
+ if( v3[2]*v2[0] - v2[2]*v3[0] != 0.0 ) {\r
+ w = v2[1]; v2[1] = v2[2]; v2[2] = w;\r
+ w = v3[1]; v3[1] = v3[2]; v3[2] = w;\r
+ f = 1;\r
+ }\r
+ else {\r
+ w = v2[0]; v2[0] = v2[2]; v2[2] = w;\r
+ w = v3[0]; v3[0] = v3[2]; v3[2] = w;\r
+ f = 2;\r
+ }\r
+ }\r
+ if( v3[1]*v2[0] - v2[1]*v3[0] == 0.0 ) return -1;\r
+ k1 = (v2[1]*v3[2] - v3[1]*v2[2]) / (v3[1]*v2[0] - v2[1]*v3[0]);\r
+ k2 = (v3[1] * ca) / (v3[1]*v2[0] - v2[1]*v3[0]);\r
+ k3 = (v2[0]*v3[2] - v3[0]*v2[2]) / (v3[0]*v2[1] - v2[0]*v3[1]);\r
+ k4 = (v3[0] * ca) / (v3[0]*v2[1] - v2[0]*v3[1]);\r
+ \r
+ a = k1*k1 + k3*k3 + 1;\r
+ b = k1*k2 + k3*k4;\r
+ c = k2*k2 + k4*k4 - 1;\r
+ \r
+ d = b*b - a*c;\r
+ if( d < 0 ){\r
+ return -1;\r
+ }\r
+ r3 = (-b + Math.sqrt(d))/a;\r
+ p3 = k1*r3 + k2;\r
+ q3 = k3*r3 + k4;\r
+ r4 = (-b - Math.sqrt(d))/a;\r
+ p4 = k1*r4 + k2;\r
+ q4 = k3*r4 + k4;\r
+ if( f == 1 ) {\r
+ w = q3; q3 = r3; r3 = w;\r
+ w = q4; q4 = r4; r4 = w;\r
+ w = v2[1]; v2[1] = v2[2]; v2[2] = w;\r
+ w = v3[1]; v3[1] = v3[2]; v3[2] = w;\r
+ f = 0;\r
+ }\r
+ if( f == 2 ) {\r
+ w = p3; p3 = r3; r3 = w;\r
+ w = p4; p4 = r4; r4 = w;\r
+ w = v2[0]; v2[0] = v2[2]; v2[2] = w;\r
+ w = v3[0]; v3[0] = v3[2]; v3[2] = w;\r
+ f = 0;\r
+ }\r
+ \r
+ e1 = p1*p3+q1*q3+r1*r3;\r
+ if( e1 < 0 ){\r
+ e1 = -e1;\r
+ }\r
+ e2 = p1*p4+q1*q4+r1*r4;\r
+ if( e2 < 0 ){\r
+ e2 = -e2;\r
+ }\r
+ e3 = p2*p3+q2*q3+r2*r3;\r
+ if( e3 < 0 ){\r
+ e3 = -e3;\r
+ }\r
+ e4 = p2*p4+q2*q4+r2*r4;\r
+ if( e4 < 0 ){\r
+ e4 = -e4;\r
+ }\r
+ if( e1 < e2 ) {\r
+ if( e1 < e3 ) {\r
+ if( e1 < e4 ) {\r
+ rot[0][0] = p1;\r
+ rot[0][1] = q1;\r
+ rot[0][2] = r1;\r
+ rot[1][0] = p3;\r
+ rot[1][1] = q3;\r
+ rot[1][2] = r3;\r
+ }\r
+ else {\r
+ rot[0][0] = p2;\r
+ rot[0][1] = q2;\r
+ rot[0][2] = r2;\r
+ rot[1][0] = p4;\r
+ rot[1][1] = q4;\r
+ rot[1][2] = r4;\r
+ }\r
+ }\r
+ else {\r
+ if( e3 < e4 ) {\r
+ rot[0][0] = p2;\r
+ rot[0][1] = q2;\r
+ rot[0][2] = r2;\r
+ rot[1][0] = p3;\r
+ rot[1][1] = q3;\r
+ rot[1][2] = r3;\r
+ }\r
+ else {\r
+ rot[0][0] = p2;\r
+ rot[0][1] = q2;\r
+ rot[0][2] = r2;\r
+ rot[1][0] = p4;\r
+ rot[1][1] = q4;\r
+ rot[1][2] = r4;\r
+ }\r
+ }\r
+ }\r
+ else {\r
+ if( e2 < e3 ) {\r
+ if( e2 < e4 ) {\r
+ rot[0][0] = p1;\r
+ rot[0][1] = q1;\r
+ rot[0][2] = r1;\r
+ rot[1][0] = p4;\r
+ rot[1][1] = q4;\r
+ rot[1][2] = r4;\r
+ }\r
+ else {\r
+ rot[0][0] = p2;\r
+ rot[0][1] = q2;\r
+ rot[0][2] = r2;\r
+ rot[1][0] = p4;\r
+ rot[1][1] = q4;\r
+ rot[1][2] = r4;\r
+ }\r
+ }\r
+ else {\r
+ if( e3 < e4 ) {\r
+ rot[0][0] = p2;\r
+ rot[0][1] = q2;\r
+ rot[0][2] = r2;\r
+ rot[1][0] = p3;\r
+ rot[1][1] = q3;\r
+ rot[1][2] = r3;\r
+ }\r
+ else {\r
+ rot[0][0] = p2;\r
+ rot[0][1] = q2;\r
+ rot[0][2] = r2;\r
+ rot[1][0] = p4;\r
+ rot[1][1] = q4;\r
+ rot[1][2] = r4;\r
+ }\r
+ }\r
+ }\r
+ return 0;\r
+ }\r
+\r
+}\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+\r
+\r
+\r
+public class NyARVec\r
+{\r
+ private int clm;\r
+ private NyARVec(double[] i_array)\r
+ {\r
+ v=i_array;\r
+ clm=v.length;\r
+ }\r
+ public NyARVec(int i_clm)\r
+ {\r
+ v=new double[i_clm];\r
+ clm=i_clm;\r
+ }\r
+ private double[] v;\r
+ public int getClm()\r
+ {\r
+ return clm;\r
+ }\r
+ public double[] getArray()\r
+ {\r
+ return v;\r
+ }\r
+ public static NyARVec wrap(double[] i_array)\r
+ {\r
+ return new NyARVec(i_array);\r
+ }\r
+ /**\r
+ * arVecDispの代替品\r
+ * @param v\r
+ * @return\r
+ */\r
+ public int arVecDisp() throws NyARException\r
+ {\r
+ NyARException.trap("未チェックのパス");\r
+ System.out.println(" === vector ("+clm+") ===\n");//printf(" === vector (%d) ===\n", v->clm);\r
+ System.out.print(" |");//printf(" |");\r
+ for(int c = 0; c < clm; c++ ){//for( c = 0; c < v->clm; c++ ){\r
+ System.out.print(" "+v[c]);//printf( " %10g", v->v[c] );\r
+ }\r
+ System.out.println(" |");//printf(" |\n");\r
+ System.out.println(" ===================");//printf(" ===================\n");\r
+ return 0;\r
+ }\r
+ /**\r
+ * arVecInnerproduct関数の代替品\r
+ * @param x\r
+ * @param y\r
+ * @param i_start\r
+ * 演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる)\r
+ * @return\r
+ * @throws NyARException\r
+ */\r
+ private static double vecInnerproduct(NyARVec x,NyARVec y,int i_start) throws NyARException\r
+ {\r
+ NyARException.trap("この関数は動作確認できていません。"); \r
+ double result = 0.0;\r
+// double[] x_array=x.v;.getArray();\r
+// double[] y_array=y.getArray();\r
+ \r
+ if(x.clm!= y.clm){\r
+ throw new NyARException();//exit();\r
+ }\r
+ for(int i = i_start; i < x.clm; i++ ) {\r
+ NyARException.trap("未チェックのパス");\r
+ result += x.v[i] * y.v[i];//result += x->v[i] * y->v[i];\r
+ } \r
+ return result;\r
+ }\r
+ /**\r
+ * double arVecHousehold関数の代替品\r
+ * @param x\r
+ * @param i_start\r
+ * 演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる)\r
+ * @return\r
+ * @throws NyARException\r
+ */\r
+ private static double vecHousehold(NyARVec x,int i_start) throws NyARException\r
+ {\r
+ NyARException.trap("この関数は動作確認できていません。");\r
+ double s, t;\r
+ s = Math.sqrt(vecInnerproduct(x,x,i_start));\r
+// double[] x_array=x.getArray();\r
+ if( s != 0.0 ){\r
+ NyARException.trap("未チェックのパス");\r
+ if(x.v[i_start]< 0){\r
+ s = -s;\r
+ }\r
+ NyARException.trap("未チェックのパス");{\r
+ x.v[i_start]+=s;//x->v[0] += s;\r
+ t = 1 / Math.sqrt(x.v[i_start]* s);//t = 1 / sqrt(x->v[0] * s);\r
+ }\r
+ for(int i = i_start; i < x.clm; i++){\r
+ NyARException.trap("未チェックのパス");\r
+ x.v[i]*=t;//x->v[i] *= t;\r
+ }\r
+ }\r
+ return -s;\r
+ }\r
+ /**\r
+ * arVecTridiagonalize関数の代替品\r
+ * a,d,e間で演算をしてる。何をどうしているかはさっぱりさっぱり\r
+ * @param a\r
+ * @param d\r
+ * @param e\r
+ * @param i_e_start\r
+ * 演算開始列(よくわからないけどarVecTridiagonalizeの呼び出し元でなんかしてる)\r
+ * @return\r
+ * @throws NyARException\r
+ */\r
+ public static void vecTridiagonalize(NyARMat a, NyARVec d, NyARVec e,int i_e_start) throws NyARException\r
+ {\r
+ NyARVec vec,vec2;\r
+ double[][] a_array=a.getArray();\r
+ double s, t, p, q;\r
+ int dim;\r
+\r
+ if(a.getClm()!=a.getRow()){\r
+ throw new NyARException();\r
+ }\r
+ if(a.getClm() != d.clm){\r
+ throw new NyARException();\r
+ }\r
+ if(a.getClm() != e.clm){\r
+ throw new NyARException();\r
+ }\r
+ dim = a.getClm();\r
+\r
+ for(int k = 0; k < dim-2; k++ ){\r
+ vec=a.getRowVec(k);\r
+// double[] vec_array=vec.getArray();\r
+ NyARException.trap("未チェックパス"); \r
+ d.v[k]=vec.v[k];//d.set(k,v.get(k)); //d->v[k] = v[k];\r
+\r
+ //wv1.clm = dim-k-1;\r
+ //wv1.v = &(v[k+1]);\r
+ NyARException.trap("未チェックパス"); \r
+ e.v[k+i_e_start]=vecHousehold(vec,k+1);//e->v[k] = arVecHousehold(&wv1);\r
+ if(e.v[k+i_e_start]== 0.0 ){\r
+ continue;\r
+ }\r
+\r
+ for(int i = k+1; i < dim; i++ ){\r
+ s = 0.0;\r
+ for(int j = k+1; j < i; j++ ) {\r
+ NyARException.trap("未チェックのパス");\r
+ s += a_array[j][i] * vec.v[j];//s += a.get(j*dim+i) * v.get(j);//s += a->m[j*dim+i] * v[j];\r
+ }\r
+ for(int j = i; j < dim; j++ ) {\r
+ NyARException.trap("未チェックのパス");\r
+ s += a_array[i][j] * vec.v[j];//s += a.get(i*dim+j) * v.get(j);//s += a->m[i*dim+j] * v[j];\r
+ }\r
+ NyARException.trap("未チェックのパス");\r
+ d.v[i]=s;//d->v[i] = s;\r
+ }\r
+ \r
+\r
+ //wv1.clm = wv2.clm = dim-k-1;\r
+ //wv1.v = &(v[k+1]);\r
+ //wv2.v = &(d->v[k+1]);\r
+ vec=a.getRowVec(k);\r
+// vec_array=vec.getArray();\r
+ NyARException.trap("未チェックパス"); \r
+ t = vecInnerproduct(vec,d,k+1)/ 2;\r
+ for(int i = dim-1; i > k; i-- ) {\r
+ NyARException.trap("未チェックパス"); \r
+ p = vec.v[i];//p = v.get(i);//p = v[i];\r
+ d.v[i]-=t*p;q=d.v[i];//q = d->v[i] -= t*p;\r
+ for(int j = i; j < dim; j++ ){\r
+ NyARException.trap("未チェックパス"); \r
+ a_array[i][j]-=p*(d.v[j] + q*vec.v[j]);//a->m[i*dim+j] -= p*(d->v[j]) + q*v[j];\r
+ }\r
+ }\r
+ }\r
+\r
+ if( dim >= 2) {\r
+ d.v[dim-2]=a_array[dim-2][dim-2];//d->v[dim-2] = a->m[(dim-2)*dim+(dim-2)];\r
+ e.v[dim-2+i_e_start]=a_array[dim-2][dim-1];//e->v[dim-2] = a->m[(dim-2)*dim+(dim-1)];\r
+ }\r
+\r
+ if( dim >= 1 ){\r
+ d.v[dim-1]=a_array[dim-1][dim-1];//d->v[dim-1] = a->m[(dim-1)*dim+(dim-1)];\r
+ }\r
+\r
+ for(int k = dim-1; k >= 0; k--) {\r
+ vec=a.getRowVec(k);//v = a.getPointer(k*dim);//v = &(a->m[k*dim]);\r
+ if( k < dim-2 ) {\r
+ for(int i = k+1; i < dim; i++ ){\r
+ //wv1.clm = wv2.clm = dim-k-1;\r
+ //wv1.v = &(v[k+1]);\r
+ //wv2.v = &(a->m[i*dim+k+1]);\r
+ vec2=a.getRowVec(i);\r
+ \r
+ t = vecInnerproduct(vec,vec2,k+1);\r
+ for(int j = k+1; j < dim; j++ ){\r
+ NyARException.trap("未チェックパス"); \r
+ a_array[i][j]-=t*vec.v[j];//a.subValue(i*dim+j,t*v.get(j));//a->m[i*dim+j] -= t * v[j];\r
+ }\r
+ }\r
+ }\r
+ for(int i = 0; i < dim; i++ ){\r
+ vec.v[i]=0.0;//v.set(i,0.0);//v[i] = 0.0;\r
+ }\r
+ vec.v[k]=1;//v.set(k,1);//v[k] = 1;\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core;\r
+\r
+\r
+/**\r
+ * ARUint32 arGetVersion(char **versionStringRef);\r
+ * 関数の置き換え\r
+ */\r
+public class NyARVersion {\r
+ private static final int AR_HEADER_VERSION_MAJOR=2; //#define AR_HEADER_VERSION_MAJOR 2\r
+ private static final int AR_HEADER_VERSION_MINOR=72;//#define AR_HEADER_VERSION_MINOR 72 \r
+ private static final int AR_HEADER_VERSION_TINY=0;//#define AR_HEADER_VERSION_TINY 0\r
+ private static final int AR_HEADER_VERSION_BUILD=0;//#define AR_HEADER_VERSION_BUILD 0\r
+ private static final String AR_HEADER_VERSION_STRING="2.72.0";//#define AR_HEADER_VERSION_STRING "2.72.0"\r
+ public static final boolean AR_HAVE_HEADER_VERSION_2=true;//#define AR_HAVE_HEADER_VERSION_2\r
+ public static final boolean AR_HAVE_HEADER_VERSION_2_72=true;//#define AR_HAVE_HEADER_VERSION_2_72\r
+\r
+ public static String getARVersion()\r
+ {\r
+ return AR_HEADER_VERSION_STRING;\r
+ }\r
+ public static int getARVersionInt()\r
+ {\r
+ // Represent full version number (major, minor, tiny, build) in\r
+ // binary coded decimal. N.B: Integer division.\r
+ return (int)(0x10000000 * (AR_HEADER_VERSION_MAJOR / 10)) +\r
+ (int)(0x01000000 * (AR_HEADER_VERSION_MAJOR % 10)) +\r
+ (int)(0x00100000 * (AR_HEADER_VERSION_MINOR / 10)) +\r
+ (int)(0x00010000 * (AR_HEADER_VERSION_MINOR % 10)) +\r
+ (int)(0x00001000 * (AR_HEADER_VERSION_TINY / 10)) +\r
+ (int)(0x00000100 * (AR_HEADER_VERSION_TINY % 10)) +\r
+ (int)(0x00000010 * (AR_HEADER_VERSION_BUILD / 10)) +\r
+ (int)(0x00000001 * (AR_HEADER_VERSION_BUILD % 10));\r
+ \r
+ }\r
+}\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core.match;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.NyARCode;\r
+import jp.nyatla.nyartoolkit.core.NyARColorPatt;\r
+\r
+\r
+\r
+\r
+\r
+/**\r
+ * ARColorPattのマッチング計算をするインタフェイスです。\r
+ * 基準Patに対して、計算済みのARCodeデータとの間で比較演算をします。\r
+ * pattern_match関数を分解した3種類のパターン検出クラスを定義します。\r
+ *\r
+ */\r
+interface ARMatchPatt{\r
+ public double getConfidence();\r
+ public int getDirection();\r
+ public void evaluate(NyARCode i_code);\r
+ public void setPatt(NyARColorPatt i_target_patt) throws NyARException;\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core.match;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.*;\r
+\r
+/**\r
+ * AR_TEMPLATE_MATCHING_BWと同等のルールで\r
+ * マーカーを評価します。\r
+ *\r
+ */\r
+public class NyARMatchPatt_BlackWhite implements ARMatchPatt{\r
+ private double datapow;\r
+ private int width;\r
+ private int height;\r
+ private double cf=0;\r
+ private int dir=0;\r
+ private int ave;\r
+ private int[][][] input=new int[height][width][3];\r
+ public void setPatt(NyARColorPatt i_target_patt) throws NyARException\r
+ {\r
+ width=i_target_patt.getWidth();\r
+ height=i_target_patt.getHeight();\r
+ short[][][] data=i_target_patt.getPatArray(); \r
+ input=new int[height][width][3];\r
+ \r
+ int sum = ave = 0;\r
+ for(int i=0;i<height;i++) {//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){\r
+ for(int i2=0;i2<width;i2++) {//for(int i2=0;i2<Config.AR_PATT_SIZE_X;i2++){\r
+ ave += (255-data[i][i2][0])+(255-data[i][i2][1])+(255-data[i][i2][2]);\r
+ }\r
+ }\r
+ ave /= (height*width*3);\r
+\r
+ for(int i=0;i<height;i++){//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){\r
+ for(int i2=0;i2<width;i2++){//for(int i2=0;i2<Config.AR_PATT_SIZE_X;i2++){\r
+ input[i][i2][0] = ((255-data[i][i2][0]) + (255-data[i][i2][1]) + (255-data[i][i2][2]))/3 - ave;\r
+ sum += input[i][i2][0]*input[i][i2][0];\r
+ }\r
+ }\r
+ \r
+ datapow = Math.sqrt( (double)sum );\r
+ if( datapow == 0.0 ){\r
+ throw new NyARException();\r
+// dir.set(0);//*dir = 0;\r
+// cf.set(-1.0);//*cf = -1.0;\r
+// return -1;\r
+ }\r
+ }\r
+ public double getConfidence()\r
+ {\r
+ return cf;\r
+ }\r
+ public int getDirection()\r
+ {\r
+ return dir;\r
+ }\r
+ public void evaluate(NyARCode i_code)\r
+ {\r
+ short[][][] patBW=i_code.getPatBW();//static int patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];\r
+ double[] patpowBW=i_code.getPatPowBW();//static double patpowBW[AR_PATT_NUM_MAX][4];\r
+\r
+ double max=0.0;\r
+ int res=-1;\r
+ //本家が飛ぶ。試験データで0.77767376888がが出ればOKってことで\r
+ for(int j = 0; j < 4; j++ ) {\r
+ int sum = 0;\r
+ for(int i=0;i<height;i++){\r
+ for(int i2=0;i2<width;i2++){\r
+ sum += input[i][i2][0]*patBW[j][i][i2];\r
+ }\r
+ }\r
+ double sum2 = sum / patpowBW[j] / datapow;\r
+ if( sum2 > max ) {\r
+ max = sum2;\r
+ res = j;\r
+ }\r
+ }\r
+ dir=res;\r
+ cf=max; \r
+ }\r
+}\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core.match;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.*;\r
+\r
+/**\r
+ * AR_TEMPLATE_MATCHING_COLORかつAR_MATCHING_WITHOUT_PCAと同等のルールで\r
+ * マーカーを評価します。\r
+ *\r
+ */\r
+public class NyARMatchPatt_Color_WITHOUT_PCA implements ARMatchPatt{\r
+ private int[][][] input;\r
+ private int ave;\r
+ private double datapow;\r
+\r
+ private int width;\r
+ private int height;\r
+ private double cf=0;\r
+ private int dir=0;\r
+ public double getConfidence(){\r
+ return cf;\r
+ }\r
+ public int getDirection(){\r
+ return dir;\r
+ }\r
+ public void setPatt(NyARColorPatt i_target_patt) throws NyARException\r
+ {\r
+ width=i_target_patt.getWidth();\r
+ height=i_target_patt.getHeight();\r
+ short[][][] data=i_target_patt.getPatArray();\r
+ \r
+ input=new int[height][width][3];\r
+ int sum;\r
+\r
+ sum = ave = 0;\r
+ for(int i=0;i<height;i++) {//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){\r
+ for(int i2=0;i2<width;i2++) {//for(int i2=0;i2<Config.AR_PATT_SIZE_X;i2++){\r
+ ave += (255-data[i][i2][0])+(255-data[i][i2][1])+(255-data[i][i2][2]);\r
+ }\r
+ }\r
+ ave /= (height*width*3);\r
+\r
+ for(int i=0;i<height;i++){//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){\r
+ for(int i2=0;i2<width;i2++){//for(int i2=0;i2<Config.AR_PATT_SIZE_X;i2++){\r
+ for(int i3=0;i3<3;i3++){\r
+ input[i][i2][i3] = (255-data[i][i2][i3]) - ave;\r
+ sum += input[i][i2][i3]*input[i][i2][i3];\r
+ }\r
+ }\r
+ }\r
+ datapow = Math.sqrt( (double)sum );\r
+ if(datapow == 0.0){\r
+ throw new NyARException();\r
+// dir.set(0);//*dir = 0;\r
+// cf.set(-1.0);//*cf = -1.0;\r
+// return -1;\r
+ } \r
+ }\r
+ /**\r
+ * public int pattern_match(short[][][] data,IntPointer dir,DoublePointer cf)\r
+\r
+ */\r
+ public void evaluate(NyARCode i_code)\r
+ {\r
+ int[][][][] pat=i_code.getPat();\r
+ double[] patpow=i_code.getPatPow();\r
+ int res= -1;\r
+ double max=0.0;\r
+ for(int j = 0; j < 4; j++ ) {\r
+ int sum = 0;\r
+ for(int i=0;i<height;i++){//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){\r
+ for(int i2=0;i2<width;i2++){\r
+ for(int i3=0;i3<3;i3++){\r
+ sum += input[i][i2][i3]*pat[j][i][i2][i3];//sum += input[i][i2][i3]*pat[k][j][i][i2][i3];\r
+ }\r
+ }\r
+ }\r
+ double sum2 = sum / patpow[j] / datapow;//sum2 = sum / patpow[k][j] / datapow;\r
+ if( sum2 > max ){\r
+ max = sum2;\r
+ res = j;\r
+ }\r
+ }\r
+ dir=res;\r
+ cf=max;\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core.match;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.NyARCode;\r
+import jp.nyatla.nyartoolkit.core.NyARColorPatt;\r
+\r
+/**\r
+ * AR_TEMPLATE_MATCHING_COLORかつAR_MATCHING_WITH_PCAと同等のルールで\r
+ * マーカーを評価します。\r
+ *\r
+ */\r
+public class NyARMatchPatt_Color_WITH_PCA implements ARMatchPatt{\r
+ private final int EVEC_MAX=10;//#define EVEC_MAX 10\r
+ private int evec_dim;//static int evec_dim;\r
+ private int[][][] input;\r
+ private double[][][][] evec;//static double evec[EVEC_MAX][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];\r
+ private double[][] epat=new double[4][EVEC_MAX];//static double epat[AR_PATT_NUM_MAX][4][EVEC_MAX];\r
+ private int ave;\r
+ private double datapow;\r
+\r
+ private int width;\r
+ private int height;\r
+ private double cf=0;\r
+ private int dir=0;//向きか!\r
+ public double getConfidence(){\r
+ return cf;\r
+ }\r
+ public int getDirection(){\r
+ return dir;\r
+ }\r
+ public void setPatt(NyARColorPatt i_target_patt) throws NyARException\r
+ {\r
+ width=i_target_patt.getWidth();\r
+ height=i_target_patt.getHeight();\r
+ short[][][] data=i_target_patt.getPatArray();\r
+ \r
+ input=new int[height][width][3];\r
+ evec=new double[EVEC_MAX][height][width][3];//static double evec[EVEC_MAX][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];\r
+ int sum;\r
+\r
+ sum = ave = 0;\r
+ for(int i=0;i<height;i++) {//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){\r
+ for(int i2=0;i2<width;i2++) {//for(int i2=0;i2<Config.AR_PATT_SIZE_X;i2++){\r
+ ave += (255-data[i][i2][0])+(255-data[i][i2][1])+(255-data[i][i2][2]);\r
+ }\r
+ }\r
+ ave /= (height*width*3);\r
+\r
+ for(int i=0;i<height;i++){//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){\r
+ for(int i2=0;i2<width;i2++){//for(int i2=0;i2<Config.AR_PATT_SIZE_X;i2++){\r
+ for(int i3=0;i3<3;i3++){\r
+ input[i][i2][i3] = (255-data[i][i2][i3]) - ave;\r
+ sum += input[i][i2][i3]*input[i][i2][i3];\r
+ }\r
+ }\r
+ }\r
+ datapow = Math.sqrt( (double)sum );\r
+ if(datapow == 0.0){\r
+ throw new NyARException();\r
+// dir.set(0);//*dir = 0;\r
+// cf.set(-1.0);//*cf = -1.0;\r
+// return -1;\r
+ } \r
+ }\r
+ /**\r
+ * public int pattern_match(short[][][] data,IntPointer dir,DoublePointer cf)\r
+\r
+ */\r
+ public void evaluate(NyARCode i_code)\r
+ {\r
+ int[][][][] pat=i_code.getPat();\r
+ double[] patpow=i_code.getPatPow();\r
+ double[] invec=new double[EVEC_MAX];\r
+\r
+ double max = 0.0; // fix VC7 compiler warning: uninitialized variable\r
+ //確認\r
+ for(int i = 0; i < evec_dim; i++ ) {\r
+ invec[i] = 0.0;\r
+ for(int j = 0; j <height; j++ ){//for(int j = 0; j <Config.AR_PATT_SIZE_Y; j++ ){\r
+ for(int j2 = 0; j2 <width; j2++ ){\r
+ for(int j3 = 0; j3 <3; j3++ ){\r
+ invec[i] += evec[i][j][j2][j3] * input[j][j2][j3];//invec[i] += evec[i][j] * input[j];\r
+ }\r
+ }\r
+ }\r
+ invec[i] /= datapow;\r
+ }\r
+\r
+ double min = 10000.0;\r
+ int res=-1;\r
+ for(int j = 0; j < 4; j++ ) {\r
+ double sum2 = 0;\r
+ for(int i = 0; i < evec_dim; i++ ) {\r
+ sum2 += (invec[i] - epat[j][i]) * (invec[i] - epat[j][i]);\r
+ }\r
+ if( sum2 < min ) {\r
+ min = sum2;\r
+ res = j;\r
+// res2 = k;//kは常にインスタンスを刺すから、省略可能\r
+ }\r
+ }\r
+\r
+ int sum = 0;\r
+ for(int i=0;i<height;i++){//for(int i=0;i<Config.AR_PATT_SIZE_Y;i++){\r
+ for(int i2=0;i2<width;i2++){//for(int i2=0;i<Config.AR_PATT_SIZE_X;i2++){\r
+ for(int i3=0;i3<3;i3++){\r
+ sum += input[i][i2][i3]*pat[res][i][i2][i3];//sum += input[i][i2][i3]*pat[res2][res][i][i2][i3];\r
+ }\r
+ }\r
+ }\r
+ max = sum / patpow[res] / datapow;\r
+ dir=res;\r
+ cf=max;\r
+ }\r
+}\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core.raster;\r
+\r
+public interface NyARRaster{\r
+ //RGBの合計値を返す\r
+ public int getPixcelTotal(int i_x,int i_y);\r
+ public int getWidth();\r
+ public int getHeight();\r
+ public void pickRgbArray(int i_x,int i_y,int[] i_rgb);\r
+}\r
+\r
+\r
+\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core.raster;\r
+\r
+\r
+public class NyARRaster_BGRA implements NyARRaster\r
+{\r
+ private byte[] ref_buf;\r
+ int width;\r
+ int height;\r
+ public static NyARRaster_BGRA wrap(byte[] i_buffer,int i_width,int i_height)\r
+ {\r
+ NyARRaster_BGRA new_inst=new NyARRaster_BGRA();\r
+ new_inst.ref_buf=i_buffer;\r
+ new_inst.width =i_width;\r
+ new_inst.height =i_height;\r
+ return new_inst;\r
+ }\r
+ //RGBの合計値を返す\r
+ public int getPixcelTotal(int i_x,int i_y)\r
+ {\r
+ int bp=(i_x+i_y*width)*4;\r
+ return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);\r
+ }\r
+ public int getWidth()\r
+ {\r
+ return width;\r
+ }\r
+ public int getHeight()\r
+ {\r
+ return height;\r
+ }\r
+ public void pickRgbArray(int i_x,int i_y,int[] i_rgb)\r
+ {\r
+ int bp=(i_x+i_y*width)*4;\r
+ i_rgb[0]=(ref_buf[bp+2] & 0xff);//R\r
+ i_rgb[1]=(ref_buf[bp+1] & 0xff);//G\r
+ i_rgb[2]=(ref_buf[bp+0] & 0xff);//B\r
+ }\r
+}\r
+\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core.raster;\r
+\r
+\r
+/*\r
+ * 真っ黒の矩形を定義する。\r
+ *\r
+ */\r
+public class NyARRaster_Blank implements NyARRaster\r
+{\r
+ int width;\r
+ int height;\r
+ public NyARRaster_Blank(int i_width,int i_height)\r
+ {\r
+ NyARRaster_BGRA new_inst=new NyARRaster_BGRA();\r
+ new_inst.width =i_width;\r
+ new_inst.height =i_height;\r
+ }\r
+ //RGBの合計値を返す\r
+ public int getPixcelTotal(int i_x,int i_y)\r
+ {\r
+ return 0;\r
+ }\r
+ public int getWidth()\r
+ {\r
+ return width;\r
+ }\r
+ public int getHeight()\r
+ {\r
+ return height;\r
+ }\r
+ public void pickRgbArray(int i_x,int i_y,int[] i_rgb)\r
+ {\r
+ i_rgb[0]=0;\r
+ i_rgb[1]=0;\r
+ i_rgb[2]=0;\r
+ }\r
+}\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core.raster;\r
+\r
+\r
+public class NyARRaster_RGB implements NyARRaster\r
+{\r
+ protected byte[] ref_buf;\r
+ protected int width;\r
+ protected int height;\r
+ public static NyARRaster_RGB wrap(byte[] i_buffer,int i_width,int i_height)\r
+ {\r
+ NyARRaster_RGB new_inst=new NyARRaster_RGB();\r
+ new_inst.ref_buf=i_buffer;\r
+ new_inst.width =i_width;\r
+ new_inst.height =i_height;\r
+ return new_inst;\r
+ }\r
+ //RGBの合計値を返す\r
+ public int getPixcelTotal(int i_x,int i_y)\r
+ {\r
+ int bp=(i_x+i_y*width)*3;\r
+ return (ref_buf[bp] & 0xff)+(ref_buf[bp+1] & 0xff)+(ref_buf[bp+2] & 0xff);\r
+ }\r
+ public int getWidth()\r
+ {\r
+ return width;\r
+ }\r
+ public int getHeight()\r
+ {\r
+ return height;\r
+ }\r
+ public void pickRgbArray(int i_x,int i_y,int[] i_rgb)\r
+ {\r
+ int bp=(i_x+i_y*width)*3;\r
+ i_rgb[0]=(ref_buf[bp+0] & 0xff);//R\r
+ i_rgb[1]=(ref_buf[bp+1] & 0xff);//G\r
+ i_rgb[2]=(ref_buf[bp+2] & 0xff);//B\r
+ }\r
+}\r
+\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.detector;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.*;\r
+import jp.nyatla.nyartoolkit.core.match.NyARMatchPatt_Color_WITHOUT_PCA;\r
+import jp.nyatla.nyartoolkit.core.raster.*;\r
+/**\r
+ * 1個のマーカーに対する変換行列を計算するクラスです。\r
+ *\r
+ */\r
+public class NyARSingleDetectMarker{\r
+ private static final int AR_SQUARE_MAX=10;\r
+ private NyARParam param;\r
+ private NyARDetectSquare square;\r
+ private NyARCode code;\r
+ protected NyARTransMat transmat;\r
+ private double marker_width;\r
+ //検出結果の保存用\r
+ private int detected_direction;\r
+ private double detected_confidence;\r
+ private NyARSquare detected_square;\r
+ public NyARSingleDetectMarker(NyARParam i_param,NyARCode i_code,double i_marker_width)\r
+ {\r
+ param=i_param;\r
+ //解析オブジェクトを作る\r
+ square=new NyARDetectSquare(AR_SQUARE_MAX,i_param);\r
+ transmat=new NyARTransMat(param);\r
+ //比較コードを保存\r
+ code=i_code;\r
+ marker_width=i_marker_width;\r
+\r
+ \r
+ }\r
+ /**\r
+ * i_imageにマーカー検出処理を実行して、結果を保持します。\r
+ * @param dataPtr\r
+ * @param thresh\r
+ * @return\r
+ * マーカーが検出できたかを真偽値で返します。\r
+ * @throws NyARException\r
+ */\r
+ public boolean detectMarkerLite(NyARRaster i_image,int i_thresh) throws NyARException\r
+ {\r
+ detected_square=null;\r
+ //スクエアコードを探す\r
+ square.detectSquare(i_image, i_thresh);\r
+ int number_of_square=square.getSquareCount();\r
+ //コードは見つかった?\r
+ if(number_of_square<1){\r
+ return false;\r
+ }\r
+\r
+ //コードの一致度を調べる準備\r
+ NyARSquare[] squares=square.getSquareArray();\r
+ //パターンホルダを作る\r
+ NyARColorPatt patt=new NyARColorPatt(code.getWidth(),code.getHeight());\r
+ //評価基準になるパターンをイメージから切り出す\r
+ patt.pickFromRaster(i_image,squares[0].getMarker());\r
+ \r
+ //パターンの評価オブジェクトを作る。\r
+ NyARMatchPatt_Color_WITHOUT_PCA eva=new NyARMatchPatt_Color_WITHOUT_PCA();\r
+ //パターンを評価器にセット\r
+ eva.setPatt(patt);\r
+ //コードと比較する\r
+ eva.evaluate(code);\r
+ int square_index=0;\r
+ int direction=eva.getDirection();\r
+ double confidence=eva.getConfidence();\r
+ for(int i=1;i<number_of_square;i++){\r
+ //次のパターンを取得\r
+ patt.pickFromRaster(i_image,squares[i].getMarker());\r
+ //評価器にセットする。\r
+ eva.setPatt(patt);\r
+ //コードと比較する\r
+ eva.evaluate(code);\r
+ double c2=eva.getConfidence();\r
+ if(confidence>c2){\r
+ continue;\r
+ }\r
+ //もっと一致するマーカーがあったぽい\r
+ square_index=i;\r
+ direction=eva.getDirection();\r
+ confidence=c2;\r
+ }\r
+ //マーカー情報を保存\r
+ detected_square=squares[square_index];\r
+ detected_direction=direction;\r
+ detected_confidence=confidence;\r
+ return true;\r
+ }\r
+ /**\r
+ * 変換行列を返します。直前に実行したdetectMarkerLiteが成功していないと使えません。\r
+ * @param i_marker_width\r
+ * マーカーの大きさを指定します。\r
+ * @return\r
+ * double[3][4]の変換行列を返します。\r
+ * @throws NyARException\r
+ */\r
+ public NyARMat getTransmationMatrix() throws NyARException\r
+ {\r
+ //一番一致したマーカーの位置とかその辺を計算\r
+ transmat.transMat(detected_square,detected_direction,marker_width);\r
+ return transmat.getTransformationMatrix();\r
+ }\r
+ public double getConfidence()\r
+ {\r
+ return detected_confidence;\r
+ }\r
+ public int getDirection()\r
+ {\r
+ return detected_direction;\r
+ }\r
+ \r
+\r
+ \r
+ \r
+ \r
+ \r
+ \r
+// public static class arUtil_c{\r
+// public static final int arFittingMode =Config.DEFAULT_FITTING_MODE;\r
+// private static final int arImageProcMode =Config.DEFAULT_IMAGE_PROC_MODE;\r
+// public static final int arTemplateMatchingMode =Config.DEFAULT_TEMPLATE_MATCHING_MODE;\r
+// public static final int arMatchingPCAMode =Config.DEFAULT_MATCHING_PCA_MODE; \r
+ /*int arInitCparam( ARParam *param )*/\r
+\r
+\r
+ \r
+}\r
+\r
+ \r
+\r
+ \r
+ \r
+ \r
+ \r
+ \r
+ \r
+\r
+ \r
+\r
+\r
+ \r
+\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.sample;\r
+\r
+\r
+import java.io.*;\r
+import java.util.*;\r
+\r
+import jp.nyatla.nyartoolkit.core.*;\r
+import jp.nyatla.nyartoolkit.core.raster.*;\r
+import jp.nyatla.nyartoolkit.detector.*;\r
+\r
+/**\r
+ * 320x240のBGRA32で記録されたRAWイメージから、1種類のパターンを認識し、\r
+ * その変換行列を求めます。\r
+ * \r
+ * @author R.iizuka\r
+ *\r
+ */\r
+public class RawFileTest {\r
+ private final String code_file ="../Data/patt.hiro";\r
+ private final String data_file ="../Data/320x240ABGR.raw";\r
+ private final String camera_file="../Data/camera_para.dat";\r
+ public RawFileTest()\r
+ {\r
+ }\r
+ public void Test_arDetectMarkerLite() throws Exception\r
+ {\r
+ //AR用カメラパラメタファイルをロード\r
+ NyARParam ap =new NyARParam();\r
+ ap.loadFromARFile(camera_file);\r
+ ap.changeSize(320,240);\r
+ \r
+ //AR用のパターンコードを読み出し \r
+ NyARCode code=new NyARCode(16,16);\r
+ code.LoadFromARFile(code_file);\r
+ \r
+ //試験イメージの読み出し(320x240 BGRAのRAWデータ)\r
+ File f=new File(data_file);\r
+ FileInputStream fs=new FileInputStream(data_file);\r
+ byte[] buf=new byte[(int)f.length()];\r
+ fs.read(buf);\r
+ NyARRaster_BGRA ra=NyARRaster_BGRA.wrap(buf, 320, 240);\r
+ // Blank_Raster ra=new Blank_Raster(320, 240);\r
+ \r
+ //1パターンのみを追跡するクラスを作成\r
+ NyARSingleDetectMarker ar=new NyARSingleDetectMarker(ap,code,80.0);\r
+ \r
+ //マーカーを検出\r
+ Date d2=new Date();\r
+ for(int i=0;i<100;i++){\r
+ ar.detectMarkerLite(ra,100);\r
+ //変換行列を取得\r
+ double[][] tm=ar.getTransmationMatrix().getArray();\r
+ }\r
+ Date d=new Date();\r
+ System.out.println(d.getTime()-d2.getTime()); \r
+ }\r
+ public static void main(String[] args)\r
+ {\r
+ \r
+ try{\r
+ RawFileTest t=new RawFileTest();\r
+ //t.Test_arGetVersion();\r
+ t.Test_arDetectMarkerLite();\r
+ }catch(Exception e){\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+}\r
--- /dev/null
+package jp.nyatla.util;\r
+\r
+public class BytePointer {\r
+ private byte[] array_ref; //配列\r
+ private int array_offset; //配列に対する基準値\r
+ private int position; //array_offsetに対する現在位置\r
+ public static BytePointer wrap(byte[] i_array_ref,int i_offset)\r
+ {\r
+ return new BytePointer(i_array_ref,i_offset);\r
+ }\r
+ public void set(byte i_value)\r
+ {\r
+ array_ref[array_offset+position]=i_value; \r
+ }\r
+ public void set(int i_rel_positon,byte i_value)\r
+ {\r
+ array_ref[array_offset+position+i_rel_positon]=i_value;\r
+ }\r
+ /**\r
+ * カレント位置の値を取得する\r
+ * @return\r
+ */\r
+ public byte get()\r
+ {\r
+ return array_ref[array_offset+position];\r
+ }\r
+ /**\r
+ * カレント位置から+i_slideの位置にある値を取得する。\r
+ * @param i_step\r
+ * @return\r
+ */\r
+ public byte get(int i_slide)\r
+ {\r
+ return array_ref[array_offset+position+i_slide];\r
+ }\r
+ public void incPtr()\r
+ {\r
+ position++;\r
+ }\r
+ public void addPtr(int v)\r
+ {\r
+ position+=v;\r
+ }\r
+ private BytePointer(byte[] i_array_ref,int i_base_point)\r
+ {\r
+ array_offset =i_base_point;\r
+ array_ref =i_array_ref;\r
+ position =0;\r
+ }\r
+// public BytePointer()\r
+// {\r
+// array_offset =0;\r
+// array_ref =new int[1];\r
+// position =0;\r
+// }\r
+}\r
--- /dev/null
+package jp.nyatla.util;\r
+/**\r
+ * double型ポインタのエミュレートクラス\r
+ * 対象のdouble配列を基点を基準に参照する。\r
+ * @author atla\r
+ *\r
+ */\r
+public class DoublePointer\r
+{\r
+ private double[] array_ref; //配列\r
+ private int array_offset; //配列に対する基準値\r
+ private int position; //array_offsetに対する現在位置\r
+ public static DoublePointer wrap(double[] i_array_ref,int i_offset)\r
+ {\r
+ return new DoublePointer(i_array_ref,i_offset);\r
+ }\r
+ public static DoublePointer wrap(DoublePointer i_inst)\r
+ {\r
+ return new DoublePointer(i_inst.array_ref,i_inst.getPtrArrayOffset());\r
+ }\r
+ //現在位置からのサブシーケンスを返す。\r
+ public DoublePointer slice(int i_offset)\r
+ {\r
+ return DoublePointer.wrap(array_ref,array_offset+position+i_offset);\r
+ }\r
+ public void set(double i_value)\r
+ {\r
+ array_ref[array_offset+position]=i_value; \r
+ }\r
+ public void set(int i_rel_positon,double i_value)\r
+ {\r
+ array_ref[array_offset+position+i_rel_positon]=i_value;\r
+ }\r
+ /**\r
+ * カレント位置の値を取得する\r
+ * @return\r
+ */\r
+ public double get()\r
+ {\r
+ return array_ref[array_offset+position];\r
+ }\r
+ /**\r
+ * カレント位置から+i_slideの位置にある値を取得する。\r
+ * @param i_step\r
+ * @return\r
+ */\r
+ public double get(int i_slide)\r
+ {\r
+ return array_ref[array_offset+position+i_slide];\r
+ }\r
+ public void incPtr()\r
+ {\r
+ position++;\r
+ }\r
+ public void addPtr(int v)\r
+ {\r
+ position+=v;\r
+ }\r
+ public double[] array()\r
+ {\r
+ return array_ref;\r
+ }\r
+ public void subValue(double i_val)\r
+ {\r
+ array_ref[array_offset+position]-=i_val;\r
+ }\r
+ public void subValue(int i_step,double i_val)\r
+ {\r
+ array_ref[array_offset+position+i_step]-=i_val;\r
+ }\r
+ public void addValue(double i_val)\r
+ {\r
+ array_ref[array_offset+position]+=i_val;\r
+ }\r
+ public void addValue(int i_step,double i_val)\r
+ {\r
+ array_ref[array_offset+position+i_step]+=i_val;\r
+ }\r
+\r
+ /**\r
+ * 現在位置のオフセット位置を返す。\r
+ * @return\r
+ */\r
+ public int getPtrArrayOffset()\r
+ {\r
+ return array_offset+position;\r
+ }\r
+ private DoublePointer(double[] i_array_ref,int i_base_point)\r
+ {\r
+ array_offset =i_base_point;\r
+ array_ref =i_array_ref;\r
+ position =0;\r
+ }\r
+ public DoublePointer(int i_length)\r
+ {\r
+ array_offset =0;\r
+ array_ref =new double[i_length];\r
+ position =0; \r
+ }\r
+ public DoublePointer()\r
+ {\r
+ array_offset =0;\r
+ array_ref =new double[1];\r
+ position =0; \r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+package jp.nyatla.util;\r
+\r
+public class DoubleValue {\r
+ private double v;\r
+ public void set(double i_v){\r
+ v=i_v;\r
+ }\r
+ public double get(){\r
+ return v;\r
+ }\r
+ public void add(double i_v){\r
+ v+=i_v;\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+package jp.nyatla.util;\r
+\r
+public class IntPointer {\r
+ private int[] array_ref; //配列\r
+ private int array_offset; //配列に対する基準値\r
+ private int position; //array_offsetに対する現在位置\r
+ public static IntPointer wrap(int[] i_array_ref,int i_offset)\r
+ {\r
+ return new IntPointer(i_array_ref,i_offset);\r
+ }\r
+ public void set(int i_value)\r
+ {\r
+ array_ref[array_offset+position]=i_value; \r
+ }\r
+ public void set(int i_rel_positon,int i_value)\r
+ {\r
+ array_ref[array_offset+position+i_rel_positon]=i_value;\r
+ }\r
+ /**\r
+ * カレント位置の値を取得する\r
+ * @return\r
+ */\r
+ public int get()\r
+ {\r
+ return array_ref[array_offset+position];\r
+ }\r
+ /**\r
+ * カレント位置から+i_slideの位置にある値を取得する。\r
+ * @param i_step\r
+ * @return\r
+ */\r
+ public int get(int i_slide)\r
+ {\r
+ return array_ref[array_offset+position+i_slide];\r
+ }\r
+ public void incPtr()\r
+ {\r
+ position++;\r
+ }\r
+ public void addPtr(int v)\r
+ {\r
+ position+=v;\r
+ }\r
+ public void addValue(int i_val)\r
+ {\r
+ array_ref[array_offset+position]+=i_val;\r
+ }\r
+ public void addValue(int i_step,int i_val)\r
+ {\r
+ array_ref[array_offset+position+i_step]+=i_val;\r
+ }\r
+ private IntPointer(int[] i_array_ref,int i_base_point)\r
+ {\r
+ array_offset =i_base_point;\r
+ array_ref =i_array_ref;\r
+ position =0;\r
+ }\r
+ public IntPointer()\r
+ {\r
+ array_offset =0;\r
+ array_ref =new int[1];\r
+ position =0;\r
+ }\r
+}\r
--- /dev/null
+package jp.nyatla.util;\r
+\r
+public class IntValue {\r
+ private int v;\r
+ public void set(int i_v){\r
+ v=i_v;\r
+ }\r
+ public int get(){\r
+ return v;\r
+ }\r
+ public void inc(){\r
+ v++;\r
+ }\r
+ public void add(int i_v){\r
+ v+=i_v;\r
+ }\r
+}\r
--- /dev/null
+package jp.nyatla.util;\r
+\r
+public class ShortPointer {\r
+ private short[] array_ref; //配列\r
+ private int array_offset; //配列に対する基準値\r
+ private int position; //array_offsetに対する現在位置\r
+ public static ShortPointer wrap(short[] i_array_ref,int i_offset)\r
+ {\r
+ return new ShortPointer(i_array_ref,i_offset);\r
+ }\r
+ public static ShortPointer wrap(ShortPointer i_inst,int i_offset)\r
+ {\r
+ return new ShortPointer(i_inst.array_ref,i_inst.array_offset+i_inst.position+i_offset);\r
+ }\r
+ public void set(short i_value)\r
+ {\r
+ array_ref[array_offset+position]=i_value; \r
+ }\r
+ public void set(int i_rel_positon,short i_value)\r
+ {\r
+ array_ref[array_offset+position+i_rel_positon]=i_value;\r
+ }\r
+ /**\r
+ * カレント位置の値を取得する\r
+ * @return\r
+ */\r
+ public short get()\r
+ {\r
+ return array_ref[array_offset+position];\r
+ }\r
+ /**\r
+ * カレント位置から+i_slideの位置にある値を取得する。\r
+ * @param i_step\r
+ * @return\r
+ */\r
+ public short get(int i_slide)\r
+ {\r
+ return array_ref[array_offset+position+i_slide];\r
+ }\r
+ public void incPtr()\r
+ {\r
+ position++;\r
+ }\r
+ public void addPtr(int v)\r
+ {\r
+ position+=v;\r
+ }\r
+ private ShortPointer(short[] i_array_ref,int i_base_point)\r
+ {\r
+ array_offset =i_base_point;\r
+ array_ref =i_array_ref;\r
+ position =0;\r
+ }\r
+// public BytePointer()\r
+// {\r
+// array_offset =0;\r
+// array_ref =new int[1];\r
+// position =0;\r
+// }\r
+}\r
--- /dev/null
+package jp.nyatla.util;\r
+\r
+public class StringPointer {\r
+ private String[] array_ref;//配列\r
+ private int array_offset; //配列に対する基準値\r
+ private int position; //array_offsetに対する現在位置\r
+ public void set(String i_value)\r
+ {\r
+ array_ref[array_offset+position]=i_value;\r
+ }\r
+ public String get()\r
+ {\r
+ return array_ref[array_offset+position];\r
+ }\r
+ public String toString()\r
+ {\r
+ return get();\r
+ }\r
+ public StringPointer()\r
+ {\r
+ array_ref=new String[1];\r
+ array_offset=0;\r
+ position=0;\r
+ }\r
+}\r
--- /dev/null
+package jp.nyatla.util;\r
+\r
+public class StringValue {\r
+ private String v;\r
+ public StringValue()\r
+ {\r
+ v="";\r
+ }\r
+ public StringValue(String i_v)\r
+ {\r
+ v=i_v;\r
+ }\r
+ public void set(String i_v)\r
+ {\r
+ v=i_v;\r
+ }\r
+ public String get()\r
+ {\r
+ return v;\r
+ }\r
+ public String toString()\r
+ {\r
+ return v;\r
+ }\r
+}\r