2 * PROJECT: NyARToolkit
\r
3 * --------------------------------------------------------------------------------
\r
4 * This work is based on the original ARToolKit developed by
\r
7 * HITLab, University of Washington, Seattle
\r
8 * http://www.hitl.washington.edu/artoolkit/
\r
10 * The NyARToolkit is Java version ARToolkit class library.
\r
11 * Copyright (C)2008 R.Iizuka
\r
13 * This program is free software; you can redistribute it and/or
\r
14 * modify it under the terms of the GNU General Public License
\r
15 * as published by the Free Software Foundation; either version 2
\r
16 * of the License, or (at your option) any later version.
\r
18 * This program is distributed in the hope that it will be useful,
\r
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 * GNU General Public License for more details.
\r
23 * You should have received a copy of the GNU General Public License
\r
24 * along with this framework; if not, write to the Free Software
\r
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
27 * For further information please contact.
\r
28 * http://nyatla.jp/nyatoolkit/
\r
29 * <airmail(at)ebony.plala.or.jp>
\r
32 package jp.nyatla.nyartoolkit.core.match;
\r
34 import jp.nyatla.nyartoolkit.NyARException;
\r
35 import jp.nyatla.nyartoolkit.core.*;
\r
36 import jp.nyatla.nyartoolkit.core.pickup.INyARColorPatt;
\r
39 * AR_TEMPLATE_MATCHING_BWと同等のルールで マーカーを評価します。
\r
42 public class NyARMatchPatt_BlackWhite implements INyARMatchPatt
\r
44 private double datapow;
\r
50 private double cf = 0;
\r
52 private int dir = 0;
\r
56 private int[][][] input = new int[height][width][3];
\r
58 public boolean setPatt(INyARColorPatt i_target_patt) throws NyARException
\r
60 width = i_target_patt.getWidth();
\r
61 height = i_target_patt.getHeight();
\r
62 int[][][] data = i_target_patt.getPatArray();
\r
63 input = new int[height][width][3];
\r
66 for (int i = 0; i < height; i++) {// for(int
\r
67 // i=0;i<Config.AR_PATT_SIZE_Y;i++){
\r
68 for (int i2 = 0; i2 < width; i2++) {// for(int
\r
69 // i2=0;i2<Config.AR_PATT_SIZE_X;i2++){
\r
70 ave += (255 - data[i][i2][0]) + (255 - data[i][i2][1])
\r
71 + (255 - data[i][i2][2]);
\r
74 ave /= (height * width * 3);
\r
76 for (int i = 0; i < height; i++) {// for(int
\r
77 // i=0;i<Config.AR_PATT_SIZE_Y;i++){
\r
78 for (int i2 = 0; i2 < width; i2++) {// for(int
\r
79 // i2=0;i2<Config.AR_PATT_SIZE_X;i2++){
\r
80 input[i][i2][0] = ((255 - data[i][i2][0])
\r
81 + (255 - data[i][i2][1]) + (255 - data[i][i2][2]))
\r
83 sum += input[i][i2][0] * input[i][i2][0];
\r
87 datapow = Math.sqrt((double) sum);
\r
88 if (datapow == 0.0) {
\r
89 return false;// throw new NyARException();
\r
90 // dir.set(0);//*dir = 0;
\r
91 // cf.set(-1.0);//*cf = -1.0;
\r
97 public double getConfidence()
\r
102 public int getDirection()
\r
107 public void evaluate(NyARCode i_code)
\r
109 short[][][] patBW = i_code.getPatBW();// static int
\r
110 // patBW[AR_PATT_NUM_MAX][4][AR_PATT_SIZE_Y*AR_PATT_SIZE_X*3];
\r
111 double[] patpowBW = i_code.getPatPowBW();// static double
\r
112 // patpowBW[AR_PATT_NUM_MAX][4];
\r
116 // 本家が飛ぶ。試験データで0.77767376888がが出ればOKってことで
\r
117 for (int j = 0; j < 4; j++) {
\r
119 for (int i = 0; i < height; i++) {
\r
120 for (int i2 = 0; i2 < width; i2++) {
\r
121 sum += input[i][i2][0] * patBW[j][i][i2];
\r
124 double sum2 = sum / patpowBW[j] / datapow;
\r